public async Task ExchangeItemAsync_WithNewItemAvailableForShoppingListAndNotInBasket_ShouldRemoveOldItemAndAddNewItem()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            ShoppingListMock shoppingListMock = local.CreateShoppingListMockNotInBasket();
            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.VerifyPutItemInBasketNever();
            }
        }
        public async Task ConvertAsync_WithInvalidManufacturer_ShouldConvertToReadModel()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            var item         = local.CreateItem();
            var availability = item.Availabilities.First();
            var itemCategory = local.CreateItemCategory(item.ItemCategoryId);
            var store        = local.CreateStore(availability.StoreId, availability.DefaultSectionId);

            local.ItemCategoryRepositoryMock.SetupFindByAsync(item.ItemCategoryId, itemCategory);
            local.ManufacturerRepositoryMock.SetupFindByAsync(item.ManufacturerId, null);
            local.StoreRepositoryMock.SetupFindByAsync(availability.StoreId.ToMonoList(), store.ToMonoList());

            // Act
            Func <Task <StoreItemReadModel> > function = async() => await service.ConvertAsync(item, default);

            // Assert
            using (new AssertionScope())
            {
                (await function.Should().ThrowAsync <DomainException>())
                .Where(ex => ex.Reason.ErrorCode == ErrorReasonCode.ManufacturerNotFound);
            }
        }
        public async Task ConvertAsync_WithItemCategoryAndManufacturer_ShouldConvertToReadModel()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            var item         = local.CreateItem();
            var availability = item.Availabilities.First();
            var itemCategory = local.CreateItemCategory(item.ItemCategoryId);
            var manufacturer = local.CreateManufacturer(item.ManufacturerId);
            var store        = local.CreateStore(availability.StoreId, availability.DefaultSectionId);

            local.ItemCategoryRepositoryMock.SetupFindByAsync(item.ItemCategoryId, itemCategory);
            local.ManufacturerRepositoryMock.SetupFindByAsync(item.ManufacturerId, manufacturer);
            local.StoreRepositoryMock.SetupFindByAsync(availability.StoreId.ToMonoList(), store.ToMonoList());

            // Act
            var result = await service.ConvertAsync(item, default);

            // Assert
            var expected = local.ToSimpleReadModel(item, itemCategory, manufacturer, store);

            using (new AssertionScope())
            {
                result.Should().BeEquivalentTo(expected);
            }
        }
        public async Task ConvertAsync_WithItemCategoryAndNoManufacturer_ShouldConvertToReadModel()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            var store = local.CreateStore();
            var items = local.CreateItemsWithoutManufacturer(store).ToList();

            var itemCategoryIds = items
                                  .Where(i => i.ItemCategoryId != null)
                                  .Select(i => i.ItemCategoryId);

            var manufacturerIds = items
                                  .Where(i => i.ManufacturerId != null)
                                  .Select(i => i.ManufacturerId);

            var itemCategoryDict = local.CreateItemCategories(itemCategoryIds);
            var manufacturerDict = local.CreateManufacturers(manufacturerIds);

            local.ItemCategoryRepositoryMock.SetupFindByAsync(itemCategoryIds, itemCategoryDict.Values);
            local.ManufacturerRepositoryMock.SetupFindByAsync(manufacturerIds, manufacturerDict.Values);

            // Act
            var result = await service.ConvertAsync(items, store, default);

            // Assert
            var expected = local.ToSimpleReadModels(items, store, itemCategoryDict, manufacturerDict);

            using (new AssertionScope())
            {
                result.Should().BeEquivalentTo(expected);
            }
        }
        public async Task AddItemToShoppingList_WithItemIdIsNull_ShouldThrowArgumentNullException()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            var shoppingList = local.ShoppingListFixture.AsModelFixture().CreateValid();
            var sectionId    = new SectionId(local.CommonFixture.NextInt());
            var quantity     = local.CommonFixture.NextFloat();

            // Act
            Func <Task> function = async() => await service.AddItemToShoppingList(shoppingList, (ItemId)null,
                                                                                  sectionId, quantity, default);
        public async Task ConvertAsync_WithItemIsNull_ShouldThrowArgumentNullException()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            // Act
            Func <Task <StoreItemReadModel> > function = async() => await service.ConvertAsync(null, default);

            // Assert
            using (new AssertionScope())
            {
                await function.Should().ThrowAsync <ArgumentNullException>();
            }
        }
        public async Task ValidateAsync_WithAvailabilitiesIsNull_ShouldThrowArgumentNullException()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            // Act
            Func <Task> function = async() => await service.ValidateAsync(null, default);

            // Assert
            using (new AssertionScope())
            {
                await function.Should().ThrowAsync <ArgumentNullException>();
            }
        }
        public async Task ExchangeItemAsync_WithOldItemIdIsNull_ShouldThrowArgumentNullException()
        {
            // Arrange
            var local     = new LocalFixture();
            var service   = local.CreateService();
            var oldItemId = local.CreateOldItemId();

            // Act
            Func <Task> function = async() => await service.ExchangeItemAsync(oldItemId, null, default);

            // Assert
            using (new AssertionScope())
            {
                await function.Should().ThrowAsync <ArgumentNullException>();
            }
        }
        public async Task ValidateAsync_WithDuplicatedStoreIds_ShouldThrowDomainException()
        {
            // Arrange
            var local          = new LocalFixture();
            var service        = local.CreateService();
            var availabilities = local.CreateAvailabilitiesWithDuplicatedStoreIds();

            // Act
            Func <Task> function = async() => await service.ValidateAsync(availabilities, default);

            // Assert
            using (new AssertionScope())
            {
                (await function.Should().ThrowAsync <DomainException>())
                .Where(ex => ex.Reason.ErrorCode == ErrorReasonCode.MultipleAvailabilitiesForStore);
            }
        }
        public async Task AddItemToShoppingList_WithItemIdAndShoppingListIsNull_ShouldThrowArgumentNullException()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            var itemId    = new ItemId(local.CommonFixture.NextInt());
            var sectionId = new SectionId(local.CommonFixture.NextInt());
            var quantity  = local.CommonFixture.NextFloat();

            // Act
            Func <Task> function = async() => await service.AddItemToShoppingList(null, itemId, sectionId, quantity, default);

            // Assert
            using (new AssertionScope())
            {
                await function.Should().ThrowAsync <ArgumentNullException>();
            }
        }
