public void ArgsEqualsReturnsTheExpectedArgs() { object[] args = new object[] { 1, "43", 5.2f }; ArgsEqualExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), args, new Range(1, 1)); Assert.True(List.Equal(args).Eval(expectation.ExpectedArgs)); }
protected override IExpectation GetExpectation(MethodInfo m, Range r, int actual) { ArgsEqualExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(m), new object[0], new Range(1, 1)); SetupExpectation(expectation, r, actual); return(expectation); }
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 ArgsEqualWhenArgsMatch() { IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] { 1, "43", 5.2f }, new Range(1, 1)); object[] args = new object[] { 1, "43", 5.2f }; Assert.True(expectation.IsExpected(args)); }
public void ArgsEqualWithDifferentNumberOfParameters() { IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] { 1, "43", 5.2f }, new Range(1, 1)); object[] args = new object[] { 1, "43" }; Assert.False(expectation.IsExpected(args)); Assert.Equal(String.Format("IDemo.VoidThreeArgs(1, \"43\", {0:N1});", 5.2), expectation.ErrorMessage); }
public void ArgsEqualWhenArgsMismatch() { IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] { 1, "43", 5.2f }, new Range(1, 1)); object[] args = new object[] { 1, "43", 6.4f }; Assert.False(expectation.IsExpected(args)); Assert.Equal(String.Format("IDemo.VoidThreeArgs(1, \"43\", {0:N1});", 5.2), expectation.ErrorMessage); }
public void ArgsEqualWhenValueTypeArrayArgsMatch() { MethodInfo method = typeof(IDemo).GetMethod("VoidValueTypeArrayArgs"); IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] { new ushort[] { 123, 456 } }, new Range(1, 1)); object[] args = new object[] { new ushort[] { 123 } }; Assert.False(expectation.IsExpected(args)); Assert.Equal("IDemo.VoidValueTypeArrayArgs([123, 456]);", expectation.ErrorMessage); }
public void ArgsEqualWithArrayReferenceEqual() { object[] arr = new object[3] { "1", 2, 5.2f }; IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] { 1, arr }, new Range(1, 1)); object[] args = new object[] { 1, arr }; Assert.True(expectation.IsExpected(args)); }
public void ArgsEqualWithStringArray() { MethodInfo method = typeof(IDemo).GetMethod("VoidThreeStringArgs"); string[] str1 = new string[] { "", "1", "1234" }, str2 = new string[] { "1", "1234", "54321" }; IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), str1, new Range(1, 1)); Assert.False(expectation.IsExpected(str2)); Assert.Equal("IDemo.VoidThreeStringArgs(\"\", \"1\", \"1234\");", expectation.ErrorMessage); }
public void ArgsEqualWithArrayContentEqual() { object[] arr1 = new object[3] { "1", 2, 4.5f }, arr2 = new object[3] { "1", 2, 4.5f }; IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] { 1, arr2 }, new Range(1, 1)); object[] args = new object[] { 1, arr1 }; Assert.True(expectation.IsExpected(args)); }
public void ArgsEqualWithArrayContentLengthDifferent() { object[] arr1 = new object[3] { "1", 2, 4.5f }, arr2 = new object[2] { "1", 5 }; IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] { 1, arr1 }, new Range(1, 1)); object[] args = new object[] { 1, arr2 }; Assert.False(expectation.IsExpected(args)); Assert.Equal(String.Format("IDemo.VoidThreeArgs(1, [\"1\", 2, {0:N1}], missing parameter);", 4.5), expectation.ErrorMessage); }
public void RemoveExpectationWhenNestedOrdering() { IExpectation newExpectation = new ArgsEqualExpectation(new FakeInvocation(voidThreeArgs), new object[] { 1, null, 1f }, new Range(1, 1)); recorder.Record(this.demo, this.voidNoArgs, expectationOne); recorder.AddRecorder(CreateRecorder()); recorder.Record(this.demo, this.voidThreeArgs, expectationTwo); recorder.Record(this.demo, this.voidNoArgs, newExpectation); recorder.RemoveExpectation(expectationTwo); //move to replayer, but also remove one expectation from consideration recorder.GetRecordedExpectation(new FakeInvocation(voidNoArgs), demo, voidNoArgs, new object[0]); ExpectationsList expectations = recorder.GetAllExpectationsForProxy(demo); Assert.Equal(1, expectations.Count); Assert.Equal(expectations[0], newExpectation); }
public void AnyArgsIsNotEqualsToNonAnyArgsExpectation() { IExpectation other = new ArgsEqualExpectation(new FakeInvocation(method), new object[0], new Range(1, 1)); Assert.NotEqual(any, other); }
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 CreateErrorMessageWhenParametersAreNull() { ArgsEqualExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] { 1, null, 3.3f }, new Range(1, 1)); Assert.Equal(String.Format("IDemo.VoidThreeArgs(1, null, {0:N1});", 3.3), expectation.ErrorMessage); }