public void Handle_WhenNextStepIsDefined_ShouldCallNextStep()
        {
            //arrange
            var allowedStates = new[]
            {
                "10",
            };

            var allowedOtherGECOsStates = new[]
            {
                "10",
                "25",
            };

            var tabItems = allowedStates.Select(state =>
            {
                Item item = ItemHelper.CreateItem(string.Empty, string.Empty);
                item.setProperty(StatePropertyKey, state);
                return(item);
            });

            var relationshipItems = new Dictionary <string, IEnumerable <Item> >()
            {
                { TestRelationshipName, tabItems },
            };

            Item currentGECO = ItemHelper.CreateItem(string.Empty, string.Empty);

            currentGECO.setNewID();

            var validationContext = new ValidationContext(relationshipItems)
            {
                CurrentGECO = currentGECO,
                RootItem    = ItemHelper.CreateItem(string.Empty, string.Empty),
            };

            IRelationshipNameProvider relationshipNameProvider = Substitute.For <IRelationshipNameProvider>();

            relationshipNameProvider.TabName.Returns(TestRelationshipName);
            Item anotherGECO = ItemHelper.CreateItem(string.Empty, string.Empty);

            anotherGECO.setNewID();
            Item affectedItem = ItemHelper.CreateItem(string.Empty, string.Empty);

            affectedItem.setProperty("gag_action", "Release");

            IGECOProvider gecoProvider = Substitute.For <IGECOProvider>();

            gecoProvider.GetRelatedGECOs(Arg.Any <Item>()).Returns(new[] { anotherGECO });
            gecoProvider.GECOContainsItem(Arg.Any <Item>(), Arg.Any <string>()).Returns(false);
            gecoProvider.FindAffectedItems(Arg.Any <Item>(), Arg.Any <string>()).Returns(new[] { affectedItem });
            IStep nextStep = Substitute.For <IStep>();

            var testClass = new TestClass(nameof(TestClass), gecoProvider, relationshipNameProvider, allowedStates);

            testClass.SetNext(nextStep);

            //act
            testClass.Handle(validationContext);

            //assert
            nextStep.Received(1).Handle(Arg.Any <ValidationContext>());
        }
        public void Handle_WhenRelationshipItemsOnCurrentGECOWithNotAllowedState_ShouldReturnErrorCollection()
        {
            //arrange
            var allowedStates = new[]
            {
                "10",
            };

            Item affectedItem = ItemHelper.CreateItem(string.Empty, string.Empty);

            affectedItem.setProperty("gag_action", "Release");

            Item item = ItemHelper.CreateItem(TestType, string.Empty);

            item.setProperty(StatePropertyKey, "invalid state");
            var relationshipItems = new Dictionary <string, IEnumerable <Item> >()
            {
                { TestRelationshipName, new [] { item } },
            };

            Item currentGECO = ItemHelper.CreateItem(string.Empty, string.Empty);

            currentGECO.setNewID();

            var validationContext = new ValidationContext(relationshipItems)
            {
                CurrentGECO = currentGECO,
                RootItem    = ItemHelper.CreateItem(string.Empty, string.Empty),
            };

            int expectedErrorCounts = allowedStates.Length;
            IRelationshipNameProvider relationshipNameProvider = Substitute.For <IRelationshipNameProvider>();

            relationshipNameProvider.TabName.Returns(TestRelationshipName);
            Item anotherGECO = ItemHelper.CreateItem(string.Empty, string.Empty);

            anotherGECO.setNewID();

            Item[]        relatedItems = { anotherGECO };
            IGECOProvider gecoProvider = Substitute.For <IGECOProvider>();

            gecoProvider.GetRelatedGECOs(Arg.Any <Item>()).Returns(relatedItems);
            gecoProvider.GetActualItems(Arg.Any <Item>(), Arg.Any <Item>()).Returns(relatedItems);
            gecoProvider.GECOContainsItem(Arg.Any <Item>(), Arg.Any <string>()).Returns(true);
            gecoProvider.FindAffectedItems(Arg.Any <Item>(), Arg.Any <string>()).Returns(new[] { affectedItem });

            var testClass = new TestClass(nameof(TestClass), gecoProvider, 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_WhenRelationshipItemsWithAllowedStatesContainsOnOtherActiveGECOsWithNotCadReleaseClassification_ShouldReturnCollectionWithMessages(string affectedItemAction)
        {
            //arrange
            var states = new[]
            {
                "10",
                "20",
            };

            var tabItems = states.Select(state =>
            {
                Item item = ItemHelper.CreateItem(TestType, string.Empty);
                item.setProperty(StatePropertyKey, state);
                return(item);
            });

            var relationshipItems = new Dictionary <string, IEnumerable <Item> >()
            {
                { TestRelationshipName, tabItems },
            };

            Item currentGECO = ItemHelper.CreateItem(string.Empty, string.Empty);

            currentGECO.setNewID();

            var validationContext = new ValidationContext(relationshipItems)
            {
                CurrentGECO = currentGECO,
                RootItem    = ItemHelper.CreateItem(string.Empty, string.Empty),
            };

            Item affectedItem = ItemHelper.CreateItem(string.Empty, string.Empty);

            affectedItem.setProperty("gag_action", affectedItemAction);

            int expectedErrorCounts = states.Length;
            IRelationshipNameProvider relationshipNameProvider = Substitute.For <IRelationshipNameProvider>();

            relationshipNameProvider.TabName.Returns(TestRelationshipName);
            Item anotherGECO = ItemHelper.CreateItem(string.Empty, string.Empty);

            anotherGECO.setNewID();
            anotherGECO.setProperty("classification", "invalid classification");

            IGECOProvider gecoProvider = Substitute.For <IGECOProvider>();

            gecoProvider.GetRelatedGECOs(Arg.Any <Item>()).Returns(new[] { anotherGECO });
            gecoProvider.GECOIsActive(Arg.Any <Item>()).Returns(true);
            gecoProvider.FindAffectedItems(Arg.Any <Item>(), Arg.Any <string>()).Returns(new[] { affectedItem });

            string[] availableClassifications = { "available classification" };
            var      testClass = new TestClass(nameof(TestClass), gecoProvider, relationshipNameProvider, availableClassifications, states);
            IReadOnlyCollection <ValidatorInfoModel> validatorInfo
                = new[]
                {
                new ValidatorInfoModel
                {
                    AllowedStates = states,
                    Name          = testClass.Name,
                    Type          = TestType,
                },
                };

            StepHelper.ApplyFinalStep(testClass, validatorInfo);

            //act
            IList <string> result = testClass.Handle(validationContext).ToList();

            //assert
            Assert.AreEqual(expectedErrorCounts, result.Count);
        }