Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Berardi committed Nov 27, 2010
1 parent 0b55d70 commit 87d37d9
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 16 deletions.
6 changes: 6 additions & 0 deletions ManagedFusion.Web.sln
Expand Up @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 # Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedFusion.Web", "src\ManagedFusion.Web.csproj", "{FB8FDF75-AF29-409D-B2E5-9283B9D1ECF3}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedFusion.Web", "src\ManagedFusion.Web.csproj", "{FB8FDF75-AF29-409D-B2E5-9283B9D1ECF3}"
EndProject 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Expand All @@ -13,6 +15,10 @@ Global
{FB8FDF75-AF29-409D-B2E5-9283B9D1ECF3}.Debug|Any CPU.Build.0 = Debug|Any CPU {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.ActiveCfg = Release|Any CPU
{FB8FDF75-AF29-409D-B2E5-9283B9D1ECF3}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
Expand Down
Binary file modified lib/ManagedFusion.dll
Binary file not shown.
Binary file removed lib/ManagedFusion.pdb
Binary file not shown.
Binary file added lib/Moq.dll
Binary file not shown.
Binary file added lib/nunit.framework.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions src/ManagedFusion.Web.csproj
Expand Up @@ -128,7 +128,7 @@
<Compile Include="Web\Mvc\ISerializableActionResult.cs" /> <Compile Include="Web\Mvc\ISerializableActionResult.cs" />
<Compile Include="Web\Mvc\ISerializableExceptionResult.cs" /> <Compile Include="Web\Mvc\ISerializableExceptionResult.cs" />
<Compile Include="Web\Mvc\JavaScriptCallbackResult.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\LowercaseRoute.cs" />
<Compile Include="Web\Mvc\MethodNotAllowedResult.cs" /> <Compile Include="Web\Mvc\MethodNotAllowedResult.cs" />
<Compile Include="Web\Mvc\NameAttribute.cs" /> <Compile Include="Web\Mvc\NameAttribute.cs" />
Expand All @@ -141,7 +141,7 @@
<Compile Include="Web\Mvc\ServiceOnlyAttribute.cs" /> <Compile Include="Web\Mvc\ServiceOnlyAttribute.cs" />
<Compile Include="Web\Mvc\StopwatchAttribute.cs" /> <Compile Include="Web\Mvc\StopwatchAttribute.cs" />
<Compile Include="Web\Mvc\UnsupportedMediaTypeResult.cs" /> <Compile Include="Web\Mvc\UnsupportedMediaTypeResult.cs" />
<Compile Include="Web\Mvc\XmlResult.cs" /> <Compile Include="Web\Mvc\XmlView.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
Expand Down
2 changes: 1 addition & 1 deletion src/Web/Mvc/JavaScriptCallbackResult.cs
Expand Up @@ -12,7 +12,7 @@ namespace ManagedFusion.Web.Mvc
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class JavaScriptCallbackResult : JsonResult public class JavaScriptCallbackResult : JsonView
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JavaScriptResult"/> class. /// Initializes a new instance of the <see cref="JavaScriptResult"/> class.
Expand Down
8 changes: 2 additions & 6 deletions src/Web/Mvc/JsonResult.cs → src/Web/Mvc/JsonView.cs
@@ -1,19 +1,15 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;


using ManagedFusion.Serialization; using ManagedFusion.Serialization;


namespace ManagedFusion.Web.Mvc namespace ManagedFusion.Web.Mvc
{ {
public class JsonResult : SerializedView public class JsonView : SerializedView
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JsonResult"/> class. /// Initializes a new instance of the <see cref="JsonResult"/> class.
/// </summary> /// </summary>
public JsonResult() public JsonView()
{ {
ContentType = "application/json"; ContentType = "application/json";
} }
Expand Down
4 changes: 2 additions & 2 deletions src/Web/Mvc/SerializedResult.cs
Expand Up @@ -112,11 +112,11 @@ private void UpdateModelSerializer(ControllerContext context)
break; break;


case ResponseType.Json: case ResponseType.Json:
ModelSerializer = new JsonResult(); ModelSerializer = new JsonView();
break; break;


case ResponseType.Xml: case ResponseType.Xml:
ModelSerializer = new XmlResult(); ModelSerializer = new XmlView();
break; break;


case ResponseType.Csv: case ResponseType.Csv:
Expand Down
2 changes: 1 addition & 1 deletion src/Web/Mvc/SerializedView.cs
Expand Up @@ -156,7 +156,7 @@ public virtual void Render(ViewContext viewContext, TextWriter writer)
string content = GetContent(); string content = GetContent();


if (content != null) if (content != null)
response.Write(content); writer.Write(content);
} }
} }


Expand Down
4 changes: 2 additions & 2 deletions src/Web/Mvc/ServiceAttribute.cs
Expand Up @@ -85,11 +85,11 @@ public override void OnActionExecuted(ActionExecutedContext filterContext)
break; break;


case ResponseType.Json: case ResponseType.Json:
result.View = new JsonResult(); result.View = new JsonView();
break; break;


case ResponseType.Xml: case ResponseType.Xml:
result.View = new XmlResult(); result.View = new XmlView();
break; break;


case ResponseType.Csv: case ResponseType.Csv:
Expand Down
4 changes: 2 additions & 2 deletions src/Web/Mvc/XmlResult.cs → src/Web/Mvc/XmlView.cs
Expand Up @@ -11,12 +11,12 @@ namespace ManagedFusion.Web.Mvc
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class XmlResult : SerializedView public class XmlView : SerializedView
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="XmlResult"/> class. /// Initializes a new instance of the <see cref="XmlResult"/> class.
/// </summary> /// </summary>
public XmlResult() public XmlView()
{ {
ContentType = "text/xml"; ContentType = "text/xml";
} }
Expand Down
31 changes: 31 additions & 0 deletions test/ManagedFusion.Web.Tests/HttpHelpers.cs
@@ -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;
}
}
}
74 changes: 74 additions & 0 deletions test/ManagedFusion.Web.Tests/ManagedFusion.Web.Tests.csproj
@@ -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>
36 changes: 36 additions & 0 deletions test/ManagedFusion.Web.Tests/Properties/AssemblyInfo.cs
@@ -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")]
66 changes: 66 additions & 0 deletions test/ManagedFusion.Web.Tests/SerializedViewTest.cs
@@ -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.