public async Task itemSizeIsValidated() { var currentInstant = Instant.FromUtc(2017, 08, 17, 12, 0, 0); var fakeClock = new FakeClock(currentInstant); var itemValidator = new itemItemValidator() as IMessageValidator <ItemAsset>; var validator = new ItemOutValidator(itemValidator); var header = new OrderHeader { OrderId = "ABC123", OrderDate = currentInstant.ToDateTimeUtc() }; var item = new List <ItemAsset>(); // Note that the test is "<=" which will add one extra item to the set, since the index // starts at 0. for (var index = 0; index <= ItemOutValidator.MaxitemItemCount; ++index) { item.Add(new ItemAsset { Name = $"Key{ index }", Location = $"Value{ index }" }); } var target = new LineItem { Assets = item }; var result = await validator.ValidateAsync(target); result.Should().NotBeNull("because a validation result should have been returned"); result.Should().ContainSingle(error => ((error.MemberPath == nameof(LineItem.Assets)) && (error.Code == ErrorCode.SetCountIsInvalid.ToString())), "because the item set has too many items"); }
public async Task itemItemsAreValidated() { var currentInstant = Instant.FromUtc(2017, 08, 17, 12, 0, 0); var fakeClock = new FakeClock(currentInstant); var headerValidator = new OrderHeaderValidator(fakeClock) as IMessageValidator <OrderHeader>; var itemValidator = new itemItemValidator() as IMessageValidator <ItemAsset>; var validator = new ItemOutValidator(itemValidator); var header = new OrderHeader { OrderId = "ABC123", OrderDate = currentInstant.ToDateTimeUtc() }; var item = new List <ItemAsset>(); item.Add(new ItemAsset { Name = "Item", Location = null }); var target = new LineItem { Assets = item }; var result = await validator.ValidateAsync(target); var failurePath = $"{ nameof(LineItem.Assets) }[0].{ nameof(ItemAsset.Location) }"; result.Should().NotBeNull("because a validation result should have been returned"); result.Should().ContainSingle(error => error.MemberPath == failurePath, "because the item item value was not set"); }
public async Task ValueIsRequired(string value) { var validator = new itemItemValidator(); var target = new ItemAsset { Name = "SomeName", Location = value }; var result = await validator.ValidateAsync(target); result.Should().NotBeNull("because a validation result should have been returned"); result.Should().ContainSingle(error => ((error.MemberPath == nameof(ItemAsset.Location)) && (error.Code == ErrorCode.ValueIsRequired.ToString())), "because the value was not provided"); }
public async Task ValueIsValidated() { var value = new String('j', itemItemValidator.MaxValueLength + 1); var validator = new itemItemValidator(); var target = new ItemAsset { Name = "SomeName", Location = value }; var result = await validator.ValidateAsync(target); result.Should().NotBeNull("because a validation result should have been returned"); result.Should().ContainSingle(error => ((error.MemberPath == nameof(ItemAsset.Location)) && (error.Code == ErrorCode.LengthIsInvalid.ToString())), "because the value was too long"); }
public async Task RequestHeaderIsRequired() { var currentInstant = Instant.FromUtc(2017, 08, 17, 12, 0, 0); var fakeClock = new FakeClock(currentInstant); var headerValidator = new OrderHeaderValidator(fakeClock) as IMessageValidator <OrderHeader>; var itemValidator = new itemItemValidator() as IMessageValidator <ItemAsset>; var itemOutValidator = new ItemOutValidator(itemValidator) as IMessageValidator <LineItem>; var validator = new OrderFulfillmentMessageValidator(headerValidator, itemOutValidator); var target = new OrderFulfillmentMessage { OrderRequestHeader = null, LineItems = new List <LineItem>() }; var result = await validator.ValidateAsync(target); result.Should().NotBeNull("because a validation result should have been returned"); result.Should().ContainSingle(error => ((error.MemberPath == nameof(OrderFulfillmentMessage.OrderRequestHeader)) && (error.Code == ErrorCode.ValueIsRequired.ToString())), "because the order header was not provided"); }
public async Task EmptyitemIsValid() { var currentInstant = Instant.FromUtc(2017, 08, 17, 12, 0, 0); var fakeClock = new FakeClock(currentInstant); var itemValidator = new itemItemValidator() as IMessageValidator <ItemAsset>; var validator = new ItemOutValidator(itemValidator); var header = new OrderHeader { OrderId = "ABC123", OrderDate = currentInstant.ToDateTimeUtc() }; var target = new LineItem { Assets = new List <ItemAsset>() }; var result = await validator.ValidateAsync(target); result.Should().NotBeNull("because a validation result should have been returned"); result.Should().BeEmpty("because an empty item set is allowed"); }
public async Task itemIsRequired() { var currentInstant = Instant.FromUtc(2017, 08, 17, 12, 0, 0); var fakeClock = new FakeClock(currentInstant); var itemValidator = new itemItemValidator() as IMessageValidator <ItemAsset>; var validator = new ItemOutValidator(itemValidator); var header = new OrderHeader { OrderId = "ABC123", OrderDate = currentInstant.ToDateTimeUtc() }; var target = new LineItem { Assets = null }; var result = await validator.ValidateAsync(target); result.Should().NotBeNull("because a validation result should have been returned"); result.Should().ContainSingle(error => ((error.MemberPath == nameof(LineItem.Assets)) && (error.Code == ErrorCode.ValueIsRequired.ToString())), "because the item set was not provided"); }
public async Task RequestHeaderIsValidated() { var currentInstant = Instant.FromUtc(2017, 08, 17, 12, 0, 0); var fakeClock = new FakeClock(currentInstant); var headerValidator = new OrderHeaderValidator(fakeClock) as IMessageValidator <OrderHeader>; var itemValidator = new itemItemValidator() as IMessageValidator <ItemAsset>; var itemOutValidator = new ItemOutValidator(itemValidator) as IMessageValidator <LineItem>; var validator = new OrderFulfillmentMessageValidator(headerValidator, itemOutValidator); var header = new OrderHeader { OrderId = null, OrderDate = currentInstant.ToDateTimeUtc() }; var target = new OrderFulfillmentMessage { OrderRequestHeader = header, LineItems = new List <LineItem>() }; var result = await validator.ValidateAsync(target); result.Should().NotBeNull("because a validation result should have been returned"); result.Should().ContainSingle(error => (error.MemberPath == $"{ nameof(OrderFulfillmentMessage.OrderRequestHeader) }.{ nameof(OrderHeader.OrderId) }"), "because the order id was not provided in the header"); }
public async Task ItemOutsAreValidated() { var currentInstant = Instant.FromUtc(2017, 08, 17, 12, 0, 0); var fakeClock = new FakeClock(currentInstant); var headerValidator = new OrderHeaderValidator(fakeClock) as IMessageValidator <OrderHeader>; var itemValidator = new itemItemValidator() as IMessageValidator <ItemAsset>; var itemOutValidator = new ItemOutValidator(itemValidator) as IMessageValidator <LineItem>; var validator = new OrderFulfillmentMessageValidator(headerValidator, itemOutValidator); var header = new OrderHeader { OrderId = "ABC123", OrderDate = currentInstant.ToDateTimeUtc() }; var itemOuts = new List <LineItem> { new LineItem { Assets = new List <ItemAsset> { new ItemAsset(), new ItemAsset() } } }; var target = new OrderFulfillmentMessage { OrderRequestHeader = header, LineItems = itemOuts }; var result = await validator.ValidateAsync(target); var failurePath = $"{ nameof(OrderFulfillmentMessage.LineItems) }[0].{ nameof(LineItem.Assets) }"; result.Should().NotBeNull("because a validation result should have been returned"); result.Should().ContainSingle(error => error.MemberPath == failurePath, "because the itemout violated a rule"); }