public void ApplyWillNotApplyDiscountsIfNoneInBasketArePresentInRepository() { // Fixture setup var fixture = new RepositoryFixture(); fixture.Register(() => { var repositoryStub = new Mock <DiscountRepository>(); repositoryStub.Setup(r => r.GetDiscountedProducts()).Returns(fixture.CreateMany <Product>()); return(repositoryStub.Object); }); var basket = fixture.CreateAnonymous <Basket>(); fixture.AddManyTo(basket.Contents); var expectedContents = (from e in basket.Contents select new Likeness <Extent, Extent>(e) .With(d => d.Product).EqualsWhen((s, d) => new Likeness <Product, Product>(s.Product).Equals(d.Product))) .ToList(); var sut = fixture.CreateAnonymous <RepositoryBasketDiscountPolicy>(); // Exercise system var result = sut.Apply(basket); // Verify outcome Assert.True(expectedContents.Cast <object>().SequenceEqual(result.Contents.Cast <object>())); // Teardown }
public void ApplyWillApplyDefaultProductDiscountForPreferredCustomer() { // Fixture setup var fixture = new RepositoryFixture(); fixture.Register(() => { var customerStub = new Mock <IPrincipal>(); customerStub.Setup(p => p.IsInRole("PreferredCustomer")).Returns(true); return(customerStub.Object); }); var basket = fixture.CreateAnonymous <Basket>(); fixture.AddManyTo(basket.Contents); var expectedExtents = (from e in basket.Contents let ep = new DefaultCustomerDiscountPolicy().Apply(e.Product, basket.Owner) select new Likeness <Extent, Extent>(e) .With(d => d.Product).EqualsWhen((s, d) => new Likeness <Product, Product>(ep) .Equals(d.Product)) .Without(d => d.Total) .Without(d => d.Updated)) .ToList(); var sut = fixture.CreateAnonymous <DefaultProductDiscountPolicy>(); // Exercise system var result = sut.Apply(basket); // Verify outcome Assert.True(expectedExtents.Cast <object>().SequenceEqual(result.Contents.Cast <object>())); // Teardown }
public void ApplyWillApplyDefaultProductDiscountForPreferredCustomer() { // Fixture setup var fixture = new RepositoryFixture(); fixture.Register(() => { var customerStub = new Mock<IPrincipal>(); customerStub.Setup(p => p.IsInRole("PreferredCustomer")).Returns(true); return customerStub.Object; }); var basket = fixture.CreateAnonymous<Basket>(); fixture.AddManyTo(basket.Contents); var expectedExtents = (from e in basket.Contents let ep = new DefaultCustomerDiscountPolicy().Apply(e.Product, basket.Owner) select new Likeness<Extent, Extent>(e) .With(d => d.Product).EqualsWhen((s, d) => new Likeness<Product, Product>(ep) .Equals(d.Product)) .Without(d => d.Total) .Without(d => d.Updated)) .ToList(); var sut = fixture.CreateAnonymous<DefaultProductDiscountPolicy>(); // Exercise system var result = sut.Apply(basket); // Verify outcome Assert.True(expectedExtents.Cast<object>().SequenceEqual(result.Contents.Cast<object>())); // Teardown }