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);
            }
        }
コード例 #3
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();
            }
        }