Skip to content

Commit

Permalink
Added Silverlight UnitTests
Browse files Browse the repository at this point in the history
  • Loading branch information
remogloor committed Oct 21, 2010
1 parent 620ad55 commit 16a2edd
Show file tree
Hide file tree
Showing 28 changed files with 972 additions and 14 deletions.
35 changes: 21 additions & 14 deletions Ninject.MockingKernel.build
Expand Up @@ -10,9 +10,11 @@
<property name="dependencies" value="Ninject" overwrite="false"/>

<include buildfile="Ninject.include" />
<target name="all" depends="core test"/>
<target name="all" depends="core test silverlight-test"/>

<target name="core" depends="init">
<target name="core" depends="init buildCore buildMoq buildRhinoMocks" />

<target name="buildCore" depends="init">
<csc noconfig="true" warnaserror="true" target="library" debug="${build.debug}" optimize="${build.optimize}" define="${build.defines}"
output="${current.path.build}/${product.assembly}" doc="${current.path.build}/${product.docfile}" keyfile="${path.src}/${product.keyfile}">
<arg line="/filealign:512" unless="${nant.settings.currentframework == 'mono-2.0'}"/>
Expand All @@ -28,7 +30,9 @@
<include name="${path.lib}/Ninject/${build.platform}/Ninject.dll"/>
</references>
</csc>
</target>

<target name="buildMoq">
<property name="product.assembly.moq" value="${product.name}.Moq.dll" overwrite="false"/>
<property name="product.docfile.moq" value="${product.name}.Moq.xml" overwrite="false"/>
<property name="current.path.lib.moq" value="${path.lib}/Moq/net-3.5" unless="${string::contains(build.platform, 'silverlight')}" />
Expand Down Expand Up @@ -57,11 +61,13 @@
<include name="${current.path.lib.moq}/Moq.Silverlight.dll" if="${string::contains(build.platform, 'silverlight')}"/>
</references>
</csc>

</target>

<target name="buildRhinoMocks" unless="${string::contains(build.platform, 'silverlight')}">
<property name="product.assembly.rhinomock" value="${product.name}.RhinoMock.dll" overwrite="false"/>
<property name="product.docfile.rhinomock" value="${product.name}.RhinoMock.xml" overwrite="false"/>
<property name="current.path.lib.rhinomocks" value="${path.lib}/RhinoMocks" unless="${string::contains(build.platform, 'silverlight')}" />
<property name="current.path.lib.rhinomocks" value="${path.lib}/RhinoMocks" if="${string::contains(build.platform, 'silverlight')}" />
<property name="current.path.lib.rhinomocks" value="${path.lib}/RhinoMocks/net-3.5" unless="${string::contains(build.platform, 'silverlight')}" />
<property name="current.path.lib.rhinomocks" value="${path.lib}/RhinoMocks/silverlight" if="${string::contains(build.platform, 'silverlight')}" />
<copy todir="${current.path.build}/lib">
<fileset basedir="${current.path.lib.rhinomocks}">
<include name="**/*.dll"/>
Expand All @@ -82,9 +88,10 @@
<include name="System.Web.dll" unless="${build.platform == 'silverlight-2.0'}"/>
<include name="${current.path.build}/${product.assembly}"/>
<include name="${path.lib}/Ninject/${build.platform}/Ninject.dll"/>
<include name="${current.path.lib.rhinomocks}/Rhino.Mocks.dll"/>
<include name="${current.path.lib.rhinomocks}/Rhino.Mocks.dll" unless="${string::contains(build.platform, 'silverlight')}"/>
<include name="${current.path.lib.rhinomocks}/Rhino.Mocks 3.5.Silverlight.dll" if="${string::contains(build.platform, 'silverlight')}"/>
</references>
</csc>
</csc>
</target>

