Example #1
0
        public async Task Then_pages_are_not_returned_in_section()
        {
            var sectionId     = Guid.NewGuid();
            var applicationId = Guid.NewGuid();
            var dataContext   = DataContextHelpers.GetInMemoryDataContext();

            var applicationData = new { OrganisationType = "HEI" };

            dataContext.Applications.Add(new Data.Entities.Application()
            {
                Id = applicationId,
                ApplicationData = JsonConvert.SerializeObject(applicationData)
            });

            dataContext.ApplicationSections.Add(new ApplicationSection()
            {
                Id            = sectionId,
                ApplicationId = applicationId,
                QnAData       = new QnAData()
                {
                    Pages = new List <Page>()
                    {
                        new Page()
                        {
                            PageId = "1", Active = true
                        },
                        new Page()
                        {
                            PageId = "2", NotRequiredConditions = new List <NotRequiredCondition>()
                            {
                                new NotRequiredCondition()
                                {
                                    Field = "OrganisationType", IsOneOf = new [] { "HEI" }
                                }
                            }, Active = true
                        },
                        new Page()
                        {
                            PageId = "3", Active = true
                        }
                    }
                }
            });

            dataContext.SaveChanges();

            var mapperConfig         = new MapperConfiguration(options => { options.CreateMap <ApplicationSection, Section>(); });
            var notRequiredProcessor = new NotRequiredProcessor();

            var handler = new GetSectionHandler(dataContext, mapperConfig.CreateMapper(), notRequiredProcessor);

            var section = await handler.Handle(new GetSectionRequest(applicationId, sectionId), CancellationToken.None);

            section.Value.QnAData.Pages.Count.Should().Be(2);
        }
