public void SetupCreateEmpty(SectionId sectionId, IShoppingListSection returnValue) { mock .Setup(instance => instance.CreateEmpty( It.Is <SectionId>(id => id == sectionId))) .Returns(returnValue); }
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); }
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); } }
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); }
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); }
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); } }
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); }
public void VerifyAddSectionOnce(IShoppingListSection section) { Verify(i => i.AddSection(section), Times.Once); }