Ejemplo n.º 1
0
        public void IndexWillUseCurrencyFromCurrencyProfileService()
        {
            // Fixture setup
            var fixture      = new ControllerFixture();
            var currencyCode = fixture.CreateAnonymous("CurrencyCode");

            var currencyProfileServiceStub = new Mock <CurrencyProfileService>();

            currencyProfileServiceStub.Setup(cps => cps.GetCurrencyCode()).Returns(currencyCode);

            var currencyProviderMock = new Mock <CurrencyProvider>();

            currencyProviderMock.Setup(cp => cp.GetCurrency(currencyCode)).Returns(fixture.CreateAnonymous <Currency>()).Verifiable();
            fixture.Register(() => currencyProviderMock.Object);

            fixture.Register(() =>
            {
                var basketServiceStub = new Mock <IBasketService>();
                basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny <IPrincipal>())).Returns(fixture.CreateAnonymous <Basket>());
                return(basketServiceStub.Object);
            });

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

            sut.CurrencyProfileService = currencyProfileServiceStub.Object;
            // Exercise system
            sut.Index();
            // Verify outcome
            currencyProviderMock.Verify();
            // 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
        }
Ejemplo n.º 4
0
        public void IndexWillReturnCorrectContentsWhenProfileRequestsConversion()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var basket  = fixture.CreateAnonymous <Basket>();

            fixture.AddManyTo(basket.Contents);

            var currencyCode          = fixture.CreateAnonymous("CurrencyCode");
            var anonymousExchangeRate = 3.2m;

            var currencyStub = new Mock <Currency>();

            currencyStub.SetupGet(c => c.Code).Returns(currencyCode);
            currencyStub.Setup(c => c.GetExchangeRateFor(It.IsAny <string>())).Returns(anonymousExchangeRate);

            fixture.Register(() =>
            {
                var basketServiceStub = new Mock <IBasketService>();
                basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny <IPrincipal>())).Returns(basket);
                return(basketServiceStub.Object);
            });
            fixture.Customize <UserProfile>(ob => ob.FromFactory(() =>
            {
                var profileStub = new Mock <UserProfile>();
                profileStub.SetupGet(p => p.Currency).Returns(currencyCode);
                return(profileStub.Object);
            }).OmitAutoProperties());
            fixture.Register(() =>
            {
                var currencyProviderStub = new Mock <CurrencyProvider>();
                currencyProviderStub.Setup(cp => cp.GetCurrency(currencyCode)).Returns(currencyStub.Object);
                return(currencyProviderStub.Object);
            });

            var expectedContents = new BasketViewModel(basket.ConvertTo(currencyStub.Object)).Contents.ToList();

            var sut = fixture.CreateAnonymous <BasketController>();
            // Exercise system
            var result = ((BasketViewModel)sut.Index().ViewData.Model).Contents.ToList();

            // Verify outcome
            Assert.True(expectedContents.SequenceEqual(result));
            // Teardown
        }
        public void SetCurrencyWillInteractCorrectlyWithUserProfileProvider()
        {
            // Fixture setup
            var fixture  = new ControllerFixture();
            var currency = fixture.CreateAnonymous("Currency");

            var currencyProfileServiceMock = new Mock <CurrencyProfileService>();

            currencyProfileServiceMock.Setup(cp => cp.UpdateCurrencyCode(currency)).Verifiable();

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

            sut.CurrencyProfileService = currencyProfileServiceMock.Object;
            // Exercise system
            sut.SetCurrency(currency);
            // Verify outcome
            currencyProfileServiceMock.Verify();
            // Teardown
        }
 public void SutIsCurrencyProfileService()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     // Exercise system
     var sut = fixture.CreateAnonymous<DefaultCurrencyProfileService>();
     // Verify outcome
     Assert.IsAssignableFrom<CurrencyProfileService>(sut);
     // Teardown
 }
        public void SutIsCurrencyProfileService()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            // Exercise system
            var sut = fixture.CreateAnonymous <DefaultCurrencyProfileService>();

            // Verify outcome
            Assert.IsAssignableFrom <CurrencyProfileService>(sut);
            // Teardown
        }
 public void SettingCurrencyProfileProviderToNullWillThrow()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     var sut = fixture.CreateAnonymous<HomeController>();
     CurrencyProfileService nullCurrencyProfileService = null;
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.CurrencyProfileService = nullCurrencyProfileService);
     // Teardown
 }
        public void AboutWillReturnInstance()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var sut     = fixture.CreateAnonymous <HomeController>();
            // Exercise system
            ViewResult result = sut.About();

            // Verify outcome
            Assert.NotNull(result);
            // Teardown
        }
        public void SetCurrencyWillReturnCorrectResult()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var sut     = fixture.CreateAnonymous <HomeController>();
            // Exercise system
            RedirectToRouteResult result = fixture.Get((string currency) => sut.SetCurrency(currency));

            // Verify outcome
            Assert.Equal <string>("Index", (string)result.RouteValues["action"]);
            // Teardown
        }
