public IStoreItem CreateItem() { var itemCategoryId = new ItemCategoryId(CommonFixture.NextInt()); var manufacturerId = new ManufacturerId(CommonFixture.NextInt()); return(CreateItem(itemCategoryId, manufacturerId)); }
public void VerifyValidateAsyncOnce(ItemCategoryId itemCategoryId) { mock.Verify(i => i.ValidateAsync( itemCategoryId, It.IsAny <CancellationToken>()), Times.Once); }
public async Task <IEnumerable <IStoreItem> > FindActiveByAsync(ItemCategoryId itemCategoryId, CancellationToken cancellationToken) { if (itemCategoryId is null) { throw new ArgumentNullException(nameof(itemCategoryId)); } cancellationToken.ThrowIfCancellationRequested(); var entities = await GetItemQuery() .Where(item => item.ItemCategoryId.HasValue && item.ItemCategoryId == itemCategoryId.Value && !item.Deleted) .ToListAsync(); cancellationToken.ThrowIfCancellationRequested(); foreach (var item in entities) { item.Predecessor = await LoadPredecessorsAsync(item); } return(toModelConverter.ToDomain(entities)); }
public void SetupFindActiveByAsync(ItemCategoryId itemCategoryId, IEnumerable <IStoreItem> returnValue) { mock .Setup(i => i.FindActiveByAsync( It.Is <ItemCategoryId>(id => id == itemCategoryId), It.IsAny <CancellationToken>())) .ReturnsAsync(returnValue); }
public void SetupFindByAsync(ItemCategoryId itemCategoryId, IItemCategory returnValue) { mock .Setup(i => i.FindByAsync( It.Is <ItemCategoryId>(id => id == itemCategoryId), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(returnValue)); }
private IStoreItem CreateItem(ItemCategoryId itemCategoryId, ManufacturerId manufacturerId) { var def = new StoreItemDefinition { ItemCategoryId = itemCategoryId, ManufacturerId = manufacturerId, Availabilities = StoreItemAvailabilityFixture.CreateManyValid(1) }; return(StoreItemFixture.CreateValid(def)); }
public override int GetHashCode() { int hash = 1; if (ItemCategoryId != 0) { hash ^= ItemCategoryId.GetHashCode(); } hash ^= subcategories_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public async Task ValidateAsync(ItemCategoryId itemCategoryId, CancellationToken cancellationToken) { if (itemCategoryId is null) { throw new ArgumentNullException(nameof(itemCategoryId)); } IItemCategory itemCategory = await itemCategoryRepository .FindByAsync(itemCategoryId, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); if (itemCategory == null) { throw new DomainException(new ItemCategoryNotFoundReason(itemCategoryId)); } }
public async Task <IItemCategory> FindByAsync(ItemCategoryId id, CancellationToken cancellationToken) { if (id == null) { throw new ArgumentNullException(nameof(id)); } var entity = await dbContext.ItemCategories.AsNoTracking() .FirstOrDefaultAsync(category => category.Id == id.Value); cancellationToken.ThrowIfCancellationRequested(); if (entity == null) { return(null); } return(toModelConverter.ToDomain(entity)); }
public IItemCategory GetItemCategory(ItemCategoryId id = null, string name = null, bool?isDeleted = null) { var fixture = commonFixture.GetNewFixture(); if (id != null) { fixture.ConstructorArgumentFor <ItemCategory, ItemCategoryId>("id", id); } if (name != null) { fixture.ConstructorArgumentFor <ItemCategory, string>("name", name); } if (isDeleted.HasValue) { fixture.ConstructorArgumentFor <ItemCategory, bool>("isDeleted", isDeleted.Value); } return(fixture.Create <ItemCategory>()); }
public ItemUpdate(ItemId oldId, string name, string comment, QuantityType quantityType, float quantityInPacket, QuantityTypeInPacket quantityTypeInPacket, ItemCategoryId itemCategoryId, ManufacturerId manufacturerId, IEnumerable <IStoreItemAvailability> availabilities) { if (string.IsNullOrWhiteSpace(name)) { throw new System.ArgumentException($"'{nameof(name)}' cannot be null or whitespace", nameof(name)); } OldId = oldId ?? throw new System.ArgumentNullException(nameof(oldId)); Name = name; Comment = comment; QuantityType = quantityType; QuantityInPacket = quantityInPacket; QuantityTypeInPacket = quantityTypeInPacket; ItemCategoryId = itemCategoryId ?? throw new System.ArgumentNullException(nameof(itemCategoryId)); ManufacturerId = manufacturerId; this.availabilities = availabilities ?? throw new System.ArgumentNullException(nameof(availabilities)); }
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 StoreItem(ItemId id, string name, bool isDeleted, string comment, bool isTemporary, QuantityType quantityType, float quantityInPacket, QuantityTypeInPacket quantityTypeInPacket, ItemCategoryId itemCategoryId, ManufacturerId manufacturerId, IEnumerable <IStoreItemAvailability> availabilities, TemporaryItemId temporaryId) { Id = id ?? throw new ArgumentNullException(nameof(id)); Name = name; IsDeleted = isDeleted; Comment = comment; IsTemporary = isTemporary; QuantityType = quantityType; QuantityInPacket = quantityInPacket; QuantityTypeInPacket = quantityTypeInPacket; ItemCategoryId = itemCategoryId; ManufacturerId = manufacturerId; TemporaryId = temporaryId; this.availabilities = availabilities.ToList() ?? throw new ArgumentNullException(nameof(availabilities)); // predecessor must be explicitly set via SetPredecessor(...) due to this AutoFixture bug: // https://github.com/AutoFixture/AutoFixture/issues/1108 Predecessor = null; }
public IStoreItem Create(ItemId id, string name, bool isDeleted, string comment, bool isTemporary, QuantityType quantityType, float quantityInPacket, QuantityTypeInPacket quantityTypeInPacket, ItemCategoryId itemCategoryId, ManufacturerId manufacturerId, IStoreItem predecessor, IEnumerable <IStoreItemAvailability> availabilities, TemporaryItemId temporaryId) { var item = new StoreItem( id, name, isDeleted, comment, isTemporary, quantityType, quantityInPacket, quantityTypeInPacket, itemCategoryId, manufacturerId, availabilities, temporaryId); item.SetPredecessor(predecessor); return(item); }
public IItemCategory Create(ItemCategoryId id, string name, bool isDeleted) { return(new ItemCategory(id, name, isDeleted)); }
public IStoreItem CreateItemWithoutManufacturer() { var itemCategoryId = new ItemCategoryId(CommonFixture.NextInt()); return(CreateItem(itemCategoryId, null)); }
public IItemCategory CreateItemCategory(ItemCategoryId itemCategoryId) { return(ItemCategoryFixture.GetItemCategory(itemCategoryId)); }
public ItemCategoryNotFoundReason(ItemCategoryId id) { Message = $"Item category {id.Value} not found."; }
public void SetupId(ItemCategoryId returnValue) { Setup(i => i.Id) .Returns(returnValue); }
public ItemCategory(ItemCategoryId id, string name, bool isDeleted) { Id = id; Name = name; IsDeleted = isDeleted; }
public DeleteItemCategoryCommand(ItemCategoryId itemCategoryId) { ItemCategoryId = itemCategoryId; }