Пример #1
0
        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_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);
        }