예제 #1
0
        public void TurnLeft_ConstructorInjection()
        {
            var car = UnityConfigManagerFactory.Resolve <ICar>();

            var result = car.TurnLeft();

            Assert.AreEqual("SteeringWheel is rotating to the left...", result);
        }
예제 #2
0
        public void GetId_Singleton()
        {
            var car1 = UnityConfigManagerFactory.Resolve <ICar>();
            var car2 = UnityConfigManagerFactory.Resolve <ICar>();

            var result  = car1.GetId();
            var result2 = car2.GetId();

            Assert.AreEqual(result, result2);
        }
예제 #3
0
        public void UnityConfigMoq()
        {
            var mock = new Mock <IMyBusiness>();

            mock.Setup(x => x.Sum(It.Is <int>(y => y.Equals(_leftNumberExpected)), It.Is <int>(y => y.Equals(_rightNumberExpected)))).Returns(_fakeTotalNumber);
            UnityConfigManagerFactory.Container.RegisterInstance(mock.Object);

            var myBiz = UnityConfigManagerFactory.Resolve <IMyBusiness>();
            var total = myBiz.Sum(_leftNumber, _rightNumber);

            Assert.AreEqual(_totalNumberExpected, total);
        }
예제 #4
0
        public void UnityConfigRhinoMock()
        {
            var mock = Rhino.Mocks.MockRepository.GenerateMock <IMyBusiness>();

            mock.Stub(x => x.Sum(Arg <int> .Is.Equal(_leftNumberExpected), Arg <int> .Is.Equal(_rightNumberExpected))).Return(_fakeTotalNumber);
            UnityConfigManagerFactory.Container.RegisterInstance(mock);

            var myBiz = UnityConfigManagerFactory.Resolve <IMyBusiness>();
            var total = myBiz.Sum(_leftNumber, _rightNumber);

            Assert.AreEqual(_totalNumberExpected, total);
        }
예제 #5
0
        static void Main(string[] args)
        {
            using (var mtw = new MethodTimeWatcher("WITHOUT IoC CONTAINER"))
            {
                for (var i = 0; i < Iterations; i++)
                {
                    var instance = new MyBusiness();
                    var result   = instance.Sum(1, 1);
                }
            }

            using (var mtw = new MethodTimeWatcher("WITH IoC CONTAINER: UNITY"))
            {
                for (var i = 0; i < Iterations; i++)
                {
                    var instance = UnityCodeManagerFactory.Resolve <IMyBusiness>();
                    var result   = instance.Sum(1, 1);
                }
            }

            using (var mtw = new MethodTimeWatcher("WITH IoC CONTAINER: UNITY APP.CONFIG"))
            {
                for (var i = 0; i < Iterations; i++)
                {
                    var instance = UnityConfigManagerFactory.Resolve <IMyBusiness>();
                    var result   = instance.Sum(1, 1);
                }
            }

            using (var mtw = new MethodTimeWatcher("WITH IoC CONTAINER: STRUCTUREMAP"))
            {
                for (var i = 0; i < Iterations; i++)
                {
                    var instance = SMManagerFactory.Resolve <IMyBusiness>();
                    var result   = instance.Sum(1, 1);
                }
            }

            using (var mtw = new MethodTimeWatcher("WITH IoC CONTAINER: NINJECT"))
            {
                Ninject.IKernel kernel = new StandardKernel(new NInjectManagerFactory());
                for (var i = 0; i < Iterations; i++)
                {
                    var instance = kernel.Get <IMyBusiness>();
                    var result   = instance.Sum(1, 1);
                }
            }


            Console.WriteLine(" --- End of the program --- ");
            Console.ReadKey();
        }