public void AbstractClassWithBasicProperty() { var testScript = LoadAssembly <AAbstractClassWithBasicProperty>(); var context = testScript.Context; var mock = testScript.MockObject; Assert.Throws <MockException>(() => context.AssertGet(f => f.OnlyGet)); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 5678)); Assert.Throws <MockException>(() => context.AssertGet(f => f.GetAndSet)); context.Arrange(f => f.OnlyGet).Returns(1234); Assert.Equal(1234, mock.OnlyGet); context.ArrangeProperty(f => f.GetAndSet); mock.GetAndSet = 5678; Assert.Equal(5678, mock.GetAndSet); context.AssertSet_When(f => f.GetAndSet = 5678); context.AssertGet(f => f.GetAndSet); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 1234)); Assert.Throws <MockException>(() => context.AssertGet(f => f.OnlyGet, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 5678, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertGet(f => f.GetAndSet, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertGet(f => f.OnlyGet, Invoked.Exactly(2))); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 5678, Invoked.Exactly(2))); Assert.Throws <MockException>(() => context.AssertGet(f => f.GetAndSet, Invoked.Exactly(2))); Assert.Equal(KExpected, testScript.DoRun()); }
public void GenericAbstractClass() { var testScript = LoadAssembly <AGenericAbstractClass <int> >(); var context = testScript.Context; var mock = testScript.MockObject; mock.DoSomething(1234); context.Assert(f => f.DoSomething(1234)); context.Arrange(f => f.GetSomething()).Returns(5678); Assert.Equal(5678, mock.GetSomething()); Assert.Throws <MockException>(() => context.AssertGet(f => f.OnlyGet)); context.Arrange(f => f.OnlyGet).Returns(9012); Assert.Equal(9012, mock.OnlyGet); context.AssertGet(f => f.OnlyGet); Assert.Throws <MockException>(() => context.AssertGet(f => f.OnlyGet, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertGet(f => f.OnlyGet, Invoked.Exactly(2))); Assert.Throws <MockException>(() => context.AssertGet(f => f.GetAndSet)); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 3456)); context.ArrangeProperty(f => f.GetAndSet); mock.GetAndSet = 3456; Assert.Equal(3456, mock.GetAndSet); context.AssertGet(f => f.GetAndSet); context.AssertSet_When(f => f.GetAndSet = 3456); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 1234)); Assert.Throws <MockException>(() => context.AssertGet(f => f.GetAndSet, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 3456, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertGet(f => f.GetAndSet, Invoked.Exactly(2))); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 3456, Invoked.Exactly(2))); Assert.Equal(KExpected, testScript.DoRun()); }
public void Assert_ExpectedExactly3TimesAnd2TimesInvoked_ThrowsException() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Exactly(3)); }
public void GenericMockAndGenericInterface() { const string resource = "GenericMockAndGenericInterface"; const string className = resource + "`1"; var testScript = LoadAssembly <IGenericMockAndGenericInterface <int> >(resource, className); var context = testScript.Context; var mock = testScript.MockObject; mock.DoSomething(1234); context.Assert(f => f.DoSomething(1234)); context.Arrange(f => f.GetSomething()).Returns(5678); Assert.Equal(5678, mock.GetSomething()); Assert.Throws <MockException>(() => context.AssertGet(f => f.OnlyGet)); context.Arrange(f => f.OnlyGet).Returns(9012); Assert.Equal(9012, mock.OnlyGet); context.AssertGet(f => f.OnlyGet); Assert.Throws <MockException>(() => context.AssertGet(f => f.OnlyGet, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertGet(f => f.OnlyGet, Invoked.Exactly(2))); Assert.Throws <MockException>(() => context.AssertGet(f => f.GetAndSet)); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 3456)); context.ArrangeProperty(f => f.GetAndSet); mock.GetAndSet = 3456; Assert.Equal(3456, mock.GetAndSet); context.AssertGet(f => f.GetAndSet); context.AssertSet_When(f => f.GetAndSet = 3456); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 1234)); Assert.Throws <MockException>(() => context.AssertGet(f => f.GetAndSet, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 3456, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertGet(f => f.GetAndSet, Invoked.Exactly(2))); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.GetAndSet = 3456, Invoked.Exactly(2))); Assert.Equal(KExpected, testScript.DoRun()); }
public void AbstractClassWithMultipleNamespaces() { var testScript = LoadAssembly <AAbstractClassWithMultipleNamespaces>(); var context = testScript.Context; var mock = testScript.MockObject; var arg1 = new MultipleNamespacesArgument(); mock.DoSomething(arg1); context.Assert(f => f.DoSomething(arg1)); var arg2 = new MultipleNamespacesArgument(); context.Arrange(f => f.GetSomething()).Returns(arg2); Assert.Same(expected: arg2, mock.GetSomething()); var arg3 = new MultipleNamespacesArgument(); Assert.Throws <MockException>(() => context.AssertGet(f => f.SomeProperty)); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.SomeProperty = arg3)); context.ArrangeProperty(f => f.SomeProperty); mock.SomeProperty = arg3; Assert.Same(expected: arg3, mock.SomeProperty); context.AssertGet(f => f.SomeProperty); context.AssertSet_When(f => f.SomeProperty = arg3); Assert.Throws <MockException>(() => context.AssertGet(f => f.SomeProperty, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.SomeProperty = arg3, Invoked.Never)); Assert.Throws <MockException>(() => context.AssertGet(f => f.SomeProperty, Invoked.Exactly(2))); Assert.Throws <MockException>(() => context.AssertSet_When(f => f.SomeProperty = arg3, Invoked.Exactly(2))); Assert.Equal(KExpected, testScript.DoRun()); }