public IMethodRecorderTests() { demo = MockRepository.GenerateStrictMock(typeof(IDemo), null, null) as IDemo; voidNoArgs = typeof (IDemo).GetMethod("VoidNoArgs"); voidThreeArgs = typeof (IDemo).GetMethod("VoidThreeStringArgs"); expectationOne = new AnyArgsExpectation(new FakeInvocation(this.voidNoArgs), new Range(1, 1)); expectationTwo = new AnyArgsExpectation(new FakeInvocation(voidThreeArgs), new Range(1, 1)); recorder = CreateRecorder(); ChildSetup(); }
/// <summary> /// Determines if the object equal to expectation /// </summary> public override bool Equals(object obj) { AnyArgsExpectation other = obj as AnyArgsExpectation; if (other == null) { return(false); } return(Method.Equals(other.Method)); }
public void EqualsTest() { ProxyInstance proxy1 = new ProxyInstance(null); ProxyInstance proxy2 = new ProxyInstance(null); MethodInfo method1 = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) }), method2 = endsWith; IExpectation expectation1 = new AnyArgsExpectation(new FakeInvocation(method1), new Range(1, 1)), expectation2 = new AnyArgsExpectation(new FakeInvocation(method2), new Range(1, 1)); ProxyMethodExpectationTriplet same1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), same2 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1); Assert.AreEqual(same1, same2); Assert.AreEqual(same2, same1); ProxyMethodExpectationTriplet proxyDiff1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), proxyDiff2 = new ProxyMethodExpectationTriplet(proxy2, method1, expectation1); Assert.AreNotEqual(proxyDiff2, proxyDiff1); Assert.AreNotEqual(proxyDiff1, proxyDiff2); ProxyMethodExpectationTriplet methodDiff1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), methodDiff2 = new ProxyMethodExpectationTriplet(proxy1, method2, expectation1); Assert.AreNotEqual(methodDiff1, methodDiff2); Assert.AreNotEqual(methodDiff2, methodDiff1); ProxyMethodExpectationTriplet expectationDiff1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), expectationDiff2 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation2); Assert.AreNotEqual(expectationDiff1, expectationDiff2); Assert.AreNotEqual(expectationDiff2, expectationDiff1); ProxyMethodExpectationTriplet allDiff1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), allDiff2 = new ProxyMethodExpectationTriplet(proxy2, method2, expectation2); Assert.AreNotEqual(allDiff1, allDiff2); Assert.AreNotEqual(allDiff2, allDiff1); }
protected override IExpectation GetExpectation(MethodInfo m, Range r, int actual) { AnyArgsExpectation expectation = new AnyArgsExpectation(new FakeInvocation(m), new Range(1, 1)); SetupExpectation(expectation, r, actual); return expectation; }
public AnyArgsExpectationTests() { method = typeof(int).GetMethod("CompareTo", new Type[] { typeof(object) }); equal = new ArgsEqualExpectation(new FakeInvocation(this.method), new object[] {1}, new Range(1, 1)); any = new AnyArgsExpectation(this.equal); }
public void ReplaceExpectationWhenNestingOrdering() { recorder.AddRecorder(CreateRecorder()); recorder.Record(this.demo, this.voidNoArgs, expectationOne); AnyArgsExpectation newExpectation = new AnyArgsExpectation(new FakeInvocation(voidNoArgs), new Range(1, 1)); recorder.ReplaceExpectation(demo, voidNoArgs, expectationOne, newExpectation); ExpectationsList list = recorder.GetAllExpectationsForProxyAndMethod(demo, voidNoArgs); Assert.Same(newExpectation, list[0]); }
public void TryingToPassNullToReturnOrThrowWithActionWillThrow() { AnyArgsExpectation expectation = new AnyArgsExpectation(new FakeInvocation(typeof(object).GetMethod("ToString")), new Range(1, 1)); expectation.ActionToExecute = (ToStringDelegate)delegate { return "fpp"; }; expectation.ReturnOrThrow(null,null); }
public void TryingToPassNullToReturnOrThrowWithActionWillThrow() { AnyArgsExpectation expectation = new AnyArgsExpectation(new FakeInvocation(typeof(object).GetMethod("ToString")), new Range(1, 1)); expectation.ActionToExecute = (ToStringDelegate)delegate { return "fpp"; }; Assert.Throws<InvalidOperationException>( "Trying to run a Do() delegate when no arguments were matched to the expectation.", () => expectation.ReturnOrThrow(null, null)); }
public void ArgsEqualFalseWhenMatchingAnotherExpectation() { IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] {1, "43", 5.2f}, new Range(1, 1)); IExpectation other = new AnyArgsExpectation(new FakeInvocation(method), new Range(1, 1)); Assert.NotEqual(expectation,other); }
public void SetUp() { endsWith = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) }); expectation = new AnyArgsExpectation(new FakeInvocation(endsWith), new Range(1, 1)); proxy = new ProxyInstance(null); }
public void SetUp() { mocks = new MockRepository(); demo = this.mocks.StrictMock(typeof (IDemo)) as IDemo; voidNoArgs = typeof (IDemo).GetMethod("VoidNoArgs"); voidThreeArgs = typeof (IDemo).GetMethod("VoidThreeStringArgs"); expectationOne = new AnyArgsExpectation(new FakeInvocation(this.voidNoArgs), new Range(1, 1)); expectationTwo = new AnyArgsExpectation(new FakeInvocation(voidThreeArgs), new Range(1, 1)); recorder = CreateRecorder(); ChildSetup(); }