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");

            string[] availableClassifications = { "Release & Change/CAD Document" };
            var      testClass = new TestClass(nameof(TestClass), Substitute.For <IGECOProvider>(), relationshipNameProvider, availableClassifications, Array.Empty <string>());

            //act
            //assert
            Assert.Throws <InvalidOperationException>(() => testClass.Handle(validationContext));
        }
        public void Handle_WhenNextStepIsDefined_ShouldCallNextStep()
        {
            //arrange
            var ignoreStates = new[]
            {
                "10",
                "20",
            };

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

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

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

            Item anotherGECO = ItemHelper.CreateItem(string.Empty, string.Empty);
            IRelationshipNameProvider relationshipNameProvider = Substitute.For <IRelationshipNameProvider>();

            relationshipNameProvider.TabName.Returns(TestRelationshipName);
            IGECOProvider gecoProvider = Substitute.For <IGECOProvider>();

            gecoProvider.GetRelatedGECOs(anotherGECO);
            IStep nextStep = Substitute.For <IStep>();

            string[] availableClassifications = { "Release & Change/CAD Document" };
            var      testClass = new TestClass(nameof(TestClass), gecoProvider, relationshipNameProvider, availableClassifications, ignoreStates);

            testClass.SetNext(nextStep);

            //act
            testClass.Handle(validationContext);

            //assert
            nextStep.Received(1).Handle(Arg.Any <ValidationContext>());
        }
        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);
        }