Ejemplo n.º 11
0
        public void SettingCurrencyProfileServiceCanNotBeDoneAfterPropertyHasBeenRead()
        {
            // Fixture setup
            var fixture        = new ControllerFixture();
            var sut            = fixture.CreateAnonymous <BasketController>();
            var currentService = sut.CurrencyProfileService;

            // Exercise system and verify outcome
            Assert.Throws <InvalidOperationException>(() =>
                                                      sut.CurrencyProfileService = new Mock <CurrencyProfileService>().Object);
            // Teardown
        }
Ejemplo n.º 12
0
        public void AddWillAddCorrectItemToBasketService()
        {
            // Fixture setup
            var fixture = new ControllerFixture();

            var productId = fixture.CreateAnonymous <int>();

            var repositoryStub = new Mock <IBasketService>();

            repositoryStub.Setup(r => r.AddToBasket(productId, 1, It.IsAny <IPrincipal>())).Verifiable();

            fixture.Register(() => repositoryStub.Object);

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

            // Exercise system
            sut.Add(productId);
            // Verify outcome
            repositoryStub.Verify();
            // Teardown
        }
Ejemplo n.º 13
0
        public void EmptyWillReturnCorrectRedirectAction()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var sut     = fixture.CreateAnonymous <BasketController>();
            // Exercise system
            RedirectToRouteResult result = sut.Empty();

            // Verify outcome
            Assert.Equal <string>("Index", (string)result.RouteValues["action"]);
            // Teardown
        }
Ejemplo n.º 14
0
        public void SettingCurrencyProfileProviderToNullWillThrow()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var sut     = fixture.CreateAnonymous <BasketController>();
            CurrencyProfileService nullCurrencyProfileService = null;

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.CurrencyProfileService = nullCurrencyProfileService);
            // Teardown
        }
        public void IndexWillReturnViewWithCorrectModel()
        {
            // Fixture setup
            var  fixture = new ControllerFixture();
            var  sut     = fixture.CreateAnonymous <HomeController>();
            Type expectedViewModelType = typeof(FeaturedProductsViewModel);
            // Exercise system
            ViewResult result = sut.Index();

            // Verify outcome
            Assert.IsAssignableFrom <FeaturedProductsViewModel>(result.ViewData.Model);
            // Teardown
        }
