Esempio n. 1
0
        public void ISmthInterfaceTest()
        {
            var stub = new StubISmthInterface
            {
                MulInt32Int32 = (left, right) => left + right,
                DivInt32Int32 = (left, right) => left - right
            };

            Assert.AreEqual(stub.MulInt32Int32(2, 3), 5);
            Assert.AreEqual(stub.DivInt32Int32(16, 2), 14);
        }
Esempio n. 2
0
        public void Test2()
        {
            var stub = new StubISmthInterface
            {
                MulInt32Int32 = (left, right) => left * right,
                DivInt32Int32 = (left, right) => left / right
            };

            ShimSingleton.AllInstances.SmthExecutorGet = f => stub;

            Assert.AreEqual(Singleton.Instance.SmthExecutor.Mul(2, 3), 6);
            Assert.AreEqual(Singleton.Instance.SmthExecutor.Div(16, 2), 8);
        }
Esempio n. 3
0
        public void SmthClassTest()
        {
            var stubWorker = new StubISmthInterface
            {
                MulInt32Int32 = (left, right) => left + right,
                DivInt32Int32 = (left, right) => left - right
            };

            var realWorker = new SmthClassWithInterface();
            var smthClass  = new SmthClass();

            Assert.AreEqual(smthClass.Mul(stubWorker, 2, 3), 5);
            Assert.AreEqual(smthClass.Mul(realWorker, 2, 3), 6);
            Assert.AreEqual(smthClass.Div(stubWorker, 16, 2), 14);
            Assert.AreEqual(smthClass.Div(realWorker, 16, 2), 8);
        }
Esempio n. 4
0
        public void SingletonTest()
        {
            Singleton.Instance.SmthExecutor = new SmthClassWithInterface();

            var listOfA = Singleton.Instance.SmthExecutor.GetList <ClassA>();

            Assert.AreEqual(listOfA.Count, 1);

            var listOfB = Singleton.Instance.SmthExecutor.GetList <ClassB>();

            Assert.AreEqual(listOfB.Count, 1);

            Assert.AreEqual(Singleton.Instance.SmthExecutor.Mul(2, 3), 6);
            Assert.AreEqual(Singleton.Instance.SmthExecutor.Div(16, 2), 8);

            using (ShimsContext.Create())
            {
                var stub = new StubISmthInterface
                {
                    MulInt32Int32 = (left, right) => left + right,
                    DivInt32Int32 = (left, right) => left - right
                };
                stub.GetListOf1(() => new List <ClassA> {
                    new ClassA("ClassA[0] (from StubISmthInterface)"), new ClassA("ClassA[1] (from StubISmthInterface)")
                });
                stub.GetListOf1(() => new List <ClassB> {
                    new ClassB("ClassB[0] (from StubISmthInterface)"), new ClassB("ClassB[1] (from StubISmthInterface)")
                });

                ShimSingleton.AllInstances.SmthExecutorGet = f => stub;

                listOfA = Singleton.Instance.SmthExecutor.GetList <ClassA>();
                Assert.AreEqual(listOfA.Count, 2);

                listOfB = Singleton.Instance.SmthExecutor.GetList <ClassB>();
                Assert.AreEqual(listOfB.Count, 2);

                Assert.AreEqual(Singleton.Instance.SmthExecutor.Mul(2, 3), 5);
                Assert.AreEqual(Singleton.Instance.SmthExecutor.Div(16, 2), 14);
            }
        }