コード例 #1
0
 public void GetFeaturedProductsWillReturnInstance()
 {
     // Fixture setup
     var fixture = new RepositoryFixture();
     var sut = fixture.CreateAnonymous<ProductService>();
     // Exercise system
     IEnumerable<DiscountedProduct> result = fixture.Get((IPrincipal user) => sut.GetFeaturedProducts(user));
     // Verify outcome
     Assert.NotNull(result);
     // Teardown
 }
コード例 #2
0
        public void GetFeaturedProductsWillReturnInstance()
        {
            // Fixture setup
            var fixture = new RepositoryFixture();
            var sut     = fixture.CreateAnonymous <ProductService>();
            // Exercise system
            IEnumerable <DiscountedProduct> result = fixture.Get((IPrincipal user) => sut.GetFeaturedProducts(user));

            // Verify outcome
            Assert.NotNull(result);
            // Teardown
        }
コード例 #3
0
        public void GetFeaturedProductsWillReturnCorrectProductsForNonPreferredUser()
        {
            // Fixture setup
            var fixture          = new RepositoryFixture();
            var featuredProducts = fixture.CreateMany <Product>().ToList();

            fixture.Register(() => {
                var repositoryStub = new Mock <ProductRepository>();
                repositoryStub.Setup(r => r.GetFeaturedProducts()).Returns(featuredProducts);
                return(repositoryStub.Object);
            });

            var expectedProducts = (from p in featuredProducts
                                    select new Likeness <Product, DiscountedProduct>(p)).ToList();

            var sut = fixture.CreateAnonymous <ProductService>();
            // Exercise system
            var result = fixture.Get((IPrincipal user) => sut.GetFeaturedProducts(user));

            // Verify outcome
            Assert.True(expectedProducts.Cast <object>().SequenceEqual(result.Cast <object>()));
            // Teardown
        }
コード例 #4
0
        public void GetFeaturedProductsWillReturnCorrectProductsForNonPreferredUser()
        {
            // Fixture setup
            var fixture = new RepositoryFixture();
            var featuredProducts = fixture.CreateMany<Product>().ToList();
            fixture.Register(() =>
                {
                    var repositoryStub = new Mock<ProductRepository>();
                    repositoryStub.Setup(r => r.GetFeaturedProducts()).Returns(featuredProducts);
                    return repositoryStub.Object;
                });

            var expectedProducts = (from p in featuredProducts
                                    select new Likeness<Product, DiscountedProduct>(p)).ToList();

            var sut = fixture.CreateAnonymous<ProductService>();
            // Exercise system
            var result = fixture.Get((IPrincipal user) => sut.GetFeaturedProducts(user));
            // Verify outcome
            Assert.True(expectedProducts.Cast<object>().SequenceEqual(result.Cast<object>()));
            // Teardown
        }