Exemplo n.º 1
0
		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);
		}
Exemplo n.º 2
0
		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);
		}
Exemplo n.º 3
0
        /// <summary>
        /// Determines if the object equal to expectation
        /// </summary>
        public override bool Equals(object obj)
        {
            ArgsEqualExpectation other = obj as ArgsEqualExpectation;

            if (other == null)
            {
                return(false);
            }
            return(Method.Equals(other.Method) && Validate.ArgsEqual(expectedArgs, other.expectedArgs));
        }
Exemplo n.º 4
0
 public void AnyArgsIsNotEqualsToNonAnyArgsExpectation()
 {
     IExpectation other = new ArgsEqualExpectation(new FakeInvocation(method), new object[0], new Range(1, 1));
     Assert.NotEqual(any, other );
 }
Exemplo n.º 5
0
 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 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.AreEqual(1, expectations.Count);
            Assert.AreEqual(expectations[0],newExpectation);
        }
Exemplo n.º 7
0
		public void ArgsEqualWhenArgsAreNull()
		{
			IExpectation expectation = new ArgsEqualExpectation(new FakeInvocation(method), new object[] {1, null, 5.2f}, new Range(1, 1));
			object[] args = new object[] {1, null, 5.2f};
			Assert.True(expectation.IsExpected(args));
		}
Exemplo n.º 8
0
		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));
		}
Exemplo n.º 9
0
		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);
		}
Exemplo n.º 10
0
		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);
		}
Exemplo n.º 11
0
		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;
		}
Exemplo n.º 12
0
		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);
		}
Exemplo n.º 13
0
		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);
		}
Exemplo n.º 14
0
		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));
		}
Exemplo n.º 15
0
		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));
		}
Exemplo n.º 16
0
		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);
		}