public void SetupCreateEmpty(SectionId sectionId, IShoppingListSection returnValue)
 {
     mock
     .Setup(instance => instance.CreateEmpty(
                It.Is <SectionId>(id => id == sectionId)))
     .Returns(returnValue);
 }
示例#2
0
        public void AddSection(IShoppingListSection section)
        {
            if (section is null)
            {
                throw new ArgumentNullException(nameof(section));
            }

            if (sections.ContainsKey(section.Id))
            {
                throw new DomainException(new SectionAlreadyInShoppingListReason(Id, section.Id));
            }

            sections.Add(section.Id, section);
        }
示例#3
0
        public void AddSection_WithSectionAlreadyInShoppingList_ShouldThrowDomainException()
        {
            IShoppingList        shoppingList = shoppingListFixture.CreateValid();
            IShoppingListSection section      = commonFixture.ChooseRandom(shoppingList.Sections);

            // Act
            Action action = () => shoppingList.AddSection(section);

            // Assert
            using (new AssertionScope())
            {
                action.Should().Throw <DomainException>()
                .Where(e => e.Reason.ErrorCode == ErrorReasonCode.SectionAlreadyInShoppingList);
            }
        }
示例#4
0
        public void RemoveFromBasket(ItemId itemId)
        {
            if (itemId == null)
            {
                throw new ArgumentNullException(nameof(itemId));
            }

            IShoppingListSection section = sections.Values.FirstOrDefault(s => s.ContainsItem(itemId));

            if (section == null)
            {
                throw new DomainException(new ItemNotOnShoppingListReason(Id, itemId));
            }

            sections[section.Id] = section.RemoveItemFromBasket(itemId);
        }
示例#5
0
        public void RemoveItem(ItemId itemId)
        {
            if (itemId == null)
            {
                throw new ArgumentNullException(nameof(itemId));
            }

            IShoppingListSection section = sections.Values.FirstOrDefault(s => s.ContainsItem(itemId));

            if (section == null)
            {
                return;
            }

            sections[section.Id] = section.RemoveItem(itemId);
        }
示例#6
0
        public void AddSection_WithNewSection_ShouldThrowDomainException()
        {
            IShoppingList shoppingList       = shoppingListFixture.CreateValid();
            var           existingSectionIds = shoppingList.Sections.Select(s => s.Id.Value);

            var sectionDef = ShoppingListSectionDefinition.FromId(commonFixture.NextInt(existingSectionIds));
            IShoppingListSection section = shoppingListSectionFixture.CreateValid(sectionDef);

            // Act
            shoppingList.AddSection(section);

            // Assert
            using (new AssertionScope())
            {
                shoppingList.Sections.Should().Contain(section);
            }
        }
示例#7
0
        public void ChangeItemQuantity(ItemId itemId, float quantity)
        {
            if (itemId == null)
            {
                throw new ArgumentNullException(nameof(itemId));
            }
            if (quantity <= 0f)
            {
                throw new DomainException(new InvalidItemQuantityReason(quantity));
            }

            IShoppingListSection section = sections.Values.FirstOrDefault(s => s.ContainsItem(itemId));

            if (section == null)
            {
                throw new DomainException(new ItemNotOnShoppingListReason(Id, itemId));
            }

            sections[section.Id] = section.ChangeItemQuantity(itemId, quantity);
        }
示例#8
0
 public void VerifyAddSectionOnce(IShoppingListSection section)
 {
     Verify(i => i.AddSection(section),
            Times.Once);
 }