Ejemplo n.º 16
0
        public void SettingCurrencyProfileServiceCanOnlyBeDoneOnce()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var sut     = fixture.CreateAnonymous <BasketController>();
            var currencyProfileService1 = new Mock <CurrencyProfileService>().Object;
            var currencyProfileService2 = new Mock <CurrencyProfileService>().Object;

            sut.CurrencyProfileService = currencyProfileService1;
            // Exercise system and verify outcome
            Assert.Throws <InvalidOperationException>(() =>
                                                      sut.CurrencyProfileService = currencyProfileService2);
            // Teardown
        }
        public void IndexWillUseCurrencyFromProfile()
        {
            // Fixture setup
            var fixture      = new ControllerFixture();
            var currencyCode = fixture.CreateAnonymous("CurrencyCode");

            var currencyProfileServiceStub = new Mock <CurrencyProfileService>();

            currencyProfileServiceStub.Setup(cps => cps.GetCurrencyCode()).Returns(currencyCode);

            var currencyProviderMock = new Mock <CurrencyProvider>();

            currencyProviderMock.Setup(cp => cp.GetCurrency(currencyCode)).Returns(fixture.CreateAnonymous <Currency>()).Verifiable();
            fixture.Register(() => currencyProviderMock.Object);

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

            sut.CurrencyProfileService = currencyProfileServiceStub.Object;
            // Exercise system
            sut.Index();
            // Verify outcome
            currencyProviderMock.Verify();
            // Teardown
        }
        public void GetCurrencyCodeWillReturnProfileFromContextWhenThatProfileIsUserProfile()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var expectedCurrencyCode = fixture.CreateAnonymous("CurrencyCode");

            var userProfileStub = new Mock<UserProfile>();
            userProfileStub.SetupGet(up => up.Currency).Returns(expectedCurrencyCode);

            var httpContextStub = new Mock<HttpContextBase>();
            httpContextStub.SetupGet(ctx => ctx.Profile).Returns(userProfileStub.Object);

            var sut = new DefaultCurrencyProfileService(httpContextStub.Object);
            // Exercise system
            var result = sut.GetCurrencyCode();
            // Verify outcome
            Assert.Equal<string>(expectedCurrencyCode, result);
            // Teardown
        }
Ejemplo n.º 19
0
        public void IndexWillReturnCorrectViewWhenBasketIsEmpty()
        {
            // Fixture setup
            var fixture = new ControllerFixture();

            fixture.Register(() =>
            {
                var basketServiceStub = new Mock <IBasketService>();
                basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny <IPrincipal>())).Returns(fixture.CreateAnonymous <Basket>());
                return(basketServiceStub.Object);
            });
            var sut = fixture.CreateAnonymous <BasketController>();
            // Exercise system
            var result = sut.Index().ViewName;

            // Verify outcome
            Assert.Equal <string>("Empty", result);
            // Teardown
        }
Ejemplo n.º 20
0
        public void IndexWillReturnInstance()
        {
            // Fixture setup
            var fixture = new ControllerFixture();

            fixture.Register(() =>
            {
                var basketServiceStub = new Mock <IBasketService>();
                basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny <IPrincipal>())).Returns(fixture.CreateAnonymous <Basket>());
                return(basketServiceStub.Object);
            });

            var sut = fixture.CreateAnonymous <BasketController>();
            // Exercise system
            ViewResult result = sut.Index();

            // Verify outcome
            Assert.NotNull(result);
            // Teardown
        }
Ejemplo n.º 21
0
        public void IndexWillReturnViewWithCorrectModelWhenBasketHasContents()
        {
            // Fixture setup
            var fixture = new ControllerFixture();

            fixture.Register(() =>
            {
                var basketServiceStub = new Mock <IBasketService>();
                basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny <IPrincipal>())).Returns(fixture.Build <Basket>().Do(b => fixture.AddManyTo(b.Contents)).CreateAnonymous());
                return(basketServiceStub.Object);
            });
            var  sut = fixture.CreateAnonymous <BasketController>();
            Type expectedModelType = typeof(BasketViewModel);
            // Exercise system
            var result = sut.Index().ViewData.Model;

            // Verify outcome
            Assert.IsAssignableFrom <BasketViewModel>(result);
            // Teardown
        }
        public void ContentsWillBeCorrect()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            
            var basket = fixture.CreateAnonymous<Basket>();
            fixture.AddManyTo(basket.Contents);

            var expectedResult = (from e in basket.Contents
                                  select string.Format("{0} {1}: {2:C}", e.Quantity, e.Product.Name, e.Total)).ToList();

            var sut = fixture.Build<BasketViewModel>()
                .FromFactory(() => new BasketViewModel(basket))
                .OmitAutoProperties()
                .CreateAnonymous();
            // Exercise system
            IEnumerable<string> result = sut.Contents;
            // Verify outcome
            Assert.True(expectedResult.SequenceEqual(result));
            // Teardown
        }
        public void GetCurrencyCodeWillReturnProfileFromContextWhenThatProfileIsUserProfile()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var expectedCurrencyCode = fixture.CreateAnonymous("CurrencyCode");

            var userProfileStub = new Mock <UserProfile>();

            userProfileStub.SetupGet(up => up.Currency).Returns(expectedCurrencyCode);

            var httpContextStub = new Mock <HttpContextBase>();

            httpContextStub.SetupGet(ctx => ctx.Profile).Returns(userProfileStub.Object);

            var sut = new DefaultCurrencyProfileService(httpContextStub.Object);
            // Exercise system
            var result = sut.GetCurrencyCode();

            // Verify outcome
            Assert.Equal <string>(expectedCurrencyCode, result);
            // Teardown
        }
