Exemplo n.º 1
0
        public void RemoveFromBasket_WithValidItemId_ShouldRemoveItemFromList()
        {
            // Arrange
            var sectionMocks = shoppingListSectionMockFixture.CreateMany(3).ToList();

            var listDefinition = new ShoppingListDefinition()
            {
                Sections = sectionMocks.Select(s => s.Object)
            };
            var shoppingList = shoppingListFixture.Create(listDefinition);

            ShoppingListSectionMock chosenSectionMock = commonFixture.ChooseRandom(sectionMocks);
            IShoppingListItem       chosenItem        = commonFixture.ChooseRandom(chosenSectionMock.Object.Items);

            sectionMocks.ForEach(m => m.SetupContainsItem(m == chosenSectionMock));

            // Act
            shoppingList.RemoveFromBasket(chosenItem.Id);

            // Assert
            using (new AssertionScope())
            {
                foreach (var section in sectionMocks)
                {
                    if (section == chosenSectionMock)
                    {
                        section.VerifyRemoveItemFromBasketOnce(chosenItem.Id);
                    }
                    else
                    {
                        section.VerifyRemoveItemFromBasketNever();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void AddItem_WithValidItemWithActualId_ShouldAddItemToList()
        {
            // Arrange
            var sections = shoppingListSectionMockFixture.CreateMany(3).ToList();

            var listDefinition = new ShoppingListDefinition()
            {
                Sections = sections.Select(s => s.Object)
            };
            var shoppingList = shoppingListFixture.Create(listDefinition);

            ShoppingListSectionMock chosenSection = commonFixture.ChooseRandom(sections);
            IShoppingListItem       item          = shoppingListItemFixture.CreateUnique(shoppingList);

            // Act
            shoppingList.AddItem(item, chosenSection.Object.Id);

            // Assert
            using (new AssertionScope())
            {
                chosenSection.VerifyAddItemOnce(item);
            }
        }
Exemplo n.º 3
0
        public void ChangeItemQuantity_WithValidItemId_ShouldChangeQuantity()
        {
            // Arrange
            var sectionMocks = shoppingListSectionMockFixture.CreateMany(3).ToList();

            var listDefinition = new ShoppingListDefinition()
            {
                Sections = sectionMocks.Select(s => s.Object)
            };
            var shoppingList = shoppingListFixture.Create(listDefinition);

            ShoppingListSectionMock chosenSectionMock = commonFixture.ChooseRandom(sectionMocks);
            IShoppingListItem       chosenItem        = commonFixture.ChooseRandom(chosenSectionMock.Object.Items);

            sectionMocks.ForEach(m => m.SetupContainsItem(m == chosenSectionMock));

            float quantity = commonFixture.NextFloat();

            // Act
            shoppingList.ChangeItemQuantity(chosenItem.Id, quantity);

            // Assert
            using (new AssertionScope())
            {
                foreach (var section in sectionMocks)
                {
                    if (section == chosenSectionMock)
                    {
                        section.VerifyChangeItemQuantityOnce(chosenItem.Id, quantity);
                    }
                    else
                    {
                        section.VerifyChangeItemQuantityNever();
                    }
                }
            }
        }