Example #2
0
        public void When_NotRequired_conditions_are_expected(string notRequiredConditionValue, string applicationDataValue, bool match)
        {
            var notRequiredProcessor = new NotRequiredProcessor();

            var notRequiredConditions = new List <NotRequiredCondition>
            {
                new NotRequiredCondition()
                {
                    Field = "FieldToTest", IsOneOf = new string[] { "value1", notRequiredConditionValue, "value2", "value3" }
                }
            };

            var applicationDataJson = JsonConvert.SerializeObject(new
            {
                FieldToTest = applicationDataValue
            });

            var applicationData = JObject.Parse(applicationDataJson);


            var result = notRequiredProcessor.NotRequired(notRequiredConditions, applicationData);

            Assert.AreEqual(match, result);
        }
        public void When_PagesWithNotRequired_conditions_with_containsAllOf(string[] containsAllValues, string applicationDataValue, bool match)
        {
            var expectedPagesCount = 1;

            if (!match)
            {
                expectedPagesCount = 2;
            }

            var pageIdAlwaysPresent       = "3";
            var pageIdAbsentIfNotRequired = "2";
            var applicationDataJson       = JsonConvert.SerializeObject(new
            {
                FieldToTest = applicationDataValue
            });

            var applicationData = JObject.Parse(applicationDataJson);

            var pages = new List <Page>
            {
                new Page
                {
                    PageId = pageIdAbsentIfNotRequired,
                    NotRequiredConditions = new List <NotRequiredCondition>
                    {
                        new NotRequiredCondition
                        {
                            Field         = "FieldToTest",
                            ContainsAllOf = containsAllValues
                        }
                    },
                    Next = new List <Next>
                    {
                        new Next
                        {
                            Action     = "NextPage",
                            ReturnId   = "12",
                            Conditions = new List <Condition>()
                        },
                        new Next
                        {
                            Action     = "NextPage",
                            ReturnId   = "14",
                            Conditions = new List <Condition>()
                        }
                    }
                },
                new Page
                {
                    PageId = pageIdAlwaysPresent,
                    NotRequiredConditions = null
                }
            };

            var notRequiredProcessor = new NotRequiredProcessor();
            var actualPages          = notRequiredProcessor.PagesWithoutNotRequired(pages, applicationData);

            Assert.AreEqual(actualPages.Count(), expectedPagesCount);
            Assert.IsTrue(actualPages.Any(p => p.PageId == pageIdAlwaysPresent));
            Assert.AreNotEqual(actualPages.Any(p => p.PageId == pageIdAbsentIfNotRequired), match);
        }
        public async Task SetUp()
        {
            DataContext = DataContextHelpers.GetInMemoryDataContext();
            var validator = Substitute.For <IAnswerValidator>();

            NotRequiredProcessor = new NotRequiredProcessor();
            TagProcessingService = new TagProcessingService(DataContext);

            validator.Validate(Arg.Any <List <Answer> >(), Arg.Any <Page>()).Returns(new List <KeyValuePair <string, string> >());

            Handler = new SetPageAnswersHandler(DataContext, validator, NotRequiredProcessor, TagProcessingService);

            ApplicationId = Guid.NewGuid();
            SectionId     = Guid.NewGuid();
            await DataContext.ApplicationSections.AddAsync(new ApplicationSection()
            {
                ApplicationId = ApplicationId,
                Id            = SectionId,
                QnAData       = new QnAData()
                {
                    Pages = new List <Page>
                    {
                        new Page()
                        {
                            PageId    = "1",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q1", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "2", Conditions = new List <Condition>()
                                    {
                                        new Condition {
                                            QuestionId = "Q1", MustEqual = "Yes"
                                        }
                                    }
                                },
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "4", Conditions = new List <Condition>()
                                    {
                                        new Condition {
                                            QuestionId = "Q1", MustEqual = "No"
                                        }
                                    }
                                }
                            },
                            Active = true
                        },
                        new Page()
                        {
                            PageId    = "2",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q2", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "3", Conditions = new List <Condition>()
                                    {
                                        new Condition {
                                            QuestionId = "Q2", MustEqual = "Yes"
                                        }
                                    }
                                },
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "5", Conditions = new List <Condition>()
                                    {
                                        new  Condition {
                                            QuestionId = "Q2", MustEqual = "No"
                                        }
                                    }
                                }
                            },
                            Active            = false,
                            ActivatedByPageId = "1"
                        },
                        new Page()
                        {
                            PageId    = "3",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q3", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "7"
                                }
                            },
                            Active            = false,
                            ActivatedByPageId = "2"
                        },
                        new Page()
                        {
                            PageId    = "4",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q4", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "6"
                                }
                            },
                            Active            = false,
                            ActivatedByPageId = "1"
                        },
                        new Page()
                        {
                            PageId    = "5",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q5", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "7"
                                }
                            },
                            Active            = false,
                            ActivatedByPageId = "2"
                        },
                        new Page()
                        {
                            PageId    = "6",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q6", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "8"
                                }
                            },
                            Active            = false,
                            ActivatedByPageId = "1"
                        },
                        new Page()
                        {
                            PageId    = "7",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q7", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "8"
                                }
                            },
                            Active            = false,
                            ActivatedByPageId = "1"
                        },
                        new Page()
                        {
                            PageId    = "8",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q8", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "9"
                                }
                            },
                            Active = true
                        },
                        new Page()
                        {
                            PageId    = "9",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q9", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "NextPage", ReturnId = "10"
                                }
                            },
                            Active = true
                        },
                        new Page()
                        {
                            PageId    = "10",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q10", Input = new Input()
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next>
                            {
                                new Next()
                                {
                                    Action = "ReturnToSequence", ReturnId = "1"
                                }
                            },
                            Active = true
                        }
                    }
                }
            });

            await DataContext.Applications.AddAsync(new Data.Entities.Application()
            {
                Id = ApplicationId, ApplicationData = "{}"
            });

            await DataContext.SaveChangesAsync();
        }
        public void When_PagesWithNotRequired_DoesNotContain_conditions_are_removed(string notRequiredConditionValue, string applicationDataValue, bool toRemove, bool singleValue, string explanation)
        {
            var expectedPagesCount = 2;

            if (toRemove)
            {
                expectedPagesCount = 1;
            }

            var pageIdAlwaysPresent       = "3";
            var pageIdAbsentIfNotRequired = "2";
            var applicationDataJson       = JsonConvert.SerializeObject(new
            {
                FieldToTest = applicationDataValue
            });

            var applicationData    = JObject.Parse(applicationDataJson);
            var doesNotContainList = new string[] { notRequiredConditionValue };

            if (!singleValue)
            {
                doesNotContainList = new string[] { "value1", notRequiredConditionValue, "value2" }
            }
            ;

            var pages = new List <Page>
            {
                new Page
                {
                    PageId = pageIdAbsentIfNotRequired,
                    NotRequiredConditions = new List <NotRequiredCondition>
                    {
                        new NotRequiredCondition()
                        {
                            Field          = "FieldToTest",
                            DoesNotContain = doesNotContainList
                        }
                    },
                    Next = new List <Next>
                    {
                        new Next
                        {
                            Action     = "NextPage",
                            ReturnId   = "12",
                            Conditions = new List <Condition>()
                        },
                        new Next
                        {
                            Action     = "NextPage",
                            ReturnId   = "14",
                            Conditions = new List <Condition>()
                        }
                    }
                },
                new Page
                {
                    PageId = pageIdAlwaysPresent,
                    NotRequiredConditions = null
                }
            };

            var notRequiredProcessor = new NotRequiredProcessor();
            var actualPages          = notRequiredProcessor.PagesWithoutNotRequired(pages, applicationData);

            Assert.AreEqual(actualPages.ToList().Count, expectedPagesCount);
            Assert.IsTrue(actualPages.Any(p => p.PageId == pageIdAlwaysPresent));
            Assert.AreNotEqual(actualPages.Any(p => p.PageId == pageIdAbsentIfNotRequired), toRemove);
        }
    }
        public async Task SetUp()
        {
            DataContext          = DataContextHelpers.GetInMemoryDataContext();
            NotRequiredProcessor = new NotRequiredProcessor();
            TagProcessingService = new TagProcessingService(DataContext);
            var fileStorageConfig = GetFileStorageConfig();

            var encryptionService = Substitute.For <IEncryptionService>();

            encryptionService.Encrypt(Arg.Any <Stream>()).Returns(callinfo => callinfo.ArgAt <Stream>(0)); // Don't Encrypt stream
            encryptionService.Decrypt(Arg.Any <Stream>()).Returns(callinfo => callinfo.ArgAt <Stream>(0)); // Don't Decrypt stream

            var validator = Substitute.For <IAnswerValidator>();

            validator.Validate(Arg.Any <List <Answer> >(), Arg.Any <Page>()).Returns(new List <KeyValuePair <string, string> >());

            var fileContentValidator = Substitute.For <IFileContentValidator>();

            fileContentValidator.Validate(Arg.Any <IFormFileCollection>()).Returns(new List <KeyValuePair <string, string> >());

            Handler = new SubmitPageOfFilesHandler(DataContext, fileStorageConfig, encryptionService, validator, fileContentValidator, NotRequiredProcessor, TagProcessingService);

            ApplicationId = Guid.NewGuid();
            SectionId     = Guid.NewGuid();
            await DataContext.ApplicationSections.AddAsync(new ApplicationSection()
            {
                ApplicationId = ApplicationId,
                Id            = SectionId,
                QnAData       = new QnAData()
                {
                    Pages = new List <Page>
                    {
                        new Page()
                        {
                            PageId    = "1",
                            Questions = new List <Question> {
                                new Question()
                                {
                                    QuestionId = "Q1", Input = new Input {
                                        Type = "FileUpload"
                                    }
                                }
                            },
                            PageOfAnswers = new List <PageOfAnswers>(),
                            Next          = new List <Next> {
                                new Next {
                                }
                            },
                            Active = true
                        }
                    }
                }
            });

            await DataContext.Applications.AddAsync(new Data.Entities.Application()
            {
                Id = ApplicationId, ApplicationData = "{}"
            });

            await DataContext.SaveChangesAsync();
        }