Ejemplo n.º 24
0
        public void EmptyWillEmptyBasketFromService()
        {
            // Fixture setup
            var fixture = new ControllerFixture();

            var user = new Mock <IPrincipal>().Object;

            fixture.Register(() => user);

            var repositoryStub = new Mock <IBasketService>();

            repositoryStub.Setup(r => r.Empty(user)).Verifiable();

            fixture.Register(() => repositoryStub.Object);

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

            // Exercise system
            sut.Empty();
            // Verify outcome
            repositoryStub.Verify();
            // Teardown
        }
Ejemplo n.º 25
0
        public void ContentsWillBeCorrect()
        {
            // Fixture setup
            var fixture = new ControllerFixture();

            var basket = fixture.CreateAnonymous <Basket>();

            fixture.AddManyTo(basket.Contents);

            var expectedResult = (from e in basket.Contents
                                  select string.Format("{0} {1}: {2:C}", e.Quantity, e.Product.Name, e.Total)).ToList();

            var sut = fixture.Build <BasketViewModel>()
                      .FromFactory(() => new BasketViewModel(basket))
                      .OmitAutoProperties()
                      .CreateAnonymous();
            // Exercise system
            IEnumerable <string> result = sut.Contents;

            // Verify outcome
            Assert.True(expectedResult.SequenceEqual(result));
            // Teardown
        }
