public void TestPropertyStubWithGetterAndSetter_Set_MockBehavior_Strict() { var stub = new StubITestInterface(MockBehavior.Strict); ITestInterface testInterface = stub; testInterface.Prop3 = string.Empty; }
public void TestMethod_Void_WithNoParameters_DefaultBehavior_Strict() { var stub = new StubITestInterface(MockBehavior.Strict); ITestInterface testInterface = stub; testInterface.DoSomething(); }
public void TestMockBehaviorProperty_CanBeChangedAtRuntime() { StubITestInterface stub = new StubITestInterface(MockBehavior.Strict); ITestInterface testInterface = stub; bool wasExceptionThrownInStrictMode = false; bool wasExceptionThrownInStrictMode2ndTime = false; // Check for exception in strict mode try { testInterface.DoSomething(); } catch (SimpleStubsException) { wasExceptionThrownInStrictMode = true; } // Switch to loose mode, do not expect exception stub.MockBehavior = MockBehavior.Loose; testInterface.DoSomething(); // Switch back to strict mode and check for exception stub.MockBehavior = MockBehavior.Strict; try { testInterface.DoSomething(); } catch (SimpleStubsException) { wasExceptionThrownInStrictMode2ndTime = true; } Assert.AreEqual(true, wasExceptionThrownInStrictMode); Assert.AreEqual(true, wasExceptionThrownInStrictMode2ndTime); }
public void TestPropertyStubWithSetterOnly_Set_MockBehavior_Loose() { var stub = new StubITestInterface(MockBehavior.Loose); ITestInterface testInterface = stub; testInterface.Prop2 = string.Empty; }
public void TestPropertyStubWithGetterOnly_Get_MockBehavior_Loose() { var stub = new StubITestInterface(MockBehavior.Loose); ITestInterface testInterface = stub; string returnedValue = testInterface.Prop1; Assert.IsNull(returnedValue); }
public void TestMethod_Void_WithNoParameters() { var stub = new StubITestInterface(); bool wasDelegateCalled = false; stub.DoSomething(() => { wasDelegateCalled = true; }); ITestInterface testInterface = stub; testInterface.DoSomething(); Assert.IsTrue(wasDelegateCalled); }
public async Task TestMethod_Void_WithNoParameters_Async() { var stub = new StubITestInterface(); bool wasDelegateCalled = false; stub.DoSomethingAsync(async() => { await Task.Run(() => wasDelegateCalled = true); }); ITestInterface testInterface = stub; await testInterface.DoSomethingAsync(); Assert.IsTrue(wasDelegateCalled); }
public void TestTupleParametersAndReturnType() { (float x, float y)coordinates = (0.0f, 0.0f); var stub = new StubITestInterface() .SetCoordinates((coords) => coordinates = coords) .GetCoordinates(() => coordinates); ITestInterface testInterface = (ITestInterface)stub; testInterface.SetCoordinates((1.0f, 2.0f)); Assert.AreEqual((1.0f, 2.0f), coordinates); }
public void TestMockBehaviorProperty_MatchesConstructorSuppliedValue_Strict() { StubITestInterface stub = new StubITestInterface(MockBehavior.Strict); Assert.AreEqual(MockBehavior.Strict, stub.MockBehavior); }
public void TestPropertyStubWithGetterOnly_Get_MockBehavior_Strict() { var stub = new StubITestInterface(MockBehavior.Strict); ITestInterface testInterface = stub; string returnedValue = testInterface.Prop1; }
public async Task TestMethod_Void_WithNoParameters_DefaultBehavior_Loose_Async() { var stub = new StubITestInterface(MockBehavior.Loose); ITestInterface testInterface = stub; await testInterface.DoSomethingAsync(); }