Ejemplo n.º 1
0
        public void GetFeaturedProductsWillReturnCorrectProductsForPreferredCustomer()
        {
            // 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)
                                    .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice * .95m == d.UnitPrice)).ToList();

            var sut = fixture.CreateAnonymous <ProductService>();

            var preferredCustomerStub = new Mock <IPrincipal>();

            preferredCustomerStub.Setup(u => u.IsInRole("PreferredCustomer")).Returns(true);
            // Exercise system
            var result = sut.GetFeaturedProducts(preferredCustomerStub.Object);

            // Verify outcome
            Assert.True(expectedProducts.Cast <object>().SequenceEqual(result.Cast <object>()));
            // Teardown
        }
 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
 }
 public void GetFeaturedProductsWithNullPrincipalWillThrow()
 {
     // Fixture setup
     var fixture = new RepositoryFixture();
     var sut = fixture.CreateAnonymous<ProductService>();
     IPrincipal nullPrincipal = null;
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.GetFeaturedProducts(nullPrincipal));
     // Teardown
 }
 public void CreateWithNullRepositoryWillThrow()
 {
     // Fixture setup
     var fixture = new RepositoryFixture();
     ProductRepository nullRepository = null;
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         fixture.Build<ProductService>()
             .FromFactory(() => new ProductService(nullRepository))
             .CreateAnonymous());
     // Teardown
 }
Ejemplo n.º 5
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
        }
Ejemplo n.º 6
0
        public void GetFeaturedProductsWithNullPrincipalWillThrow()
        {
            // Fixture setup
            var        fixture       = new RepositoryFixture();
            var        sut           = fixture.CreateAnonymous <ProductService>();
            IPrincipal nullPrincipal = null;

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.GetFeaturedProducts(nullPrincipal));
            // Teardown
        }
Ejemplo n.º 7
0
        public void CreateWithNullRepositoryWillThrow()
        {
            // Fixture setup
            var fixture = new RepositoryFixture();
            ProductRepository nullRepository = null;

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  fixture.Build <ProductService>()
                                                  .FromFactory(() => new ProductService(nullRepository))
                                                  .CreateAnonymous());
            // Teardown
        }
Ejemplo n.º 8
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
        }
        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
        }
Ejemplo n.º 10
0
        public void GetFeaturedProductsWillReturnCorrectProductsForPreferredCustomer()
        {
            // 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)
                                        .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice * .95m == d.UnitPrice)).ToList();

            var sut = fixture.CreateAnonymous<ProductService>();

            var preferredCustomerStub = new Mock<IPrincipal>();
            preferredCustomerStub.Setup(u => u.IsInRole("PreferredCustomer")).Returns(true);
            // Exercise system
            var result = sut.GetFeaturedProducts(preferredCustomerStub.Object);
            // Verify outcome
            Assert.True(expectedProducts.Cast<object>().SequenceEqual(result.Cast<object>()));
            // Teardown
        }