Ejemplo n.º 26
0
 public void SettingCurrencyProfileServiceCanNotBeDoneAfterPropertyHasBeenRead()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     var sut = fixture.CreateAnonymous<HomeController>();
     var currentService = sut.CurrencyProfileService;
     // Exercise system and verify outcome
     Assert.Throws<InvalidOperationException>(() =>
         sut.CurrencyProfileService = new Mock<CurrencyProfileService>().Object);
     // Teardown
 }
        public void IndexWillUseCurrencyFromCurrencyProfileService()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var currencyCode = fixture.CreateAnonymous("CurrencyCode");

            var currencyProfileServiceStub = new Mock<CurrencyProfileService>();
            currencyProfileServiceStub.Setup(cps => cps.GetCurrencyCode()).Returns(currencyCode);

            var currencyProviderMock = new Mock<CurrencyProvider>();
            currencyProviderMock.Setup(cp => cp.GetCurrency(currencyCode)).Returns(fixture.CreateAnonymous<Currency>()).Verifiable();
            fixture.Register(() => currencyProviderMock.Object);

            fixture.Register(() =>
                {
                    var basketServiceStub = new Mock<IBasketService>();
                    basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny<IPrincipal>())).Returns(fixture.CreateAnonymous<Basket>());
                    return basketServiceStub.Object;
                });

            var sut = fixture.CreateAnonymous<BasketController>();
            sut.CurrencyProfileService = currencyProfileServiceStub.Object;
            // Exercise system
            sut.Index();
            // Verify outcome
            currencyProviderMock.Verify();
            // Teardown
        }
        public void IndexWillReturnCorrectContentsWhenProfileRequestsConversion()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var basket = fixture.CreateAnonymous<Basket>();
            fixture.AddManyTo(basket.Contents);

            var currencyCode = fixture.CreateAnonymous("CurrencyCode");
            var anonymousExchangeRate = 3.2m;

            var currencyStub = new Mock<Currency>();
            currencyStub.SetupGet(c => c.Code).Returns(currencyCode);
            currencyStub.Setup(c => c.GetExchangeRateFor(It.IsAny<string>())).Returns(anonymousExchangeRate);

            fixture.Register(() =>
                {
                    var basketServiceStub = new Mock<IBasketService>();
                    basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny<IPrincipal>())).Returns(basket);
                    return basketServiceStub.Object;
                });
            fixture.Customize<UserProfile>(ob => ob.FromFactory(() =>
                {
                    var profileStub = new Mock<UserProfile>();
                    profileStub.SetupGet(p => p.Currency).Returns(currencyCode);
                    return profileStub.Object;
                }).OmitAutoProperties());
            fixture.Register(() =>
                {
                    var currencyProviderStub = new Mock<CurrencyProvider>();
                    currencyProviderStub.Setup(cp => cp.GetCurrency(currencyCode)).Returns(currencyStub.Object);
                    return currencyProviderStub.Object;
                });

            var expectedContents = new BasketViewModel(basket.ConvertTo(currencyStub.Object)).Contents.ToList();

            var sut = fixture.CreateAnonymous<BasketController>();
            // Exercise system
            var result = ((BasketViewModel)sut.Index().ViewData.Model).Contents.ToList();
            // Verify outcome
            Assert.True(expectedContents.SequenceEqual(result));
            // Teardown
        }
        public void AddWillAddCorrectItemToBasketService()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            
            var productId = fixture.CreateAnonymous<int>();

            var repositoryStub = new Mock<IBasketService>();
            repositoryStub.Setup(r => r.AddToBasket(productId, 1, It.IsAny<IPrincipal>())).Verifiable();

            fixture.Register(() => repositoryStub.Object);

            var sut = fixture.CreateAnonymous<BasketController>();
            // Exercise system
            sut.Add(productId);
            // Verify outcome
            repositoryStub.Verify();
            // Teardown
        }
 public void EmptyWillReturnCorrectRedirectAction()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     var sut = fixture.CreateAnonymous<BasketController>();
     // Exercise system
     RedirectToRouteResult result = sut.Empty();
     // Verify outcome
     Assert.Equal<string>("Index", (string)result.RouteValues["action"]);
     // Teardown
 }
Ejemplo n.º 31
0
 public void SetCurrencyWillReturnCorrectResult()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     var sut = fixture.CreateAnonymous<HomeController>();
     // Exercise system
     RedirectToRouteResult result = fixture.Get((string currency) => sut.SetCurrency(currency));
     // Verify outcome
     Assert.Equal<string>("Index", (string)result.RouteValues["action"]);
     // Teardown
 }
Ejemplo n.º 32
0
        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 IndexWillReturnCorrectViewWhenBasketIsEmpty()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     fixture.Register(() =>
         {
             var basketServiceStub = new Mock<IBasketService>();
             basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny<IPrincipal>())).Returns(fixture.CreateAnonymous<Basket>());
             return basketServiceStub.Object;
         });
     var sut = fixture.CreateAnonymous<BasketController>();
     // Exercise system
     var result = sut.Index().ViewName;
     // Verify outcome
     Assert.Equal<string>("Empty", result);
     // Teardown
 }
        public void EmptyWillEmptyBasketFromService()
        {
            // Fixture setup
            var fixture = new ControllerFixture();

            var user = new Mock<IPrincipal>().Object;
            fixture.Register(() => user);

            var repositoryStub = new Mock<IBasketService>();
            repositoryStub.Setup(r => r.Empty(user)).Verifiable();

            fixture.Register(() => repositoryStub.Object);

            var sut = fixture.CreateAnonymous<BasketController>();
            // Exercise system
            sut.Empty();
            // Verify outcome
            repositoryStub.Verify();
            // Teardown
        }
