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_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 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); } }