Exemplo n.º 1
0
        public void MethodNullThrows()
        {
            ProxyInstance mockProxy = new ProxyInstance(null);

            Assert.Throws<ArgumentNullException>("Value cannot be null.\r\nParameter name: method",
                                                 () => new ProxyMethodPair(mockProxy, null));
        }
Exemplo n.º 2
0
 public void NotEqualIfNotSameMethod()
 {
     ProxyInstance mockProxy = new ProxyInstance(null);
     ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy, endsWith);
     ProxyMethodPair pair2 = new ProxyMethodPair(mockProxy, startsWith);
     Assert.AreNotEqual(pair1, pair2);
     Assert.AreNotEqual(pair2, pair1); //make sure that it works both ways
 }
Exemplo n.º 3
0
 public void EqualsToAnotherProxy()
 {
     ProxyInstance mockProxy = new ProxyInstance(null);
     ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy, endsWith);
     ProxyMethodPair pair2 = new ProxyMethodPair(mockProxy, endsWith);
     Assert.AreEqual(pair1, pair2);
     Assert.AreEqual(pair2, pair1); //make sure that it works both ways
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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());
 }
Exemplo n.º 6
0
        public void MethodNullThrows()
        {
            var culture = Thread.CurrentThread.CurrentUICulture;
            try
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
                ProxyInstance mockProxy = new ProxyInstance(null);

                var ex = Assert.Throws<ArgumentNullException>(() => new ProxyMethodPair(mockProxy, null));
                Assert.Equal("Value cannot be null.\r\nParameter name: method", ex.Message);
            }
            finally
            {
                Thread.CurrentThread.CurrentUICulture = culture;
            }
        }
        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);
        }
Exemplo n.º 8
0
 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();
 }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
        public void MethodNullThrows()
        {
            ProxyInstance mockProxy = new ProxyInstance(null);

            new ProxyMethodPair(mockProxy, null);
        }
Exemplo n.º 12
0
 public void NotEqualToNull()
 {
     ProxyInstance mockProxy = new ProxyInstance(null);
     ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy, endsWith);
     Assert.IsFalse(pair1.Equals(null));
 }
 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);
 }
Exemplo n.º 14
0
 public void NotEqualIfNotSameMethodAndNotSameProxy()
 {
     ProxyInstance mockProxy1 = new ProxyInstance(null);
     ProxyInstance mockProxy2 = new ProxyInstance(null);
     ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy1, this.endsWith);
     ProxyMethodPair pair2 = new ProxyMethodPair(mockProxy2, this.startsWith);
     Assert.NotEqual(pair1, pair2);
     Assert.NotEqual(pair2, pair1); //make sure that it works both ways
 }