예제 #1
0
        public void ShouldBeAbleToMockInAAAMode()
        {
            var adapter = new RhinoMockAdapter(MockMode.AAA);
            locator.Register(Mock<TestClassWithInterfaceDependencies>.Using(adapter));
            var testClass = locator.GetInstance<TestClassWithInterfaceDependencies>();
            testClass.TestInterface.Expect(i => i.GetSomeValue()).Return(1);
            var result = testClass.TestInterface.GetSomeValue();

            Assert.AreEqual(1, result);
        }
예제 #2
0
        public void AAAModeCanBeEnabledViaPropertySetter()
        {
            var adapter = new RhinoMockAdapter {MockingMode = MockMode.AAA};
            locator.Register(Mock<TestClassWithInterfaceDependencies>.Using(adapter));
            var testClass = locator.GetInstance<TestClassWithInterfaceDependencies>();
            testClass.TestInterface.Expect(i => i.GetSomeValue()).Return(1);
            var result = testClass.TestInterface.GetSomeValue();

            Assert.AreEqual(1, result);
        }
예제 #3
0
        public void ShouldBeAbleToSetExpecationOnMockedInstance()
        {
            var adapter = new RhinoMockAdapter();
            locator.Register(Mock<TestClassWithInterfaceDependencies>.Using(adapter));
            var testClass = locator.GetInstance<TestClassWithInterfaceDependencies>();

            using (adapter.Repository.Record())
            {
                testClass.TestInterface.Expect(i => i.GetSomeValue()).Return(1);
            }

            var result = testClass.TestInterface.GetSomeValue();

            Assert.AreEqual(1, result);
        }
예제 #4
0
        public void ShouldBeAbleToStubInAAAMode()
        {
            var adapter = new RhinoMockAdapter(MockMode.AAA);
            locator.Register(Mock<TestClassWithClassDependencies>.Using(adapter));
            var testClass = locator.GetInstance<TestClassWithInterfaceDependencies>();
            testClass.Stub(c => c.GetSomeValue(Arg<int>.Is.Anything)).Return(1);
            var result = testClass.GetSomeValue(0);

            Assert.AreEqual(1, result);
        }
예제 #5
0
        public void SpecialTypesTest()
        {
            var adapter = new RhinoMockAdapter {MockingMode = MockMode.AAA};
            locator.Register(Mock<SpecialTestCase>.Using(adapter));

            var testClass = locator.GetInstance<SpecialTestCase>();
            var stringResult = testClass.StringInput;
            var intResult = testClass.IntInput;
            var boolResult = testClass.BoolInput;
            var enumReulst = testClass.EnumInput;
            var structResult = testClass.StructInput;

            Assert.AreEqual(string.Empty, stringResult);
            Assert.AreEqual(0, intResult);
            Assert.AreEqual(false, boolResult);
            Assert.AreEqual(TestEnum.Case1, enumReulst);
            Assert.IsTrue(structResult.x == 0 && structResult.y == 0);
        }
예제 #6
0
 public void ShouldNotMockTypesAlreadyRegisteredInServiceLocator()
 {
     var adapter = new RhinoMockAdapter();
     locator.Register(Given<ITestInterface>.Then<TestCase1>());
     adapter.MockingMode = MockMode.AAA;
     locator.Register(Mock<ITestInterface>.Using(adapter, locator));
     var testClass = locator.GetInstance<ITestInterface>();
     Assert.IsInstanceOf(typeof(TestCase1), testClass);
 }