Ejemplo n.º 35
0
        public void IndexWillUseCurrencyFromProfile()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var currencyCode = fixture.CreateAnonymous("CurrencyCode");

            var currencyProfileServiceStub = new Mock<CurrencyProfileService>();
            currencyProfileServiceStub.Setup(cps => cps.GetCurrencyCode()).Returns(currencyCode);

            var currencyProviderMock = new Mock<CurrencyProvider>();
            currencyProviderMock.Setup(cp => cp.GetCurrency(currencyCode)).Returns(fixture.CreateAnonymous<Currency>()).Verifiable();
            fixture.Register(() => currencyProviderMock.Object);

            var sut = fixture.CreateAnonymous<HomeController>();
            sut.CurrencyProfileService = currencyProfileServiceStub.Object;
            // Exercise system
            sut.Index();
            // Verify outcome
            currencyProviderMock.Verify();
            // Teardown
        }
Ejemplo n.º 36
0
        public void SetCurrencyWillInteractCorrectlyWithUserProfileProvider()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var currency = fixture.CreateAnonymous("Currency");

            var currencyProfileServiceMock = new Mock<CurrencyProfileService>();
            currencyProfileServiceMock.Setup(cp => cp.UpdateCurrencyCode(currency)).Verifiable();

            var sut = fixture.CreateAnonymous<HomeController>();
            sut.CurrencyProfileService = currencyProfileServiceMock.Object;
            // Exercise system
            sut.SetCurrency(currency);
            // Verify outcome
            currencyProfileServiceMock.Verify();
            // Teardown
        }
 public void IndexWillReturnViewWithCorrectModelWhenBasketHasContents()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     fixture.Register(() =>
     {
         var basketServiceStub = new Mock<IBasketService>();
         basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny<IPrincipal>())).Returns(fixture.Build<Basket>().Do(b => fixture.AddManyTo(b.Contents)).CreateAnonymous());
         return basketServiceStub.Object;
     });
     var sut = fixture.CreateAnonymous<BasketController>();
     Type expectedModelType = typeof(BasketViewModel);
     // Exercise system
     var result = sut.Index().ViewData.Model;
     // Verify outcome
     Assert.IsAssignableFrom<BasketViewModel>(result);
     // Teardown
 }
Ejemplo n.º 38
0
 public void AboutWillReturnInstance()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     var sut = fixture.CreateAnonymous<HomeController>();
     // Exercise system
     ViewResult result = sut.About();
     // Verify outcome
     Assert.NotNull(result);
     // Teardown
 }
Ejemplo n.º 39
0
        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
        }
Ejemplo n.º 40
0
 public void IndexWillReturnViewWithCorrectModel()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     var sut = fixture.CreateAnonymous<HomeController>();
     Type expectedViewModelType = typeof(FeaturedProductsViewModel);
     // Exercise system
     ViewResult result = sut.Index();
     // Verify outcome
     Assert.IsAssignableFrom<FeaturedProductsViewModel>(result.ViewData.Model);
     // Teardown
 }
        public void IndexWillReturnInstance()
        {
            // Fixture setup
            var fixture = new ControllerFixture();

            fixture.Register(() =>
                {
                    var basketServiceStub = new Mock<IBasketService>();
                    basketServiceStub.Setup(bs => bs.GetBasketFor(It.IsAny<IPrincipal>())).Returns(fixture.CreateAnonymous<Basket>());
                    return basketServiceStub.Object;
                });

            var sut = fixture.CreateAnonymous<BasketController>();
            // Exercise system
            ViewResult result = sut.Index();
            // Verify outcome
            Assert.NotNull(result);
            // Teardown
        }
Ejemplo n.º 42
0
        public void SettingCurrencyProviderServiceCanOnlyBeDoneOnce()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var sut = fixture.CreateAnonymous<HomeController>();
            var currencyProfileService1 = new Mock<CurrencyProfileService>().Object;
            var currencyProfileService2 = new Mock<CurrencyProfileService>().Object;

            sut.CurrencyProfileService = currencyProfileService1;
            // Exercise system and verify outcome
            Assert.Throws<InvalidOperationException>(() =>
                sut.CurrencyProfileService = currencyProfileService2);
            // Teardown
        }