public void CreateWithNullCurrencyProviderWillThrow()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     CurrencyProvider nullCurrencyProvider = null;
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         fixture.Build<HomeController>()
             .FromFactory((ProductRepository pr) => new HomeController(pr, nullCurrencyProvider))
             .OmitAutoProperties()
             .CreateAnonymous());
     // Teardown
 }
 public void CreateWithNullBasketWillThrow()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     Basket nullBasket = null;
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         fixture.Build<BasketViewModel>()
             .FromFactory(() => new BasketViewModel(nullBasket))
             .OmitAutoProperties()
             .CreateAnonymous());
     // Teardown
 }
 public void CreateWithNullBasketServiceWillThrow()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     IBasketService nullBasketService = null;
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         fixture.Build<BasketController>()
             .FromFactory((CurrencyProvider cp) => new BasketController(nullBasketService, cp))
             .OmitAutoProperties()
             .CreateAnonymous());
     // Teardown
 }
Example #4
0
        public void CreateWithNullCurrencyProviderWillThrow()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            CurrencyProvider nullCurrencyProvider = null;

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  fixture.Build <BasketController>()
                                                  .FromFactory((IBasketService bs) => new BasketController(bs, nullCurrencyProvider))
                                                  .OmitAutoProperties()
                                                  .CreateAnonymous());
            // Teardown
        }
Example #5
0
        public void CreateWithNullBasketWillThrow()
        {
            // Fixture setup
            var    fixture    = new ControllerFixture();
            Basket nullBasket = null;

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  fixture.Build <BasketViewModel>()
                                                  .FromFactory(() => new BasketViewModel(nullBasket))
                                                  .OmitAutoProperties()
                                                  .CreateAnonymous());
            // Teardown
        }
        public void CreateWithNullProductRepositoryWillThrow()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            ProductRepository nullProductRepository = null;

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  fixture.Build <HomeController>()
                                                  .FromFactory((CurrencyProvider cp) => new HomeController(nullProductRepository, cp))
                                                  .OmitAutoProperties()
                                                  .CreateAnonymous());
            // Teardown
        }
 public void DefaultCurrencyProfileServiceIsCorrect()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     var sut = fixture.Build<BasketController>()
         .OmitAutoProperties()
         .With(s => s.ControllerContext)
         .CreateAnonymous();
     // Exercise system
     CurrencyProfileService result = sut.CurrencyProfileService;
     // Verify outcome
     Assert.IsAssignableFrom<DefaultCurrencyProfileService>(result);
     // Teardown
 }
Example #8
0
        public void DefaultCurrencyProfileServiceIsCorrect()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var sut     = fixture.Build <BasketController>()
                          .OmitAutoProperties()
                          .With(s => s.ControllerContext)
                          .CreateAnonymous();
            // Exercise system
            CurrencyProfileService result = sut.CurrencyProfileService;

            // Verify outcome
            Assert.IsAssignableFrom <DefaultCurrencyProfileService>(result);
            // Teardown
        }
 public void CurrencyProfileSerivceIsWellBehavedWritableProperty()
 {
     // Fixture setup
     var fixture = new ControllerFixture();
     var sut = fixture.Build<HomeController>()
         .OmitAutoProperties()
         .CreateAnonymous();
     var expectedCurrencyProfileService = new Mock<CurrencyProfileService>().Object;
     // Exercise system
     sut.CurrencyProfileService = expectedCurrencyProfileService;
     CurrencyProfileService result = sut.CurrencyProfileService;
     // Verify outcome
     Assert.Equal<CurrencyProfileService>(expectedCurrencyProfileService, result);
     // Teardown
 }
Example #10
0
        public void CurrencyProfileSerivceIsWellBehavedWritableProperty()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var sut     = fixture.Build <BasketController>()
                          .OmitAutoProperties()
                          .CreateAnonymous();
            var expectedCurrencyProfileService = new Mock <CurrencyProfileService>().Object;

            // Exercise system
            sut.CurrencyProfileService = expectedCurrencyProfileService;
            CurrencyProfileService result = sut.CurrencyProfileService;

            // Verify outcome
            Assert.Equal <CurrencyProfileService>(expectedCurrencyProfileService, 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
        }
Example #12
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
        }
Example #13
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 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
 }