Esempio n. 1
0
        public void UnityCodeRhinoMock()
        {
            var mock = Rhino.Mocks.MockRepository.GenerateMock <IMyBusiness>();

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

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

            Assert.AreEqual(_totalNumberExpected, total);
        }
Esempio n. 2
0
        public void UnityCodeMoq()
        {
            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);
            UnityCodeManagerFactory.Container.RegisterInstance(mock.Object);

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

            Assert.AreEqual(_totalNumberExpected, total);
        }
Esempio n. 3
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();
        }