From: Choy R. <ch...@us...> - 2005-01-29 09:13:41
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14691/DotNetMock.TestFramework.Tests Added Files: .cvsignore AssemblyInfo.cs DotNetMock.TestFramework.Tests.csproj ImplementationFactoryTests.cs MbUnitStubMakerTests.cs NUnitStubMakerTests.cs StubClassMakerTests.cs csUnitStubMakerTests.cs Log Message: Merged changes in from branch RFE_1098585. * Had a little trouble with the new sn -Vr stuff. I don't normally develop under administrative id. So had to added target skip-verification run as administrator. then ran tests. all pass. --- NEW FILE: .cvsignore --- bin obj *.csproj.user --- NEW FILE: NUnitStubMakerTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; using DotNetMock.TestFramework; using DotNetMock.Core; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class NUnitStubMakerTests { [Test] public void Basic() { Assembly providerAssembly = Assembly.Load("nunit.framework"); NUnitStubMaker stubMaker = new NUnitStubMaker( providerAssembly, new SystemDynamicLinker() ); StubClassMaker scm = new StubClassMaker(); Type stubClass = scm.MakeStubClass(typeof(ITestFramework), stubMaker); ITestFramework tf = (ITestFramework) Activator.CreateInstance(stubClass); tf.Assert(true); tf.AssertEquals(1, 1); } } } --- NEW FILE: DotNetMock.TestFramework.Tests.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{6C2904D4-ADCC-4980-AED0-64A8C6F3AF69}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "DotNetMock.TestFramework.Tests" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "DotNetMock.TestFramework.Tests" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "DotNetMock.Core" Project = "{5666DF57-5109-4C5F-967D-EEDC554B8E55}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "DotNetMock" Project = "{1AD0CD00-16FA-4456-B2ED-A47406957228}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "nunit.framework" AssemblyName = "nunit.framework" HintPath = "..\lib\nunit.framework.dll" Private = "True" /> </References> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "csUnitStubMakerTests.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ImplementationFactoryTests.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MbUnitStubMakerTests.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "NUnitStubMakerTests.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "StubClassMakerTests.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: csUnitStubMakerTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; using DotNetMock.TestFramework; using DotNetMock.Core; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class csUnitStubMakerTests { static readonly Assembly providerAssembly = Assembly.GetExecutingAssembly(); const string EXPECTED_MESSAGE = "MESSAGE"; const string NOT_NULL = "NOT-NULL"; ITestFramework tf; static string MethodName { get { return csUnit.Assert.MethodName; } } static object[] Arguments { get { return csUnit.Assert.Arguments; } } [Test] public void CheckAssert() { tf.Assert(true); Assert.AreEqual("True", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(true, Arguments[0]); tf.Assert(false); Assert.AreEqual("True", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(false, Arguments[0]); } [Test] public void CheckAssertWithMessage() { tf.Assert(EXPECTED_MESSAGE, true); Assert.AreEqual("True", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(true, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.Assert(EXPECTED_MESSAGE, false); Assert.AreEqual("True", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(false, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckAssertNotNull() { tf.AssertNotNull(NOT_NULL); Assert.AreEqual("NotNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); tf.AssertNotNull(null); Assert.AreEqual("NotNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.IsNull(Arguments[0]); } [Test] public void CheckAssertNotNullWithMessage() { tf.AssertNotNull(EXPECTED_MESSAGE, NOT_NULL); Assert.AreEqual("NotNull", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.AssertNotNull(EXPECTED_MESSAGE, null); Assert.AreEqual("NotNull", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.IsNull(Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckAssertNull() { tf.AssertNull(NOT_NULL); Assert.AreEqual("Null", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); tf.AssertNull(null); Assert.AreEqual("Null", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.IsNull(Arguments[0]); } [Test] public void CheckAssertNullWithMessage() { tf.AssertNull(EXPECTED_MESSAGE, NOT_NULL); Assert.AreEqual("Null", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.AssertNull(EXPECTED_MESSAGE, null); Assert.AreEqual("Null", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.IsNull(Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckFail() { tf.Fail(); Assert.AreEqual("Fail", MethodName); Assert.AreEqual(0, Arguments.Length); } [Test] public void CheckFailWithMessage() { tf.Fail(EXPECTED_MESSAGE); Assert.AreEqual("Fail", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[0]); } [Test] public void CheckAssertEquals() { tf.AssertEquals(1, 1); Assert.AreEqual("Equals", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(1, Arguments[0]); Assert.AreEqual(1, Arguments[1]); } [Test] public void CheckAssertEqualsWithMessage() { tf.AssertEquals(EXPECTED_MESSAGE, 1, 1); Assert.AreEqual("Equals", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreEqual(1, Arguments[0]); Assert.AreEqual(1, Arguments[1]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[2]); } [SetUp] public void BeforeEachTest() { // reset mock csUnit implementation csUnit.Assert.Reset(); // make provider stub instance tf = MakeProviderStubInstance(); } ITestFramework MakeProviderStubInstance() { csUnitStubMaker stubMaker = new csUnitStubMaker( providerAssembly, new SystemDynamicLinker() ); StubClassMaker scm = new StubClassMaker(); Type stubClass = scm.MakeStubClass(typeof(ITestFramework), stubMaker); ITestFramework stub = (ITestFramework) Activator.CreateInstance(stubClass); return stub; } } } namespace csUnit { /// <summary> /// Mock implementation of csUnit.Assert for testing. /// </summary> public class Assert { static string _methodName; static object[] _args = null; public static string MethodName { get { return _methodName; } } public static object[] Arguments { get { return _args; } } public static void Reset() { _methodName = null; _args = null; } public static void True(bool expression) { _methodName = "True"; _args = new object[] { expression }; } public static void True(bool expression, string message) { _methodName = "True"; _args = new object[] { expression, message }; } public static void NotNull(object obj) { _methodName = "NotNull"; _args = new object[] { obj }; } public static void NotNull(object obj, string message) { _methodName = "NotNull"; _args = new object[] { obj, message }; } public static new void Equals(object expected, object actual) { _methodName = "Equals"; _args = new object[] { expected, actual }; } public static void Equals( object expected, object actual, string message ) { _methodName = "Equals"; _args = new object[] { expected, actual, message }; } public static void Fail() { _methodName = "Fail"; _args = new object[0]; } public static void Fail(string message) { _methodName = "Fail"; _args = new object[] { message }; } public static void Null(object obj) { _methodName = "Null"; _args = new object[] { obj }; } public static void Null(object obj, string message) { _methodName = "Null"; _args = new object[] { obj, message }; } } } --- NEW FILE: MbUnitStubMakerTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; using DotNetMock.TestFramework; using DotNetMock.Core; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class MbUnitStubMakerTests { static readonly Assembly providerAssembly = Assembly.GetExecutingAssembly(); const string EXPECTED_MESSAGE = "MESSAGE"; const string NOT_NULL = "NOT-NULL"; ITestFramework tf; static string MethodName { get { return MbUnit.Core.Framework.Assert.MethodName; } } static object[] Arguments { get { return MbUnit.Core.Framework.Assert.Arguments; } } [Test] public void CheckAssert() { tf.Assert(true); Assert.AreEqual("IsTrue", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(true, Arguments[0]); tf.Assert(false); Assert.AreEqual("IsTrue", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(false, Arguments[0]); } [Test] public void CheckAssertWithMessage() { tf.Assert(EXPECTED_MESSAGE, true); Assert.AreEqual("IsTrue", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreEqual(true, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.Assert(EXPECTED_MESSAGE, false); Assert.AreEqual("IsTrue", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreEqual(false, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckAssertNotNull() { tf.AssertNotNull(NOT_NULL); Assert.AreEqual("IsNotNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); tf.AssertNotNull(null); Assert.AreEqual("IsNotNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.IsNull(Arguments[0]); } [Test] public void CheckAssertNotNullWithMessage() { tf.AssertNotNull(EXPECTED_MESSAGE, NOT_NULL); Assert.AreEqual("IsNotNull", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.AssertNotNull(EXPECTED_MESSAGE, null); Assert.AreEqual("IsNotNull", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.IsNull(Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckAssertNull() { tf.AssertNull(NOT_NULL); Assert.AreEqual("IsNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); tf.AssertNull(null); Assert.AreEqual("IsNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.IsNull(Arguments[0]); } [Test] public void CheckAssertNullWithMessage() { tf.AssertNull(EXPECTED_MESSAGE, NOT_NULL); Assert.AreEqual("IsNull", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.AssertNull(EXPECTED_MESSAGE, null); Assert.AreEqual("IsNull", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.IsNull(Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckFail() { tf.Fail(); Assert.AreEqual("Fail", MethodName); Assert.AreEqual(0, Arguments.Length); } [Test] public void CheckFailWithMessage() { tf.Fail(EXPECTED_MESSAGE); Assert.AreEqual("Fail", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[0]); } [Test] public void CheckAssertEquals() { tf.AssertEquals(1, 1); Assert.AreEqual("AreEqual", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(1, Arguments[0]); Assert.AreEqual(1, Arguments[1]); } [Test] public void CheckAssertEqualsWithMessage() { tf.AssertEquals(EXPECTED_MESSAGE, 1, 1); Assert.AreEqual("AreEqual", MethodName); Assert.AreEqual(4, Arguments.Length); Assert.AreEqual(1, Arguments[0]); Assert.AreEqual(1, Arguments[1]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[2]); } [SetUp] public void BeforeEachTest() { // reset mock MbUnit implementation MbUnit.Core.Framework.Assert.Reset(); // make provider stub instance tf = MakeProviderStubInstance(); } ITestFramework MakeProviderStubInstance() { MbUnitStubMaker stubMaker = new MbUnitStubMaker( providerAssembly, new SystemDynamicLinker() ); StubClassMaker scm = new StubClassMaker(); Type stubClass = scm.MakeStubClass(typeof(ITestFramework), stubMaker); ITestFramework stub = (ITestFramework) Activator.CreateInstance(stubClass); return stub; } } } namespace MbUnit.Core.Framework { /// <summary> /// Mock implementation of MbUnit.Core.Framework.Assert for testing. /// </summary> public class Assert { static string _methodName; static object[] _args = null; public static string MethodName { get { return _methodName; } } public static object[] Arguments { get { return _args; } } public static void Reset() { _methodName = null; _args = null; } public static void IsTrue(bool assertion) { _methodName = "IsTrue"; _args = new object[] { assertion }; } public static void IsTrue(bool assertion, string format, params object[] args) { _methodName = "IsTrue"; _args = new object[] { assertion, format, args }; } public static void IsNotNull(object nullable) { _methodName = "IsNotNull"; _args = new object[] { nullable }; } public static void IsNotNull(object nullable, string format, params object[] args) { _methodName = "IsNotNull"; _args = new object[] { nullable, format, args }; } public static void AreEqual(object expected, object actual) { _methodName = "AreEqual"; _args = new object[] { expected, actual }; } public static void AreEqual( object expected, object actual, string format, params object[] args ) { _methodName = "AreEqual"; _args = new object[] { expected, actual, format, args }; } public static void Fail() { _methodName = "Fail"; _args = new object[0]; } public static void Fail(string format, params object[] args) { _methodName = "Fail"; _args = new object[] { format, args }; } public static void IsNull(object nullable) { _methodName = "IsNull"; _args = new object[] { nullable }; } public static void IsNull(object nullable, string format, params object[] args) { _methodName = "IsNull"; _args = new object[] { nullable, format, args }; } } } --- NEW FILE: StubClassMakerTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; using DotNetMock.TestFramework; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class StubClassMakerTests { static bool CalledMethod1; interface ITrivialProvider { void Method1(); } class TrivialStubMaker : AbstractStubMaker { public TrivialStubMaker() : base(typeof(StubClassMakerTests)) { } public override void ImplementStubMethod(ILGenerator ilg, MethodInfo mi) { EmitProviderCall(ilg, "RealMethod1", new Type[0]); } } public static void RealMethod1() { CalledMethod1 = true; } [Test] public void TrivialProviderInterface() { StubClassMaker classBuilder = new StubClassMaker(); TrivialStubMaker tsm = new TrivialStubMaker(); Type stubClass = classBuilder.MakeStubClass( typeof(ITrivialProvider), tsm ); ITrivialProvider provider = (ITrivialProvider) Activator.CreateInstance(stubClass); provider.Method1(); Assert.IsTrue(CalledMethod1); } [SetUp] public void BeforeEachTest() { CalledMethod1 = false; } } } --- NEW FILE: ImplementationFactoryTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Collections; using System.Reflection; using NUnit.Framework; using DotNetMock.TestFramework; using DotNetMock.Core; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class ImplementationFactoryTests { const string EXPECTED_STATIC_ASSEMBLY_NAME = "Assembly"; static readonly string EXPECTED_STATIC_TYPE_NAME = typeof(TestStaticImplementation).FullName; MockLinker linker; TestStaticImplementation implementation; Hashtable env; [Test] public void UseStaticImplementation() { linker.ExpectedAssemblyName = EXPECTED_STATIC_ASSEMBLY_NAME; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(TestStaticImplementation); env["DotNetMock_TestingAssembly"] = EXPECTED_STATIC_ASSEMBLY_NAME; env["DotNetMock_TestingComponent"] = EXPECTED_STATIC_TYPE_NAME; ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(1, linker.ActualAssemblyNames.Count); Assert.AreEqual("Assembly", linker.ActualAssemblyNames.Pop()); Assert.AreEqual(EXPECTED_STATIC_TYPE_NAME, linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual(typeof(TestStaticImplementation), linker.ActualType); } [Test] public void UseDynamicNUnitImplementation() { linker.ExpectedAssemblyName = "nunit.framework"; linker.ExpectedAssembly = typeof(NUnit.Framework.Assertion).Module.Assembly; linker.ExpectedType = typeof(NUnit.Framework.Assertion); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(1, linker.ActualAssemblyNames.Count); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("NUnit.Framework.Assertion", linker.ActualTypeName); Assert.AreSame(typeof(NUnit.Framework.Assertion).Module.Assembly, linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicMbUnitImplementation() { linker.ExpectedAssemblyName = "MbUnit.Core"; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(MbUnit.Core.Framework.Assert); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(2, linker.ActualAssemblyNames.Count); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core.Framework.Assert", linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicCsUnitImplementation() { linker.ExpectedAssemblyName = "csUnit"; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(csUnit.Assert); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(3, linker.ActualAssemblyNames.Count); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit.Assert", linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicNUnitImplementationViaPartialName() { linker.ExpectedAssemblyName = "xxx"; linker.ExpectedPartialAssemblyName = "nunit.framework"; linker.ExpectedAssembly = typeof(NUnit.Framework.Assertion).Module.Assembly; linker.ExpectedType = typeof(NUnit.Framework.Assertion); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(4, linker.ActualAssemblyNames.Count); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("NUnit.Framework.Assertion", linker.ActualTypeName); Assert.AreSame(typeof(NUnit.Framework.Assertion).Module.Assembly, linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicMbUnitImplementationViaPartialName() { linker.ExpectedAssemblyName = "xxx"; linker.ExpectedPartialAssemblyName = "MbUnit.Core"; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(MbUnit.Core.Framework.Assert); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(5, linker.ActualAssemblyNames.Count); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core.Framework.Assert", linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicCsUnitImplementationViaPartialName() { linker.ExpectedAssemblyName = "xxx"; linker.ExpectedPartialAssemblyName = "csUnit"; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(csUnit.Assert); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(6, linker.ActualAssemblyNames.Count); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit.Assert", linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [SetUp] public void BeforeEachTest() { linker = new MockLinker(); implementation = new TestStaticImplementation(); env = new Hashtable(); linker.ExpectedInstance = implementation; } public class TestStaticImplementation : ITestFramework { #region ITestFramework Members public void Assert(bool assertion) { // TODO: Add TestStaticImplementation.Assert implementation } void DotNetMock.Core.ITestFramework.Assert(string message, bool assertion) { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.Assert implementation } public void AssertNotNull(object assertion) { // TODO: Add TestStaticImplementation.AssertNotNull implementation } void DotNetMock.Core.ITestFramework.AssertNotNull(string message, object assertion) { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.AssertNotNull implementation } public void AssertEquals(object expectedObject, object actualObject) { // TODO: Add TestStaticImplementation.AssertEquals implementation } void DotNetMock.Core.ITestFramework.AssertEquals(string message, object expectedObject, object actualObject) { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.AssertEquals implementation } public void Fail(string message) { // TODO: Add TestStaticImplementation.Fail implementation } void DotNetMock.Core.ITestFramework.Fail() { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.Fail implementation } public void AssertNull(object assertion) { // TODO: Add TestStaticImplementation.AssertNull implementation } void DotNetMock.Core.ITestFramework.AssertNull(string message, object assertion) { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.AssertNull implementation } #endregion } class MockLinker : IDynamicLinker { public Stack ActualAssemblyNames = new Stack(); public string ExpectedAssemblyName = null; public string ExpectedPartialAssemblyName = null; public Assembly ExpectedAssembly = null; public string ActualTypeName = null; public Assembly ActualAssembly = null; public Type ExpectedType = null; public Type ActualType = null; public object ExpectedInstance = null; #region IDynamicLinker Members public Assembly LoadAssembly(string name) { ActualAssemblyNames.Push(name); if ( name!=ExpectedAssemblyName ) { return null; } return ExpectedAssembly; } public Assembly LoadAssemblyWithPartialName(string name) { ActualAssemblyNames.Push(name); if ( name!=ExpectedPartialAssemblyName ) { return null; } return ExpectedAssembly; } public Type GetType(string typeName, Assembly assembly) { ActualTypeName = typeName; ActualAssembly = assembly; return ExpectedType; } public object CreateInstance(Type type) { ActualType = type; return ExpectedInstance; } #endregion } } } --- NEW FILE: AssemblyInfo.cs --- using System.Reflection; using System.Runtime.CompilerServices; // // 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("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // // 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 Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")] // // In order to sign your assembly you must specify a key to use. Refer to the // Microsoft .NET Framework documentation for more information on assembly signing. // // Use the attributes below to control which key is used for signing. // // Notes: // (*) If no key is specified, the assembly is not signed. // (*) KeyName refers to a key that has been installed in the Crypto Service // Provider (CSP) on your machine. KeyFile refers to a file which contains // a key. // (*) If the KeyFile and the KeyName values are both specified, the // following processing occurs: // (1) If the KeyName can be found in the CSP, that key is used. // (2) If the KeyName does not exist and the KeyFile does exist, the key // in the KeyFile is installed into the CSP and used. // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. // When specifying the KeyFile, the location of the KeyFile should be // relative to the project output directory which is // %Project Directory%\obj\<configuration>. For example, if your KeyFile is // located in the project directory, you would specify the AssemblyKeyFile // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework // documentation for more information on this. // [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] |