Permalink
Browse files

added tests

  • Loading branch information...
1 parent 0b55d70 commit 87d37d99adf6a90a9e8386d3e9daa35eb6e8b3f1 @nberardi nberardi committed Nov 27, 2010
View
@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedFusion.Web", "src\ManagedFusion.Web.csproj", "{FB8FDF75-AF29-409D-B2E5-9283B9D1ECF3}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedFusion.Web.Tests", "test\ManagedFusion.Web.Tests\ManagedFusion.Web.Tests.csproj", "{9548F38C-6F75-44AD-81C6-418330CF879E}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -13,6 +15,10 @@ Global
{FB8FDF75-AF29-409D-B2E5-9283B9D1ECF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB8FDF75-AF29-409D-B2E5-9283B9D1ECF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB8FDF75-AF29-409D-B2E5-9283B9D1ECF3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9548F38C-6F75-44AD-81C6-418330CF879E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9548F38C-6F75-44AD-81C6-418330CF879E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9548F38C-6F75-44AD-81C6-418330CF879E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9548F38C-6F75-44AD-81C6-418330CF879E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -128,7 +128,7 @@
<Compile Include="Web\Mvc\ISerializableActionResult.cs" />
<Compile Include="Web\Mvc\ISerializableExceptionResult.cs" />
<Compile Include="Web\Mvc\JavaScriptCallbackResult.cs" />
- <Compile Include="Web\Mvc\JsonResult.cs" />
+ <Compile Include="Web\Mvc\JsonView.cs" />
<Compile Include="Web\Mvc\LowercaseRoute.cs" />
<Compile Include="Web\Mvc\MethodNotAllowedResult.cs" />
<Compile Include="Web\Mvc\NameAttribute.cs" />
@@ -141,7 +141,7 @@
<Compile Include="Web\Mvc\ServiceOnlyAttribute.cs" />
<Compile Include="Web\Mvc\StopwatchAttribute.cs" />
<Compile Include="Web\Mvc\UnsupportedMediaTypeResult.cs" />
- <Compile Include="Web\Mvc\XmlResult.cs" />
+ <Compile Include="Web\Mvc\XmlView.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
@@ -12,7 +12,7 @@ namespace ManagedFusion.Web.Mvc
/// <summary>
///
/// </summary>
- public class JavaScriptCallbackResult : JsonResult
+ public class JavaScriptCallbackResult : JsonView
{
/// <summary>
/// Initializes a new instance of the <see cref="JavaScriptResult"/> class.
@@ -1,19 +1,15 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Web.Mvc;
using ManagedFusion.Serialization;
namespace ManagedFusion.Web.Mvc
{
- public class JsonResult : SerializedView
+ public class JsonView : SerializedView
{
/// <summary>
/// Initializes a new instance of the <see cref="JsonResult"/> class.
/// </summary>
- public JsonResult()
+ public JsonView()
{
ContentType = "application/json";
}
@@ -112,11 +112,11 @@ private void UpdateModelSerializer(ControllerContext context)
break;
case ResponseType.Json:
- ModelSerializer = new JsonResult();
+ ModelSerializer = new JsonView();
break;
case ResponseType.Xml:
- ModelSerializer = new XmlResult();
+ ModelSerializer = new XmlView();
break;
case ResponseType.Csv:
@@ -156,7 +156,7 @@ public virtual void Render(ViewContext viewContext, TextWriter writer)
string content = GetContent();
if (content != null)
- response.Write(content);
+ writer.Write(content);
}
}
@@ -85,11 +85,11 @@ public override void OnActionExecuted(ActionExecutedContext filterContext)
break;
case ResponseType.Json:
- result.View = new JsonResult();
+ result.View = new JsonView();
break;
case ResponseType.Xml:
- result.View = new XmlResult();
+ result.View = new XmlView();
break;
case ResponseType.Csv:
@@ -11,12 +11,12 @@ namespace ManagedFusion.Web.Mvc
/// <summary>
///
/// </summary>
- public class XmlResult : SerializedView
+ public class XmlView : SerializedView
{
/// <summary>
/// Initializes a new instance of the <see cref="XmlResult"/> class.
/// </summary>
- public XmlResult()
+ public XmlView()
{
ContentType = "text/xml";
}
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Web;
+using Moq;
+
+namespace ManagedFusion.Web.Tests
+{
+ public static class HttpHelpers
+ {
+ public static HttpContextBase MockHttpContext()
+ {
+ var context = new Mock<HttpContextBase>();
+ var request = new Mock<HttpRequestBase>();
+ var response = new Mock<HttpResponseBase>();
+ var session = new Mock<HttpSessionStateBase>();
+ var server = new Mock<HttpServerUtilityBase>();
+ var cache = new Mock<HttpCachePolicyBase>();
+
+ response.SetupGet(x => x.Cache).Returns(cache.Object);
+
+ context.SetupGet(x => x.Request).Returns(request.Object);
+ context.SetupGet(x => x.Response).Returns(response.Object);
+ context.SetupGet(x => x.Session).Returns(session.Object);
+ context.SetupGet(x => x.Server).Returns(server.Object);
+
+ return context.Object;
+ }
+ }
+}
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{9548F38C-6F75-44AD-81C6-418330CF879E}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>ManagedFusion.Web.Tests</RootNamespace>
+ <AssemblyName>ManagedFusion.Web.Tests</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="ManagedFusion">
+ <HintPath>..\..\lib\ManagedFusion.dll</HintPath>
+ </Reference>
+ <Reference Include="Moq">
+ <HintPath>..\..\lib\Moq.dll</HintPath>
+ </Reference>
+ <Reference Include="nunit.framework">
+ <HintPath>..\..\lib\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Web.Abstractions" />
+ <Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+ <Reference Include="System.Web.Routing" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="HttpHelpers.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="SerializedViewTest.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\ManagedFusion.Web.csproj">
+ <Project>{FB8FDF75-AF29-409D-B2E5-9283B9D1ECF3}</Project>
+ <Name>ManagedFusion.Web</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ManagedFusion.Web.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("ManagedFusion.Web.Tests")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("a6d2c402-e89d-4428-8639-cbc7d4c8e92c")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using ManagedFusion.Web.Mvc;
+using System.Web.Mvc;
+using System.IO;
+using System.Web.Routing;
+using ManagedFusion.Serialization;
+
+namespace ManagedFusion.Web.Tests
+{
+ [TestFixture]
+ public class SerializedViewTest
+ {
+ [Test]
+ public void Simple_Json()
+ {
+ // arrange
+ var expected = "\"object\":{\"name\":\"value\"}";
+ var obj = new Dictionary<string, object>() {
+ { "name", "value" }
+ };
+
+ var view = new JsonView();
+
+ var viewContext = new ViewContext();
+ viewContext.ViewData = new ViewDataDictionary(obj);
+ viewContext.RouteData = new RouteData();
+ viewContext.RouteData.Values.Add("action", "test");
+ viewContext.HttpContext = HttpHelpers.MockHttpContext();
+
+ // act
+ var result = new StringWriter();
+ view.Render(viewContext, result);
+
+ // assert
+ Assert.IsTrue(result.ToString().Contains(expected), "expected: {0}, but was: {1}", expected, result);
+ }
+
+ [Test]
+ public void Simple_ModelName()
+ {
+ // arrange
+ var expected = "\"test\":{\"name\":\"value\"}";
+ var obj = new Dictionary<string, object>() {
+ { Serializer.ModelNameKey, "test" },
+ { "name", "value" }
+ };
+
+ var view = new JsonView();
+
+ var viewContext = new ViewContext();
+ viewContext.ViewData = new ViewDataDictionary(obj);
+ viewContext.RouteData = new RouteData();
+ viewContext.RouteData.Values.Add("action", "test");
+ viewContext.HttpContext = HttpHelpers.MockHttpContext();
+
+ // act
+ var result = new StringWriter();
+ view.Render(viewContext, result);
+
+ // assert
+ Assert.IsTrue(result.ToString().Contains(expected), "expected: {0}, but was: {1}", expected, result);
+ }
+ }
+}

0 comments on commit 87d37d9

Please sign in to comment.