public void MethodCallOnRecordsAddToExpectations() { MockRepository mocks = new MockRepository(); ProxyInstance proxy = new ProxyInstance(mocks); RecordMockState recordState = new RecordMockState(proxy, mocks); recordState.MethodCall(new FakeInvocation(method), method, ""); recordState.LastExpectation.ReturnValue = true; Assert.NotNull(Get.Recorder(mocks).GetAllExpectationsForProxyAndMethod(proxy, method)); recordState.MethodCall(new FakeInvocation(method), method, ""); recordState.LastExpectation.ReturnValue = true; Assert.Equal(2, recordState.MethodCallsCount); }
public void MethodCallAddExpectation() { MockRepository mocks = new MockRepository(); ProxyInstance proxy = new ProxyInstance(mocks); RecordMockState recordState = new RecordMockState(proxy, mocks); recordState.MethodCall(new FakeInvocation(method), method, "1"); recordState.LastExpectation.ReturnValue = false; Assert.Equal(1, Get.Recorder(mocks).GetAllExpectationsForProxyAndMethod(proxy, method).Count); recordState.MethodCall(new FakeInvocation(method), method, "2"); recordState.LastExpectation.ReturnValue = false; Assert.Equal(2, Get.Recorder(mocks).GetAllExpectationsForProxyAndMethod(proxy, method).Count); }
public void ArgsEqualExpectationUsedForMethodsWithNoOutParameters() { MockRepository mocks = new MockRepository(); RecordMockState recordState = new RecordMockState(new ProxyInstance(mocks), mocks); Assert.IsNull(recordState.LastExpectation); recordState.MethodCall(new FakeInvocation(method), method, ""); Assert.IsInstanceOfType(typeof(ArgsEqualExpectation), recordState.LastExpectation); }
public void GetMethodOptionsForLastMethod() { MockRepository mocks = new MockRepository(); RecordMockState recordState = new RecordMockState(new ProxyInstance(mocks), mocks); recordState.MethodCall(new FakeInvocation(method), method, ""); Assert.NotNull(recordState.LastMethodOptions); }
public void SetUp() { mocks = new MockRepository(); proxy = new ProxyInstance(mocks); startsWith = CreateMethodInfo(); record = new RecordMockState(proxy, mocks); record.MethodCall(new FakeInvocation(startsWith), startsWith, "2"); replay = new ReplayMockState(record); }
public void ArgsEqualExpectationUsedForMethodsWithNoOutParameters() { MockRepository mocks = new MockRepository(); RecordMockState recordState = new RecordMockState(new ProxyInstance(mocks), mocks); Assert.Null(recordState.LastExpectation); recordState.MethodCall(new FakeInvocation(method), method, ""); Assert.IsType(typeof(ArgsEqualExpectation), recordState.LastExpectation); }
public ReplayMockStateTests() { mocks = new MockRepository(); proxy = new ProxyInstance(mocks); startsWith = CreateMethodInfo(); record = new RecordMockState(proxy, mocks); record.MethodCall(new FakeInvocation(startsWith), startsWith, "2"); replay = new ReplayMockState(record); }
public void ConstraintsExpectationUsedForMethodsWithNoOutParameters() { MethodInfo methodWithOutParams = typeof(Double).GetMethod("TryParse", new Type[] { typeof(string), typeof(Double).MakeByRefType() }); MockRepository mocks = new MockRepository(); RecordMockState recordState = new RecordMockState(new ProxyInstance(mocks), mocks); Assert.Null(recordState.LastExpectation); recordState.MethodCall(new FakeInvocation(methodWithOutParams), methodWithOutParams, "", 0); Assert.IsType(typeof(ConstraintsExpectation), recordState.LastExpectation); }
public void LastExpectationIsFilledOnCall() { MockRepository mocks = new MockRepository(); RecordMockState recordState = new RecordMockState(new ProxyInstance(mocks), mocks); Assert.Null(recordState.LastExpectation); recordState.MethodCall(new FakeInvocation(method), method, ""); Assert.NotNull(recordState.LastExpectation); Assert.True(recordState.LastExpectation.IsExpected(new object[] { "" })); }
public void CantMoveToReplayStateWithoutclosingLastMethod() { MockRepository mocks = new MockRepository(); ProxyInstance proxy = new ProxyInstance(mocks); RecordMockState recordState = new RecordMockState(proxy, mocks); recordState.MethodCall(new FakeInvocation(method), method, ""); Assert.Throws <InvalidOperationException>( "Previous method 'String.StartsWith(\"\");' requires a return value or an exception to throw.", () => recordState.Replay()); }
public void VerifyReportsAllMissingExpectationsWhenCalled() { record.LastExpectation.ReturnValue = true; MethodInfo method = CreateMethodInfo(); record.MethodCall(new FakeInvocation(method), method, "r"); record.LastExpectation.ReturnValue = true; record.MethodCall(new FakeInvocation(method), method, "y"); record.LastExpectation.ReturnValue = true; record.LastExpectation.Expected = new Range(2, 2); ReplayMockState replay = new ReplayMockState(record); try { replay.Verify(); } catch (Exception e) { string message = "String.StartsWith(\"2\"); Expected #1, Actual #0.\r\n" + "String.StartsWith(\"r\"); Expected #1, Actual #0.\r\n" + "String.StartsWith(\"y\"); Expected #2, Actual #0."; Assert.Equal(message, e.Message); } }
public void ConstraintsExpectationUsedForMethodsWithNoOutParameters() { MethodInfo methodWithOutParams = typeof(Double).GetMethod("TryParse", new Type[] { typeof(string), typeof(Double).MakeByRefType() }); MockRepository mocks = new MockRepository(); RecordMockState recordState = new RecordMockState(new ProxyInstance(mocks), mocks); Assert.IsNull(recordState.LastExpectation); recordState.MethodCall(new FakeInvocation(methodWithOutParams), methodWithOutParams, "", 0); Assert.IsInstanceOfType(typeof(ConstraintsExpectation), recordState.LastExpectation); }
public void CantMoveToReplayStateWithoutclosingLastMethod() { MockRepository mocks = new MockRepository(); ProxyInstance proxy = new ProxyInstance(mocks); RecordMockState recordState = new RecordMockState(proxy, mocks); recordState.MethodCall(new FakeInvocation(method), method, ""); recordState.Replay(); }
public void MethodCallOnRecordsAddToExpectations() { MockRepository mocks = new MockRepository(); ProxyInstance proxy = new ProxyInstance(mocks); RecordMockState recordState = new RecordMockState(proxy, mocks); recordState.MethodCall(new FakeInvocation(method), method, ""); recordState.LastExpectation.ReturnValue = true; Assert.IsNotNull(Get.Recorder(mocks).GetAllExpectationsForProxyAndMethod(proxy, method), "Record state didn't record the method call."); recordState.MethodCall(new FakeInvocation(method), method, ""); recordState.LastExpectation.ReturnValue = true; Assert.AreEqual(2, recordState.MethodCallsCount); }
public void MethodCallAddExpectation() { MockRepository mocks = new MockRepository(); ProxyInstance proxy = new ProxyInstance(mocks); RecordMockState recordState = new RecordMockState(proxy, mocks); recordState.MethodCall(new FakeInvocation(method), method, "1"); recordState.LastExpectation.ReturnValue = false; Assert.AreEqual(1, Get.Recorder(mocks).GetAllExpectationsForProxyAndMethod(proxy, method).Count); recordState.MethodCall(new FakeInvocation(method), method, "2"); recordState.LastExpectation.ReturnValue = false; Assert.AreEqual(2, Get.Recorder(mocks).GetAllExpectationsForProxyAndMethod(proxy, method).Count); }
public void LastExpectationIsFilledOnCall() { MockRepository mocks = new MockRepository(); RecordMockState recordState = new RecordMockState(new ProxyInstance(mocks), mocks); Assert.IsNull(recordState.LastExpectation); recordState.MethodCall(new FakeInvocation(method), method, ""); Assert.IsNotNull(recordState.LastExpectation); Assert.IsTrue(recordState.LastExpectation.IsExpected(new object[] {""})); }
public void GetMethodOptionsForLastMethod() { MockRepository mocks = new MockRepository(); RecordMockState recordState = new RecordMockState(new ProxyInstance(mocks), mocks); recordState.MethodCall(new FakeInvocation(method), method, ""); Assert.IsNotNull(recordState.LastMethodOptions); }
public void CantMoveToReplayStateWithoutclosingLastMethod() { MockRepository mocks = new MockRepository(); ProxyInstance proxy = new ProxyInstance(mocks); RecordMockState recordState = new RecordMockState(proxy, mocks); recordState.MethodCall(new FakeInvocation(method), method, ""); string expectedMessage="Previous method 'String.StartsWith(\"\");' requires a return value or an exception to throw."; InvalidOperationException ex = Assert.Throws<InvalidOperationException>( () => recordState.Replay()); Assert.Equal(expectedMessage, ex.Message); }