public void IndexWillReturnItemsWithCorrectCurrency()
        {
            // Fixture setup
            var fixture          = new ControllerFixture();
            var featuredProducts = fixture.CreateMany <Product>().ToList();

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

            var expectedCurrencyCode = fixture.CreateAnonymous("CurrencyCode");
            var currencyStub         = new Mock <Currency>();

            currencyStub.SetupGet(c => c.Code).Returns(expectedCurrencyCode);
            currencyStub.Setup(c => c.GetExchangeRateFor(It.IsAny <string>())).Returns(fixture.CreateAnonymous <decimal>());
            fixture.Register(() => currencyStub.Object);

            var sut = fixture.CreateAnonymous <HomeController>();
            // Exercise system
            var result = ((FeaturedProductsViewModel)sut.Index().ViewData.Model).Products.Select(pvm => pvm.UnitPrice.CurrencyCode);

            // Verify outcome
            Assert.True(result.All(code => code == expectedCurrencyCode), "Index should convert to correct currency.");
            // Teardown
        }
        public void IndexWillReturnViewModelWithCorrectProducts()
        {
            // Fixture setup
            var fixture          = new ControllerFixture();
            var featuredProducts =
                fixture.CreateMany <Product>().ToList();

            fixture.Freeze <Mock <ProductRepository> >()
            .Setup(r => r.GetFeaturedProducts())
            .Returns(featuredProducts);

            var expectedProducts = (from p in featuredProducts
                                    select new Likeness <Product, ProductViewModel>(p)
                                    .Without(d => d.SummaryText)
                                    .Without(d => d.UnitPrice)
                                    ).ToList();

            var sut =
                fixture.CreateAnonymous <HomeController>();
            // Exercise system
            var result = ((FeaturedProductsViewModel)sut
                          .Index().ViewData.Model).Products.ToList();

            // Verify outcome
            Assert.True(expectedProducts.Cast <object>().SequenceEqual(result.Cast <object>()));
            // Teardown
        }
        public void IndexWillReturnItemsWithCorrectCurrency()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var featuredProducts = fixture.CreateMany<Product>().ToList();
            fixture.Register(() =>
            {
                var repositoryStub = new Mock<ProductRepository>();
                repositoryStub.Setup(r => r.GetFeaturedProducts()).Returns(featuredProducts);
                return repositoryStub.Object;
            });

            var expectedCurrencyCode = fixture.CreateAnonymous("CurrencyCode");
            var currencyStub = new Mock<Currency>();
            currencyStub.SetupGet(c => c.Code).Returns(expectedCurrencyCode);
            currencyStub.Setup(c => c.GetExchangeRateFor(It.IsAny<string>())).Returns(fixture.CreateAnonymous<decimal>());
            fixture.Register(() => currencyStub.Object);

            var sut = fixture.CreateAnonymous<HomeController>();
            // Exercise system
            var result = ((FeaturedProductsViewModel)sut.Index().ViewData.Model).Products.Select(pvm => pvm.UnitPrice.CurrencyCode);
            // Verify outcome
            Assert.True(result.All(code => code == expectedCurrencyCode), "Index should convert to correct currency.");
            // Teardown
        }
        public void IndexWillReturnViewModelWithCorrectProducts()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var featuredProducts =
                fixture.CreateMany<Product>().ToList();
            fixture.Freeze<Mock<ProductRepository>>()
                .Setup(r => r.GetFeaturedProducts())
                .Returns(featuredProducts);

            var expectedProducts = (from p in featuredProducts
                                    select new Likeness<Product, ProductViewModel>(p)
                                        .Without(d => d.SummaryText)
                                        .Without(d => d.UnitPrice)
                                    ).ToList();

            var sut =
                fixture.CreateAnonymous<HomeController>();
            // Exercise system
            var result = ((FeaturedProductsViewModel)sut
                .Index().ViewData.Model).Products.ToList();
            // Verify outcome
            Assert.True(expectedProducts.Cast<object>().SequenceEqual(result.Cast<object>()));
            // Teardown
        }