Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
            }
        }