public void GetBasketWhenRepositoryHasBasketWillReturnBasketWithCorrectContents() { // Fixture setup var fixture = new RepositoryFixture(); var products = fixture.CreateMany <Extent>().ToList(); fixture.Register(() => { var repositoryStub = new Mock <BasketRepository>(); repositoryStub.Setup(r => r.GetBasketFor(It.IsAny <IPrincipal>())).Returns(products); return(repositoryStub.Object); }); var expectedItems = (from e in products select new Likeness <Extent, Extent>(e) .With(d => d.Product).EqualsWhen((s, d) => new Likeness <Product, Product>(s.Product).Equals(d.Product)) .Without(d => d.Total) .Without(d => d.Updated)) .ToList(); var sut = fixture.CreateAnonymous <BasketService>(); // Exercise system var result = fixture.Get((IPrincipal user) => sut.GetBasketFor(user)); // Verify outcome Assert.True(expectedItems.Cast <object>().SequenceEqual(result.Contents.Cast <object>())); // Teardown }
public void GetBasketWillApplyDiscountPolicyOnBasket() { // Fixture setup var fixture = new RepositoryFixture(); var discountPolicyMock = new Mock <BasketDiscountPolicy>(); discountPolicyMock.Setup(p => p.Apply(It.IsAny <Basket>())).Returns((Basket b) => b); fixture.Register(() => discountPolicyMock.Object); fixture.Register(() => { var basketRepositoryStub = new Mock <BasketRepository>(); basketRepositoryStub.Setup(r => r.GetBasketFor(It.IsAny <IPrincipal>())).Returns(fixture.CreateMany <Extent>()); return(basketRepositoryStub.Object); }); var sut = fixture.CreateAnonymous <BasketService>(); // Exercise system var basket = fixture.Get((IPrincipal user) => sut.GetBasketFor(user)); // Verify outcome discountPolicyMock.Verify(p => p.Apply(basket), "Discount policy not correctly invoked"); // Teardown }
public void GetFeaturedProductsWillReturnInstance() { // Fixture setup var fixture = new RepositoryFixture(); var sut = fixture.CreateAnonymous<ProductService>(); // Exercise system IEnumerable<Product> result = fixture.Get((IPrincipal user) => sut.GetFeaturedProducts(user)); // Verify outcome Assert.NotNull(result); // Teardown }
public void GetFeaturedProductsWillReturnInstance() { // Fixture setup var fixture = new RepositoryFixture(); var sut = fixture.CreateAnonymous <ProductService>(); // Exercise system IEnumerable <Product> result = fixture.Get((IPrincipal user) => sut.GetFeaturedProducts(user)); // Verify outcome Assert.NotNull(result); // Teardown }
public void GetBasketWhenRepositoryHasNoBasketWillReturnEmptyBasket() { // Fixture setup var fixture = new RepositoryFixture(); fixture.Register(() => { var repositoryStub = new Mock<BasketRepository>(); repositoryStub.Setup(r => r.GetBasketFor(It.IsAny<IPrincipal>())).Returns(Enumerable.Empty<Extent>()); return repositoryStub.Object; }); var sut = fixture.CreateAnonymous<BasketService>(); // Exercise system Basket result = fixture.Get((IPrincipal user) => sut.GetBasketFor(user)); // Verify outcome Assert.False(result.Contents.Any(), "GetBasketFor"); // Teardown }
public void GetBasketWhenRepositoryHasNoBasketWillReturnEmptyBasket() { // Fixture setup var fixture = new RepositoryFixture(); fixture.Register(() => { var repositoryStub = new Mock <BasketRepository>(); repositoryStub.Setup(r => r.GetBasketFor(It.IsAny <IPrincipal>())).Returns(Enumerable.Empty <Extent>()); return(repositoryStub.Object); }); var sut = fixture.CreateAnonymous <BasketService>(); // Exercise system Basket result = fixture.Get((IPrincipal user) => sut.GetBasketFor(user)); // Verify outcome Assert.False(result.Contents.Any(), "GetBasketFor"); // Teardown }
public void GetBasketWillReturnBasketWithAppliedDiscountPolicy() { // Fixture setup var fixture = new RepositoryFixture(); var expectedBasket = fixture.CreateAnonymous <Basket>(); var discountPolicyMock = new Mock <BasketDiscountPolicy>(); discountPolicyMock.Setup(dp => dp.Apply(It.IsAny <Basket>())).Returns(expectedBasket); fixture.Register(() => discountPolicyMock.Object); var sut = fixture.CreateAnonymous <BasketService>(); // Exercise system var result = fixture.Get((IPrincipal user) => sut.GetBasketFor(user)); // Verify outcome Assert.Equal <Basket>(expectedBasket, result); // 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, Product>(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, Product>(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 GetBasketWhenRepositoryHasBasketWillReturnBasketWithCorrectContents() { // Fixture setup var fixture = new RepositoryFixture(); var products = fixture.CreateMany<Extent>().ToList(); fixture.Register(() => { var repositoryStub = new Mock<BasketRepository>(); repositoryStub.Setup(r => r.GetBasketFor(It.IsAny<IPrincipal>())).Returns(products); return repositoryStub.Object; }); var expectedItems = (from e in products select new Likeness<Extent, Extent>(e) .With(d => d.Product).EqualsWhen((s, d) => new Likeness<Product, Product>(s.Product).Equals(d.Product)) .Without(d => d.Total) .Without(d => d.Updated)) .ToList(); var sut = fixture.CreateAnonymous<BasketService>(); // Exercise system var result = fixture.Get((IPrincipal user) => sut.GetBasketFor(user)); // Verify outcome Assert.True(expectedItems.Cast<object>().SequenceEqual(result.Contents.Cast<object>())); // Teardown }
public void GetBasketWillReturnBasketWithAppliedDiscountPolicy() { // Fixture setup var fixture = new RepositoryFixture(); var expectedBasket = fixture.CreateAnonymous<Basket>(); var discountPolicyMock = new Mock<BasketDiscountPolicy>(); discountPolicyMock.Setup(dp => dp.Apply(It.IsAny<Basket>())).Returns(expectedBasket); fixture.Register(() => discountPolicyMock.Object); var sut = fixture.CreateAnonymous<BasketService>(); // Exercise system var result = fixture.Get((IPrincipal user) => sut.GetBasketFor(user)); // Verify outcome Assert.Equal<Basket>(expectedBasket, result); // Teardown }
public void GetBasketWillApplyDiscountPolicyOnBasket() { // Fixture setup var fixture = new RepositoryFixture(); var discountPolicyMock = new Mock<BasketDiscountPolicy>(); discountPolicyMock.Setup(p => p.Apply(It.IsAny<Basket>())).Returns((Basket b) => b); fixture.Register(() => discountPolicyMock.Object); fixture.Register(() => { var basketRepositoryStub = new Mock<BasketRepository>(); basketRepositoryStub.Setup(r => r.GetBasketFor(It.IsAny<IPrincipal>())).Returns(fixture.CreateMany<Extent>()); return basketRepositoryStub.Object; }); var sut = fixture.CreateAnonymous<BasketService>(); // Exercise system var basket = fixture.Get((IPrincipal user) => sut.GetBasketFor(user)); // Verify outcome discountPolicyMock.Verify(p => p.Apply(basket), "Discount policy not correctly invoked"); // Teardown }