public void Handle_WhenStatesOfThreeRelationshipItemAreNotInAllowedStates_ShouldReturnCollectionWithThreeErrorMessages() { //arrange var invalidStates = new[] { "15", "1", "30", }; var allowedStates = new[] { "10", "20", }; int expectedErrorCounts = invalidStates.Length; var items = invalidStates.Select(state => { Item item = ItemHelper.CreateItem(TestType, string.Empty); item.setProperty(StatePropertyKey, state); return(item); }); var relationshipItems = new Dictionary <string, IEnumerable <Item> >() { { TestRelationshipName, items }, }; var validationContext = new ValidationContext(relationshipItems) { CurrentGECO = ItemHelper.CreateItem(string.Empty, string.Empty), RootItem = ItemHelper.CreateItem(string.Empty, string.Empty), }; IRelationshipNameProvider relationshipNameProvider = Substitute.For <IRelationshipNameProvider>(); relationshipNameProvider.TabName.Returns(TestRelationshipName); var testClass = new TestClass(nameof(TestClass), relationshipNameProvider, allowedStates); IReadOnlyCollection <ValidatorInfoModel> validatorInfo = new[] { new ValidatorInfoModel { AllowedStates = allowedStates, Name = testClass.Name, Type = TestType, }, }; StepHelper.ApplyFinalStep(testClass, validatorInfo); //act IList <string> result = testClass.Handle(validationContext).ToList(); //assert Assert.AreEqual(expectedErrorCounts, result.Count); }
public void Handle_WhenNextStepIsDefined_ShouldCallNextStep() { //arrange var allowedStates = new[] { "10", "20", }; var items = allowedStates.Select(state => { Item item = ItemHelper.CreateItem("Test item", string.Empty); item.setProperty(StatePropertyKey, state); return(item); }); var relationshipItems = new Dictionary <string, IEnumerable <Item> >() { { TestRelationshipName, items }, }; var validationContext = new ValidationContext(relationshipItems) { CurrentGECO = ItemHelper.CreateItem(string.Empty, string.Empty), RootItem = ItemHelper.CreateItem(string.Empty, string.Empty), }; IRelationshipNameProvider relationshipNameProvider = Substitute.For <IRelationshipNameProvider>(); relationshipNameProvider.TabName.Returns(TestRelationshipName); IStep nextStep = Substitute.For <IStep>(); var testClass = new TestClass(nameof(TestClass), relationshipNameProvider, allowedStates); testClass.SetNext(nextStep); //act testClass.Handle(validationContext); //assert nextStep.Received(1).Handle(Arg.Any <ValidationContext>()); }
public void Handle_WhenValidationContextDoesNotHaveRelationshipItems_ShouldThrowInvalidOperationException() { //arrange var relationshipItems = new Dictionary <string, IEnumerable <Item> >() { { TestRelationshipName, Array.Empty <Item>() }, }; var validationContext = new ValidationContext(relationshipItems) { CurrentGECO = ItemHelper.CreateItem(string.Empty, string.Empty), RootItem = ItemHelper.CreateItem(string.Empty, string.Empty), }; IRelationshipNameProvider relationshipNameProvider = Substitute.For <IRelationshipNameProvider>(); relationshipNameProvider.TabName.Returns("Another relationship name"); var testClass = new TestClass(nameof(TestClass), relationshipNameProvider, Array.Empty <string>()); //act //assert Assert.Throws <InvalidOperationException>(() => testClass.Handle(validationContext)); }