public void Prig_should_fake_static_property_set() { using (new IndirectionsContext()) { // Arrange PFoo.StaticConstructor().Body = () => { }; var fooPropSetMock = new Mock <IndirectionAction <int> >(MockBehavior.Strict); fooPropSetMock.Setup(_ => _(10)); PFoo.FooPropSetInt32().Body = fooPropSetMock.Object; // Act, Assert Foo.FooProp = 10; } }
public void Prig_should_assert_call_on_void() { using (new IndirectionsContext()) { // Arrange var called = false; PFoo.Execute().Body = @this => called = true; // Act new Foo().Execute(); // Assert Assert.IsTrue(called); } }
public void Prig_should_arrange_static_function() { using (new IndirectionsContext()) { // Arrange PFoo.StaticConstructor().Body = () => { }; PFoo.FooPropGet().Body = () => 0; // Act var actual = Foo.FooProp; // Assert Assert.AreEqual(0, actual); } }
public void Prig_should_assert_call_on_void_through_an_explict_implemented_interface() { using (new IndirectionsContext()) { // Arrange var called = false; PFoo.SealedMockingMigrationIFooExecuteInt32().Body = (@this, arg1) => called = true; var foo = new Foo(); // Act var iFoo = (IFoo)foo; iFoo.Execute(1); // Assert Assert.IsTrue(called); } }
public void Prig_should_assert_call_on_void_through_an_interface() { using (new IndirectionsContext()) { // Arrange var called = false; PFoo.Execute().Body = @this => called = true; var foo = new Foo(); // Act var iFoo = (IFoo)foo; iFoo.Execute(); // Assert Assert.IsTrue(called); } }
public void Prig_should_fake_static_property_get() { using (new IndirectionsContext()) { // Arrange PFoo.StaticConstructor().Body = () => { }; var called = false; PFoo.FooPropGet().Body = () => { called = true; return(1); }; // Act var actual = Foo.FooProp; // Assert Assert.AreEqual(1, actual); Assert.IsTrue(called); } }
public void Prig_should_throw_when_not_arranged() { using (new IndirectionsContext()) { // Arrange PFoo.StaticConstructor().Body = () => { }; var executeMock = new Mock <IndirectionFunc <int, int> >(MockBehavior.Strict); executeMock.Setup(_ => _(10)).Returns(10); PFoo.ExecuteInt32().Body = executeMock.Object; var submitMock = new Mock <IndirectionAction>(MockBehavior.Strict); PFoo.Submit().Body = submitMock.Object; // Act, Assert Assert.AreEqual(10, Foo.Execute(10)); Assert.Throws <MockException>(() => Foo.Submit()); } }
public void FormatCurrentThreadTimes_on_execute_should_return_expected() { using (new IndirectionsContext()) { // Arrange PFoo.GetThreadTimesIntPtrInt64RefInt64RefInt64RefInt64Ref().Body = (IntPtr hThread, out long lpCreationTime, out long lpExitTime, out long lpKernelTime, out long lpUserTime) => { lpCreationTime = 0; lpExitTime = 1; lpKernelTime = 2; lpUserTime = 3; return(true); }; // Act var actual = new Foo().FormatCurrentThreadTimes(); // Assert Assert.AreEqual("Creation Time: 0, Exit Time: 1, Kernel Time: 2, User Time: 3", actual); } }