<target name="compile-tests" depends="core" unless="${skip.tests}" if="${not(string::contains(build.platform, 'silverlight') or build.platform == 'netcf-3.5')}">
Expand Down Expand Up @@ -135,13 +142,6 @@
<include name="**/*.dll"/>
</fileset>
</copy>
<copy todir="${current.path.test}">
<fileset basedir="${path.tools.moq}/silverlight">
<include name="Moq.Silverlight.dll"/>
<include name="Castle.DynamicProxy-Silverlight.dll"/>
<include name="Castle.Core-Silverlight.dll"/>
</fileset>
</copy>
<copy todir="${current.path.test}">
<fileset basedir="${path.tools.unitdriven}">
<include name="UnitDrivenLight.dll"/>
Expand All @@ -151,8 +151,12 @@
output="${current.path.test}/${product.assembly.silverlighttestdll}">
<sources basedir="${path.src}">
<include name="${product.name}.Test/**/*.cs"/>
<include name="${product.name}.Moq.Test/**/*.cs"/>
<!--<include name="${product.name}.RhinoMock.Test/**/*.cs"/>-->
<include name="${product.name}.SilverlightTests/*.cs"/>
<exclude name="${product.name}.Test/MSTestAttributes/*.cs"/>
<exclude name="${product.name}.Moq.Test/Properties/*.cs"/>
<exclude name="${product.name}.RhinoMock.Test/Properties/*.cs"/>
</sources>
<references basedir="${current.path.test}">
<include name="mscorlib.dll"/>
Expand All @@ -162,10 +166,13 @@
<include name="System.Windows.Browser.dll"/>
<include name="System.Net.dll"/>
<include name="Moq.Silverlight.dll"/>
<include name="Rhino.Mocks 3.5.Silverlight.dll"/>
<include name="Castle.DynamicProxy-Silverlight.dll"/>
<include name="Castle.Core-Silverlight.dll"/>
<include name="UnitDrivenLight.dll"/>
<include name="${product.assembly}"/>
<include name="${product.assembly.moq}"/>
<!--<include name="${product.assembly.rhinomock}"/>-->
<include name="${path.lib}/Ninject/${build.platform}/Ninject.dll"/>
</references>
<nowarn>
Expand Down
6 changes: 6 additions & 0 deletions Ninject.Moq.sln
Expand Up @@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ninject.MockingKernel.Rhino
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ninject.MockingKernel.RhinoMocks.Test", "src\Ninject.MockingKernel.RhinoMock.Test\Ninject.MockingKernel.RhinoMocks.Test.csproj", "{8BD4FA63-ACBA-430F-80FB-DA86AAF53F58}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ninject.MockingKernel.SilverlightTests", "src\Ninject.MockingKernel.SilverlightTests\Ninject.MockingKernel.SilverlightTests.csproj", "{949002CF-F181-4E7C-B8A1-8233A2159074}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -48,6 +50,10 @@ Global
{8BD4FA63-ACBA-430F-80FB-DA86AAF53F58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BD4FA63-ACBA-430F-80FB-DA86AAF53F58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BD4FA63-ACBA-430F-80FB-DA86AAF53F58}.Release|Any CPU.Build.0 = Release|Any CPU
{949002CF-F181-4E7C-B8A1-8233A2159074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{949002CF-F181-4E7C-B8A1-8233A2159074}.Debug|Any CPU.Build.0 = Debug|Any CPU
{949002CF-F181-4E7C-B8A1-8233A2159074}.Release|Any CPU.ActiveCfg = Release|Any CPU
{949002CF-F181-4E7C-B8A1-8233A2159074}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions lib/RhinoMocks/net-3.5/acknowledgements.txt
@@ -0,0 +1,2 @@
Rhino Mocks is using Castle Dynamic Proxy (http://www.castleproject.org/dynamicproxy/index.html) to handle proxying the types it needs to mock.
The Dynamic Proxy project has been invaluable resource and made creating Rhino Mocks possible.
25 changes: 25 additions & 0 deletions lib/RhinoMocks/net-3.5/license.txt
@@ -0,0 +1,25 @@
Copyright (c) 2005 - 2009 Ayende Rahien (ayende@ayende.com)
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Ayende Rahien nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions src/Ninject.MockingKernel.Moq.Test/MoqIntegrationTest.cs
Expand Up @@ -22,10 +22,20 @@
namespace Ninject.MockingKernel.Moq
{
using global::Moq;
#if SILVERLIGHT
#if SILVERLIGHT_MSTEST
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using UnitDriven;
#endif
#else
using Ninject.MockingKernel.MSTestAttributes;
#endif

/// <summary>
/// Integration test for the moq mocking kernel.
/// </summary>
[TestClass]
public class MoqIntegrationTest : IntegrationTest
{
/// <summary>
Expand Down
Expand Up @@ -21,11 +21,22 @@

namespace Ninject.MockingKernel.RhinoMock
{
#if !NO_RHINOMOCKS_SILVERLIGHT_TESTS
#if SILVERLIGHT
#if SILVERLIGHT_MSTEST
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using UnitDriven;
#endif
#else
using Ninject.MockingKernel.MSTestAttributes;
#endif
using Rhino.Mocks;

/// <summary>
/// Tests the rhino mocks mocking kernel.
/// </summary>
[TestClass]
public class RhinoMocksIntegrationTest : IntegrationTest
{
/// <summary>
Expand All @@ -46,4 +57,5 @@ protected override void AssertDoWasCalled(IDummyService dummyService)
dummyService.AssertWasCalled(s => s.Do());
}
}
#endif
}
22 changes: 22 additions & 0 deletions src/Ninject.MockingKernel.RhinoMock/RhinoMocksMockProvider.cs
Expand Up @@ -22,6 +22,9 @@
namespace Ninject.MockingKernel.RhinoMock
{
using System;
using System.Linq;
using System.Reflection;

using Ninject.Activation;
using Ninject.Components;
using Ninject.MockingKernel;
Expand All @@ -32,6 +35,21 @@ namespace Ninject.MockingKernel.RhinoMock
/// </summary>
public class RhinoMocksMockProvider : NinjectComponent, IProvider, IMockProviderCallbackProvider
{
#if SILVERLIGHT
/// <summary>
/// The method info for creation mocks.
/// </summary>
private readonly MethodInfo generateMockMethodInfo;

/// <summary>
/// Initializes a new instance of the <see cref="RhinoMocksMockProvider"/> class.
/// </summary>
public RhinoMocksMockProvider()
{
this.generateMockMethodInfo = typeof(MockRepository).GetMethod("GenerateMock");
}
#endif

/// <summary>
/// Gets the type (or prototype) of instances the provider creates.
/// </summary>
Expand All @@ -50,7 +68,11 @@ public Type Type
/// <returns>The created instance.</returns>
public object Create(IContext context)
{
#if !SILVERLIGHT
return MockRepository.GenerateMock(context.Request.Service, new Type[0], new object[0]);
#else
return this.generateMockMethodInfo.MakeGenericMethod(context.Request.Service).Invoke(null, new[] { new object[0] });
#endif
}

/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Ninject.MockingKernel.SilverlightTests/App.xaml
@@ -0,0 +1,8 @@
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Ninject.MockingKernel.SilverlightTests.App"
>
<Application.Resources>

</Application.Resources>
</Application>
76 changes: 76 additions & 0 deletions src/Ninject.MockingKernel.SilverlightTests/App.xaml.cs
@@ -0,0 +1,76 @@
namespace Ninject.MockingKernel.SilverlightTests
{
using System;
using System.Windows;
#if SILVERLIGHT_MSTEST
using Microsoft.Silverlight.Testing;
#endif

public partial class App : Application
{
private bool contentLoaded;

public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;

this.CustomInitializeComponent();
}

/// <summary>
/// InitializeComponent
/// </summary>
public void CustomInitializeComponent()
{
if (this.contentLoaded)
{
return;
}
this.contentLoaded = true;
System.Windows.Application.LoadComponent(this, new System.Uri("/Ninject.SilverlightTests;component/App.xaml", System.UriKind.Relative));
}

private void Application_Startup(object sender, StartupEventArgs e)
{
#if SILVERLIGHT_MSTEST
RootVisual = UnitTestSystem.CreateTestPage();
#endif
}

private void Application_Exit(object sender, EventArgs e)
{

}
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
// If the app is running outside of the debugger then report the exception using
// the browser's exception mechanism. On IE this will display it a yellow alert
// icon in the status bar and Firefox will display a script error.
if (!System.Diagnostics.Debugger.IsAttached)
{

// NOTE: This will allow the application to continue running after an exception has been thrown
// but not handled.
// For production applications this error handling should be replaced with something that will
// report the error to the website and stop the application.
e.Handled = true;
Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
}
}
private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
{
try
{
string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");

// System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
}
catch (Exception)
{
}
}
}
}
13 changes: 13 additions & 0 deletions src/Ninject.MockingKernel.SilverlightTests/AppManifest.xaml
@@ -0,0 +1,13 @@
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="Ninject.MockingKernel.SilverlightTests" EntryPointType="Ninject.MockingKernel.SilverlightTests.App" RuntimeVersion="4.0.50401.0">
<Deployment.Parts>
<AssemblyPart x:Name="Ninject.MockingKernel.SilverlightTests" Source="Ninject.MockingKernel.SilverlightTests.dll" />
<AssemblyPart x:Name="Moq.Silverlight" Source="Moq.Silverlight.dll" />
<AssemblyPart x:Name="Ninject" Source="Ninject.dll" />
<AssemblyPart x:Name="Ninject.MockingKernel" Source="Ninject.MockingKernel.dll" />
<AssemblyPart x:Name="Ninject.MockingKernel.Moq" Source="Ninject.MockingKernel.Moq.dll" />
<!--<AssemblyPart x:Name="Ninject.MockingKernel.RhinoMock" Source="Ninject.MockingKernel.RhinoMock.dll" />-->
<AssemblyPart x:Name="Castle.Core-Silverlight" Source="Castle.Core-Silverlight.dll" />
<AssemblyPart x:Name="Castle.DynamicProxy-Silverlight" Source="Castle.DynamicProxy-Silverlight.dll" />
<AssemblyPart x:Name="UnitDrivenLight" Source="UnitDrivenLight.dll" />
</Deployment.Parts>
</Deployment>
38 changes: 38 additions & 0 deletions src/Ninject.MockingKernel.SilverlightTests/AssertWithThrows.cs
@@ -0,0 +1,38 @@
namespace Ninject.SilverlightTests
{
using System;
using System.Globalization;
#if SILVERLIGHT_MSTEST
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using Assert = UnitDriven.Assert;
#endif

public class AssertWithThrows
{
public static void DoesNotThrow(Action action)
{
try
{
action();
}
catch (Exception)
{
Assert.Fail("Expected no exception");
}
}

public static void Throws<T>(Action action)
where T : Exception
{
try
{
action();
Assert.Fail(string.Format(CultureInfo.InvariantCulture, "Expected excpetion {0} did not occur!", typeof(T).Name));
}
catch (T)
{
}
}
}
}

0 comments on commit 16a2edd

Please sign in to comment.