public async Task ExchangeItemAsync_WithNewItemAvailableForShoppingListAndInBasket_ShouldRemoveOldItemAndAddNewItem() { // Arrange var local = new LocalFixture(); var service = local.CreateService(); ShoppingListMock shoppingListMock = local.CreateShoppingListMockInBasket(); var shopppingListStoreId = shoppingListMock.Object.StoreId; IShoppingListItem oldShoppingListItem = shoppingListMock.GetRandomItem(local.CommonFixture, i => i.IsInBasket); ItemId oldItemId = oldShoppingListItem.Id; IStoreItem newItem = local.CreateNewItemForStore(shopppingListStoreId); local.ShoppingListRepositoryMock.SetupFindActiveByAsync(oldItemId, shoppingListMock.Object.ToMonoList()); // Act await service.ExchangeItemAsync(oldItemId, newItem, default); // Assert var sectionId = newItem.Availabilities.First(av => av.StoreId == shopppingListStoreId).DefaultSectionId; using (new AssertionScope()) { shoppingListMock.VerifyRemoveItemOnce(oldItemId); local.ShoppingListRepositoryMock.VerifyStoreAsyncOnce(shoppingListMock.Object); local.AddItemToShoppingListServiceMock.VerifyAddItemToShoppingListOnce(shoppingListMock.Object, newItem.Id, sectionId, oldShoppingListItem.Quantity); shoppingListMock.VerifyPutItemInBasketOnce(newItem.Id); } }
public async Task ExchangeItemAsync_WithNewItemNotAvailableForShoppingList_ShouldRemoveOldItemAndNotAddNewItem() { // Arrange var local = new LocalFixture(); var service = local.CreateService(); ShoppingListMock shoppingListMock = local.CreateShoppingListMockInBasket(); ItemId oldItemId = local.CommonFixture.ChooseRandom(shoppingListMock.Object.Items).Id; IStoreItem newItem = local.CreateNewItemNotInStore(shoppingListMock.Object.StoreId); local.ShoppingListRepositoryMock.SetupFindActiveByAsync(oldItemId, shoppingListMock.Object.ToMonoList()); // Act await service.ExchangeItemAsync(oldItemId, newItem, default); // Assert using (new AssertionScope()) { shoppingListMock.VerifyRemoveItemOnce(oldItemId); shoppingListMock.VerifyAddItemNever(); local.ShoppingListRepositoryMock.VerifyStoreAsyncOnce(shoppingListMock.Object); } }