コード例 #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
ファイル: AShimUsage.cs プロジェクト: chrisortman/Postiche
        public void XunitExtensibilityIsNiceForShimContext()
        {
            ShimProduct.FindByIdInt32 = id => {
                return new Product() {
                    Id = id,
                    Name = "Product " + id,
                    Price = 5M
                };
            };

            var orderService = new OrderService();
            var p1 = orderService.FindProduct(1);
            var p2 = orderService.FindProduct(2);

            Assert.Equal(1, p1.Id);
            Assert.Equal(2, p2.Id);
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: AShimUsage.cs プロジェクト: chrisortman/Postiche
        public void Xunit_YouCanMockAStaticMethod()
        {
            using (ShimsContext.Create()) {
                ShimProduct.FindByIdInt32 = id => {
                    return new Product() {
                        Id = id,
                        Name = "Product " + id,
                        Price = 5M
                    };
                };

                var orderService = new OrderService();
                var p1 = orderService.FindProduct(1);
                var p2 = orderService.FindProduct(2);

                Assert.Equal(1, p1.Id);
                Assert.Equal(2, p2.Id);
            }
        }
コード例 #6
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");
 }
コード例 #7
0
ファイル: AShimUsage.cs プロジェクト: chrisortman/Postiche
 public void ICanHasCodeCoverageForXunit()
 {
     var orderService = new OrderService(new StubIEmailService());
     orderService.ThisMethodIsOnlyCalledFromXunitSoIcanSeeCodeCoverage();
     Assert.True(true);
 }