public OrdersListViewModelTests()
        {
            var fixture = new OmitRecursionFixture();

            _orders = fixture.CreateMany <Order>();
            _ordersListViewModel = new OrdersListViewModel();
        }
Exemplo n.º 2
0
        public void TestToHtmlShouldReturnHtmlStringWithOrderValues()
        {
            //Arrange
            var fixture = new OmitRecursionFixture();
            var sut     = fixture.Create <Order>();

            //Act
            var result = sut.ToHtmlMessage();

            //Assert
            Assert.NotNull(result);
            Assert.StartsWith("<html>", result);
            Assert.Contains(sut.Id.ToString(), result);
            Assert.Contains(sut.OrderPlaced.ToString(CultureInfo.CurrentCulture), result);
            foreach (var orderDetail in sut.OrderDetails)
            {
                Assert.Contains(orderDetail.ShopItem.Name, result);
                Assert.Contains(orderDetail.Amount.ToString(), result);
                Assert.Contains((orderDetail.Price * orderDetail.Amount).ToString("C"), result);
            }

            Assert.Contains(sut.OrderTotal.ToString("C"), result);

            Assert.EndsWith("</html>", result);
        }
Exemplo n.º 3
0
        public OrderDetailTests()
        {
            _orderDetail = new OrderDetail();

            var fixture = new OmitRecursionFixture();

            _shopItem = fixture.Create <ShopItem>();
            _order    = fixture.Create <Order>();
        }
Exemplo n.º 4
0
        public ShopItemTests()
        {
            _shopItem = new ShopItem();

            var fixture = new OmitRecursionFixture();

            _category = fixture.Create <Category>();

            fixture.Freeze <ShopItem>();
            _shopItemLeft  = fixture.Create <ShopItem>();
            _shopItemRight = fixture.Create <ShopItem>();
        }
Exemplo n.º 5
0
        public OrderTests()
        {
            var fixture = new OmitRecursionFixture();

            _orderDetails = fixture.CreateMany <OrderDetail>().ToList();

            _customer = fixture.Create <Customer>();

            _orderPlaced = fixture.Create <DateTime>();

            _order = new Order();
        }
Exemplo n.º 6
0
        public CategoryTests()
        {
            _category = new Category();

            var fixture = new OmitRecursionFixture();

            _shopItems = fixture.CreateMany <ShopItem>().ToList();

            fixture.Freeze <Category>();
            _categoryLeft  = fixture.Create <Category>();
            _categoryRight = fixture.Create <Category>();
        }
Exemplo n.º 7
0
        public void TestCreateShouldReturnOrdersListViewModel()
        {
            //Arrange
            const int testPageSize  = 2;
            const int testPageIndex = 1;
            var       fixture       = new OmitRecursionFixture();
            var       orders        = fixture.CreateMany <Order>().ToList();
            var       sut           = new OrdersListViewModelFactory();

            //Act
            var result = sut.Create(orders, testPageSize, testPageIndex);

            //Assert
            Assert.Equal(testPageSize, result.PageSize);
            Assert.Equal(testPageIndex, result.PageIndex);
            Assert.Equal(orders.Take(2), result.Orders);
        }
        public void TestClearShouldEmptyCart()
        {
            //Arrange
            var       uniqueId    = Guid.NewGuid().ToString();
            var       testClearId = Guid.NewGuid().ToString();
            const int expectedShoppingCartItems = 1;

            var fixture = new OmitRecursionFixture();

            using (var context = new DatabaseContext(_options))
            {
                var shopItems = fixture
                                .Build <ShopItem>()
                                .Without(p => p.Id)
                                .With(p => p.CategoryId, 999)
                                .CreateMany().ToList();
                context.ShopItems.AddRange(shopItems);

                foreach (var item in shopItems)
                {
                    context.Add(new ShoppingCartItem
                    {
                        Id             = item.Id,
                        ShopItem       = item,
                        ShoppingCartId = testClearId,
                        Amount         = 1
                    });
                }

                var shopItem = context.ShopItems.Find(999);
                context.ShoppingCartItems.Add(new ShoppingCartItem
                {
                    Id             = 999,
                    ShopItem       = shopItem,
                    ShoppingCartId = uniqueId,
                    Amount         = 1
                });

                context.SaveChanges();
            }


            using (var context = new DatabaseContext(_options))
            {
                var sut = new ShoppingCartItemRepository(context);

                //Act

                sut.Clear(testClearId);
                context.SaveChanges();
            }

            using (var context = new DatabaseContext(_options))
            {
                var sut    = new ShoppingCartItemRepository(context);
                var result = sut.GetAll();
                //Assert


                Assert.Equal(expectedShoppingCartItems, result.Count());

                Assert.NotNull(result.FirstOrDefault(i => i.ShoppingCartId == uniqueId));

                Assert.Null(result.FirstOrDefault(i => i.ShoppingCartId == testClearId));
            }
        }