コード例 #11
0
        public async Task ValidateAsync_WithValidItemCategoryId_ShouldNotThrow()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            var itemCategory = local.CreateItemCategory();

            local.ItemCategoryRepositoryMock.SetupFindByAsync(itemCategory.Id, itemCategory);

            // Act
            Func <Task> function = async() => await service.ValidateAsync(itemCategory.Id, default);

            // Assert
            using (new AssertionScope())
            {
                await function.Should().NotThrowAsync();
            }
        }
        public async Task ValidateAsync_WithValidManufacturerId_ShouldNotThrow()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            var manufacturer = local.CreateManufacturer();

            local.ManufacturerRepositoryMock.SetupFindByAsync(manufacturer.Id, manufacturer);

            // Act
            Func <Task> function = async() => await service.ValidateAsync(manufacturer.Id, default);

            // Assert
            using (new AssertionScope())
            {
                await function.Should().NotThrowAsync();
            }
        }
コード例 #13
0
        public async Task ValidateAsync_WithInvalidItemCategoryId_ShouldThrowDomainException()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            var itemCategoryId = new ItemCategoryId(local.CommonFixture.NextInt());

            local.ItemCategoryRepositoryMock.SetupFindByAsync(itemCategoryId, null);

            // Act
            Func <Task> function = async() => await service.ValidateAsync(itemCategoryId, default);

            // Assert
            using (new AssertionScope())
            {
                (await function.Should().ThrowAsync <DomainException>())
                .Where(ex => ex.Reason.ErrorCode == ErrorReasonCode.ItemCategoryNotFound);
            }
        }
        public async Task ExchangeItemAsync_WithOldItemOnNoShoppingLists_ShouldDoNothing()
        {
            // Arrange
            var local   = new LocalFixture();
            var service = local.CreateService();

            ItemId     oldItemId = local.CreateOldItemId();
            IStoreItem newItem   = local.CreateNewItem();

            local.ShoppingListRepositoryMock.SetupFindActiveByAsync(oldItemId, Enumerable.Empty <IShoppingList>());

            // Act
            await service.ExchangeItemAsync(oldItemId, newItem, default);

            // Assert
            using (new AssertionScope())
            {
                local.ShoppingListRepositoryMock.VerifyStoreAsyncNever();
            }
        }
        public async Task ValidateAsync_WithInvalidStoreId_ShouldThrowDomainException()
        {
            // Arrange
            var local          = new LocalFixture();
            var service        = local.CreateService();
            var availabilities = local.CreateValidAvailabilities();

            var storeIds = availabilities.Select(av => av.StoreId);

            local.StoreRepositoryMock.SetupFindByAsync(storeIds, Enumerable.Empty <IStore>());

            // Act
            Func <Task> function = async() => await service.ValidateAsync(availabilities, default);

            // Assert
            using (new AssertionScope())
            {
                (await function.Should().ThrowAsync <DomainException>())
                .Where(ex => ex.Reason.ErrorCode == ErrorReasonCode.StoreNotFound);
            }
        }
        public async Task ValidateAsync_WithValidData_ShouldNotThrow()
        {
            // Arrange
            var local          = new LocalFixture();
            var service        = local.CreateService();
            var availabilities = local.CreateValidAvailabilities().ToList();

            var storeIds = availabilities.Select(av => av.StoreId);
            var stores   = local.CreateValidStores(availabilities);

            local.StoreRepositoryMock.SetupFindByAsync(storeIds, stores);

            // Act
            Func <Task> function = async() => await service.ValidateAsync(availabilities, default);

            // Assert
            using (new AssertionScope())
            {
                await function.Should().NotThrowAsync();
            }
        }
        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);
            }
        }