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(); } } } }
public void RemoveItem_WithItemIdNotOnList_ShouldDoNothing() { // Arrange var sectionMocks = shoppingListSectionMockFixture.CreateMany(2).ToList(); sectionMocks.ForEach(m => m.SetupContainsItem(false)); var listDef = new ShoppingListDefinition { Sections = sectionMocks.Select(s => s.Object) }; var list = shoppingListFixture.CreateValid(listDef); var itemIdsToExclude = list.Items.Select(i => i.Id.Value); var shoppingListItemId = new ItemId(commonFixture.NextInt(itemIdsToExclude)); // Act list.RemoveItem(shoppingListItemId); // Assert using (new AssertionScope()) { foreach (var mock in sectionMocks) { mock.VerifyRemoveItemNever(); } } }
public ShoppingListMock CreateShoppingListMockWithIncompatibleStore(IStoreItem storeItem) { var storeIds = storeItem.Availabilities.Select(av => av.StoreId.Value); var listDef = new ShoppingListDefinition { StoreId = new StoreId(CommonFixture.NextInt(storeIds)) }; var list = ShoppingListFixture.CreateValid(listDef); return(new ShoppingListMock(list)); }
public ShoppingListMock CreateValidShoppingListMock(IStoreItem storeItem) { var storeId = CommonFixture.ChooseRandom(storeItem.Availabilities).StoreId; var listDef = new ShoppingListDefinition { StoreId = storeId }; var list = ShoppingListFixture.CreateValid(listDef); return(new ShoppingListMock(list)); }
private IShoppingList GetShoppingListContainingOneItem(StoreId storeId, SectionId sectionId) { var sectionDef = new ShoppingListSectionDefinition { Id = sectionId, Items = shoppingListItemFixture.AsModelFixture().CreateValid().ToMonoList(), }; var section = shoppingListSectionFixture.CreateValid(sectionDef); var listDef = new ShoppingListDefinition { StoreId = storeId, Sections = section.ToMonoList() }; return(shoppingListFixture.CreateValid(listDef)); }
private object[] EmptyList() { IStore store = storeFixture.CreateValid(); var listDef = new ShoppingListDefinition { StoreId = store.Id, Sections = Enumerable.Empty <IShoppingListSection>() }; var list = shoppingListFixture.Create(listDef); var listReadModel = ToSimpleReadModel(list, store, null, null, null); return(new object[] { list, store, Enumerable.Empty <IStoreItem>(), Enumerable.Empty <IItemCategory>(), Enumerable.Empty <IManufacturer>(), listReadModel }); }
public void Finish_WithCompletedShoppingList_ShouldThrowDomainException() { // Arrange var fixture = commonFixture.GetNewFixture(); var listDefinition = new ShoppingListDefinition() { CompletionDate = fixture.Create <DateTime>() }; var shoppingList = shoppingListFixture.Create(listDefinition); DateTime completionDate = fixture.Create <DateTime>(); // Act Action action = () => shoppingList.Finish(completionDate); // Assert using (new AssertionScope()) { action.Should().Throw <DomainException>() .Where(e => e.Reason.ErrorCode == ErrorReasonCode.ShoppingListAlreadyFinished); } }
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); } }
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(); } } } }
public void Finish_WithUncompletedShoppingList_ShouldSetCompletionDate() { // Arrange var itemInBasket = shoppingListItemFixture.CreateValidWithBasketStatus(true); var itemNotInBasket = shoppingListItemFixture.CreateValidWithBasketStatus(false); var itemInBasketSection = shoppingListSectionFixture.CreateValidWithItem(itemInBasket); var itemNotInBasketSection = shoppingListSectionFixture.CreateValidWithItem(itemNotInBasket); var listDefinition = new ShoppingListDefinition { CompletionDate = null, Sections = new[] { itemInBasketSection, itemNotInBasketSection } }; var shoppingList = shoppingListFixture.Create(listDefinition); DateTime completionDate = commonFixture.GetNewFixture().Create <DateTime>(); // Act IShoppingList result = shoppingList.Finish(completionDate); // Assert var expectedResult = new DomainModels.ShoppingList( new ShoppingListId(0), shoppingList.StoreId, null, new List <IShoppingListSection> { new ShoppingListSection( itemNotInBasketSection.Id, new List <IShoppingListItem> { new ShoppingListItem( itemNotInBasket.Id, isInBasket: false, itemNotInBasket.Quantity) }), new ShoppingListSection( itemInBasketSection.Id, Enumerable.Empty <IShoppingListItem>()) }); var expectedRemaining = new DomainModels.ShoppingList( shoppingList.Id, shoppingList.StoreId, completionDate, new List <IShoppingListSection> { new ShoppingListSection( itemInBasketSection.Id, new List <IShoppingListItem> { new ShoppingListItem( itemInBasket.Id, true, itemInBasket.Quantity) }), new ShoppingListSection( itemNotInBasketSection.Id, Enumerable.Empty <IShoppingListItem>()) }); using (new AssertionScope()) { shoppingList.Should().BeEquivalentTo(expectedRemaining); result.Should().BeEquivalentTo(expectedResult); } }