public void Test() { TestInterface duck = DuckTyping.Implement <TestInterface> (new TestClass()); TestInterface same = DuckTyping.Implement <TestInterface> (duck); TestInterface2 duck2 = DuckTyping.Implement <TestInterface2>(same); Assert.AreSame(duck, same); int value; duck.Method(33, out value); Assert.AreEqual(33, value); Assert.AreEqual(42, duck.Method(40)); Assert.AreEqual(22, duck.Prop); duck.Event += duck_Event; duck.CallEvent(); Assert.AreEqual(55, eventValue); duck2.I2Method(33, out value); Assert.AreEqual(33, value); Assert.AreEqual(42, duck2.Method(40)); }
protected override void Given() { instance = MockRepository.GenerateStub <TestInterface>(); instance.Expect( x => x.BeginMethod( Arg <string> .Is.Anything, Arg <AsyncCallback> .Is.Anything, Arg <object> .Is.Anything)) .Return(null) .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(null)); instance.Expect(x => x.EndMethod(null)) .Throw(exception); instance.Expect( x => x.BeginFunction( Arg <string> .Is.Anything, Arg <AsyncCallback> .Is.Anything, Arg <object> .Is.Anything)) .Return(null) .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(null)); instance.Expect(x => x.EndFunction(null)) .Throw(exception); command = new AsyncPatternCommand(() => instance.Method(null)); query = new AsyncPatternQuery <string>(() => instance.Function(null)); }
public void StructTest() { DuckTyping.AllowStaticMembers = true; TestInterface duck = DuckTyping.Implement <TestInterface> (new TestStruct()); Assert.AreEqual(43, duck.Method(40)); }
protected override void Given() { instance = MockRepository.GenerateStub<TestInterface>(); instance.Expect( x => x.BeginMethod( Arg<string>.Is.Anything, Arg<AsyncCallback>.Is.Anything, Arg<object>.Is.Anything)) .Return(null) .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(null)); instance.Expect(x => x.EndMethod(null)) .Throw(exception); instance.Expect( x => x.BeginFunction( Arg<string>.Is.Anything, Arg<AsyncCallback>.Is.Anything, Arg<object>.Is.Anything)) .Return(null) .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(null)); instance.Expect(x => x.EndFunction(null)) .Throw(exception); command = new AsyncCommand(() => instance.Method(null), true); query = new AsyncQuery<string>(() => instance.Function(null), true); }
protected override void Given() { instance = MockRepository.GenerateStrictMock <TestInterface>(); ar = MockRepository.GenerateStub <IAsyncResult>(); instance.Expect( x => x.BeginMethod( Arg <string> .Is.Equal(parameter), Arg <AsyncCallback> .Is.NotNull, Arg <object> .Is.Null)) .Return(null) .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(ar)); instance.Expect(x => x.EndMethod(ar)); instance.Expect( x => x.BeginFunction( Arg <string> .Is.Equal(parameter), Arg <AsyncCallback> .Is.NotNull, Arg <object> .Is.Null)) .Return(null) .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(ar)); instance.Expect(x => x.EndFunction(ar)).Return(result); command = new AsyncPatternCommand(() => instance.Method(parameter)); query = new AsyncPatternQuery <string>(() => instance.Function(parameter)); }
protected override void Given() { instance = MockRepository.GenerateStrictMock<TestInterface>(); ar = MockRepository.GenerateStub<IAsyncResult>(); instance.Expect( x => x.BeginMethod( Arg<string>.Is.Equal(parameter), Arg<AsyncCallback>.Is.NotNull, Arg<object>.Is.Null)) .Return(null) .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(ar)); instance.Expect(x => x.EndMethod(ar)); instance.Expect( x => x.BeginFunction( Arg<string>.Is.Equal(parameter), Arg<AsyncCallback>.Is.NotNull, Arg<object>.Is.Null)) .Return(null) .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(ar)); instance.Expect(x => x.EndFunction(ar)).Return(result); command = new AsyncCommand(() => instance.Method(parameter), true); query = new AsyncQuery<string>(() => instance.Function(parameter), true); }
public void InheritanceTest2() { TestInterface duck1 = DuckTyping.Implement <TestInterface, TestClass> (new Child1()); TestInterface duck2 = DuckTyping.Implement <TestInterface, TestClass> (new Child2()); Assert.AreNotSame(duck1, duck2); Assert.AreEqual(42, duck1.Method(40)); Assert.AreEqual(42, duck2.Method(40)); }
protected override void Given() { instance = MockRepository.GenerateStub<TestInterface>(); instance.Expect(x => x.Method(null)).Throw(exception); instance.Expect(x => x.Function(null)).Throw(exception); command = new AsyncCommand(()=> instance.Method(null)); query = new AsyncQuery<string>(()=> instance.Function(null)); }
protected override void Given() { instance = MockRepository.GenerateStub <TestInterface>(); instance.Expect(x => x.Method(null)).Throw(exception); instance.Expect(x => x.Function(null)).Throw(exception); command = new AsyncCommand(() => instance.Method(null)); query = new AsyncQuery <string>(() => instance.Function(null)); }
protected override void Given() { instance = MockRepository.GenerateStrictMock<TestInterface>(); instance.Expect(x => x.Method(parameter)) .WhenCalled(x => callThreadId = CurrentThreadId()); instance.Expect(x => x.Function(parameter)).Return(result) .WhenCalled(x => callThreadId = CurrentThreadId()); ; command = new AsyncCommand(()=> instance.Method(parameter)); query = new AsyncQuery<string>(()=> instance.Function(parameter)); }
public void ShouldWireCallback() { bool proxyCalled = false; TestInterface proxy = Proxifier.WithoutBaseClass(new FuncProxyAction((instance, method, args) => { proxyCalled = true; return(null); })) .WithInterfaces(typeof(TestInterface)) .Build <TestInterface>(); proxy.Method(); Assert.True(proxyCalled, "The proxy callback was not invoked"); }
protected override void Given() { instance = MockRepository.GenerateStrictMock <TestInterface>(); instance.Expect(x => x.Method(parameter)) .WhenCalled(x => callThreadId = CurrentThreadId()); instance.Expect(x => x.Function(parameter)).Return(result) .WhenCalled(x => callThreadId = CurrentThreadId());; command = new AsyncCommand(() => instance.Method(parameter)); query = new AsyncQuery <string>(() => instance.Function(parameter)); }