예제 #1
0
        public void XUNIT_StubAConcreteClassYouDontCreate()
        {
            var fake = new StubIEmailService();
            string to = "", from = "", subject = "", body = "";
            fake.SendEmailStringStringStringString = (s, s1, arg3, arg4) => {
                to = s;
                from = s1;
                subject = arg3;
                body = arg4;
            };

            ShimCrappyEmailService.AllInstances.SendEmailStringStringStringString = (service, s, arg3, arg4, arg5) => {
                to = s;
                from = arg3;
                subject = arg4;
                body = arg5;
            };
            var orderService = new OrderService();
            orderService.Ship("100");

            Assert.Equal("*****@*****.**", to);
            Assert.Equal("*****@*****.**", from);
            Assert.Equal("Your order has shipped", subject);
            Assert.Contains("order 100", body);
        }
예제 #2
0
        public void StubAnInterfaceYouDontGetToCreate()
        {
            using (ShimsContext.Create()) {
                var fake = new StubIEmailService();
                string to = "", from = "", subject = "", body = "";
                fake.SendEmailStringStringStringString = (s, s1, arg3, arg4) => {
                    to = s;
                    from = s1;
                    subject = arg3;
                    body = arg4;
                };
                ShimOrderService.Constructor = @this => {
                    var orderServiceWithFake = new OrderService(fake);
                    var shim = new ShimOrderService(@this);
                    shim.ShipString = s => {
                        orderServiceWithFake.Ship(s);
                    };
                };

                var orderService = new OrderService();
                orderService.Ship("100");

                Assert.AreEqual("*****@*****.**", to);
                Assert.AreEqual("*****@*****.**", from);
                Assert.AreEqual("Your order has shipped", subject);
                StringAssert.Contains(body, "order 100");
            }
        }
예제 #3
0
        public void XUNIT_StubAnInterfaceOnTheConstructor()
        {
            var fake = new StubIEmailService();
            string to = "", from = "", subject = "", body = "";
            fake.SendEmailStringStringStringString = (s, s1, arg3, arg4) => {
                to = s;
                from = s1;
                subject = arg3;
                body = arg4;
            };

            var orderService = new OrderService(fake);
            orderService.Ship("100");

            Assert.Equal("*****@*****.**", to);
            Assert.Equal("*****@*****.**", from);
            Assert.Equal("Your order has shipped", subject);
            Assert.Contains("order 100", body);
        }
예제 #4
0
 public void XUNIT_YouCanPassAShimInstanceAsTheInterfaceImplementation()
 {
     bool wasCalled = false;
     var shim = new ShimCrappyEmailService();
     shim.SendEmailStringStringStringString = (s, s1, arg3, arg4) => { wasCalled = true; };
     var orderService = new OrderService(shim.Instance);
     orderService.Ship("200");
 }