public async Task SetUp() { ApplicationId = Guid.NewGuid(); SectionId = Guid.NewGuid(); PageId = Guid.NewGuid().ToString(); var dataContext = DataContextHelpers.GetInMemoryDataContext(); dataContext.Applications.Add(new Data.Entities.Application() { Id = ApplicationId, }); dataContext.ApplicationSections.Add(new ApplicationSection() { Id = SectionId, ApplicationId = ApplicationId, QnAData = new QnAData() { Pages = new List <Page> { new Page { PageId = PageId } } } }); dataContext.SaveChanges(); Handler = new GetPageHandler(dataContext); }
public async Task Then_ApplicationDataSchema_is_copied_from_Project_to_Workflow() { var inMemoryDataContext = DataContextHelpers.GetInMemoryDataContext(); var projectId = Guid.NewGuid(); var project = new Project { ApplicationDataSchema = "schema{}", Id = projectId }; await inMemoryDataContext.Projects.AddAsync(project); await inMemoryDataContext.SaveChangesAsync(); var createWorkflowHandler = new CreateWorkflowHandler(inMemoryDataContext); await createWorkflowHandler.Handle(new CreateWorkflowRequest(projectId, new Workflow() { ProjectId = projectId, Description = "Desc", Version = "1" }), CancellationToken.None); var savedWorkflow = await inMemoryDataContext.Workflows.SingleOrDefaultAsync(); savedWorkflow.Should().NotBeNull(); savedWorkflow.ApplicationDataSchema.Should().Be(project.ApplicationDataSchema); }
public async Task SetUp() { QnaDataContext = DataContextHelpers.GetInMemoryDataContext(); NotRequiredProcessor = new NotRequiredProcessor(); TagProcessingService = new TagProcessingService(QnaDataContext); SetAnswersBase = new SetAnswersBase(QnaDataContext, NotRequiredProcessor, TagProcessingService, null); ApplicationId = Guid.NewGuid(); ApplicationDataJson = JsonConvert.SerializeObject(new { OrgType = "OrgType1" }); await QnaDataContext.Applications.AddAsync(new Data.Entities.Application { Id = ApplicationId, ApplicationData = ApplicationDataJson }); await QnaDataContext.SaveChangesAsync(); NextAction = new Next { Action = "NextPage", ReturnId = "2" }; }
public async Task Then_feedback_entry_is_inserted() { var createdDateTime = new DateTime(2018, 2, 3); SystemTime.UtcNow = () => createdDateTime; var dataContext = DataContextHelpers.GetInMemoryDataContext(); var applicationId = Guid.NewGuid(); var sectionId = Guid.NewGuid(); var section = new ApplicationSection { ApplicationId = applicationId, Id = sectionId, QnAData = new QnAData { Pages = new List <Page> { new Page { PageId = "1" } } } }; await dataContext.ApplicationSections.AddAsync(section); await dataContext.SaveChangesAsync(); var handler = new UpsertFeedbackHandler(dataContext); var newFeedbackId = Guid.NewGuid(); await handler.Handle(new UpsertFeedbackRequest(applicationId, sectionId, "1", new Feedback { Date = DateTime.UtcNow, From = "Dave", Id = newFeedbackId, Message = "Feedback message" }), CancellationToken.None); var updatedSection = await dataContext.ApplicationSections.SingleAsync(); var updatedPage = updatedSection.QnAData.Pages[0]; updatedPage.Feedback.Should().NotBeNullOrEmpty(); updatedPage.Feedback.Count.Should().Be(1); var insertedFeedback = updatedPage.Feedback[0]; insertedFeedback.Date.Should().Be(createdDateTime); insertedFeedback.From.Should().Be("Dave"); insertedFeedback.Id.Should().Be(newFeedbackId); insertedFeedback.Message.Should().Be("Feedback message"); insertedFeedback.IsNew.Should().BeTrue(); insertedFeedback.IsCompleted.Should().BeFalse(); }
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); }
public async Task Then_Workflow_is_inserted_into_database() { var inMemoryDataContext = DataContextHelpers.GetInMemoryDataContext(); var upsertWorkflowHandler = new UpsertWorkflowHandler(inMemoryDataContext); var projectId = Guid.NewGuid(); var workflowId = Guid.NewGuid(); await upsertWorkflowHandler.Handle(new UpsertWorkflowRequest(projectId, Guid.Empty, new Workflow { Id = workflowId }), CancellationToken.None); var createdWorkflow = await inMemoryDataContext.Workflows.SingleOrDefaultAsync(w => w.Id == workflowId); createdWorkflow.Should().NotBeNull(); createdWorkflow.Id.Should().Be(workflowId); createdWorkflow.ProjectId.Should().Be(projectId); }
public async Task SetUp() { ApplicationId = Guid.NewGuid(); SequenceNo = 1; SectionNo = 1; ActivePageId = Guid.NewGuid().ToString(); InactivePageId = Guid.NewGuid().ToString(); var dataContext = DataContextHelpers.GetInMemoryDataContext(); dataContext.Applications.Add(new Data.Entities.Application() { Id = ApplicationId, }); dataContext.ApplicationSections.Add(new ApplicationSection() { SectionNo = SectionNo, SequenceNo = SequenceNo, ApplicationId = ApplicationId, QnAData = new QnAData() { Pages = new List <Page> { new Page { PageId = ActivePageId, Active = true }, new Page { PageId = InactivePageId, Active = false }, } } }); dataContext.SaveChanges(); Handler = new CanUpdatePageBySectionNoHandler(dataContext); }
public async Task SetUp() { _dataContext = DataContextHelpers.GetInMemoryDataContext(); _applicationId = Guid.NewGuid(); _sectionId = Guid.NewGuid(); _feedbackId = Guid.NewGuid(); var section = new ApplicationSection { ApplicationId = _applicationId, Id = _sectionId, QnAData = new QnAData { Pages = new List <Page> { new Page { PageId = "1", Feedback = new List <Feedback> { new Feedback { Id = _feedbackId } } } } } }; await _dataContext.ApplicationSections.AddAsync(section); await _dataContext.SaveChangesAsync(); _handler = new UpsertFeedbackHandler(_dataContext); }
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 async Task SetUp() { DataContext = DataContextHelpers.GetInMemoryDataContext(); var applicationDataValidator = Substitute.For <IApplicationDataValidator>(); applicationDataValidator.IsValid("", "").ReturnsForAnyArgs(true); var logger = Substitute.For <ILogger <StartApplicationHandler> >(); Handler = new StartApplicationHandler(DataContext, applicationDataValidator, logger); WorkflowId = Guid.NewGuid(); var projectId = Guid.NewGuid(); await DataContext.Workflows.AddAsync( new Workflow() { Type = "EPAO", Status = WorkflowStatus.Live, Id = WorkflowId, ProjectId = projectId }); var workflowSections = new[] { new WorkflowSection { Id = Guid.NewGuid(), Title = "Section 1", QnAData = new QnAData() { Pages = new List <Page>() { new Page() { Title = "[PageTitleToken1]" }, new Page() { Title = "[PageTitleToken2]" } } } }, new WorkflowSection { Id = Guid.NewGuid(), Title = "Section 2", QnAData = new QnAData() { Pages = new List <Page>() } }, new WorkflowSection { Id = Guid.NewGuid(), Title = "Section 3", QnAData = new QnAData() { Pages = new List <Page>() } }, new WorkflowSection { Id = Guid.NewGuid(), Title = "Section 4", QnAData = new QnAData() { Pages = new List <Page>() } }, new WorkflowSection { Id = Guid.NewGuid(), Title = "Invalid section", QnAData = new QnAData() { Pages = new List <Page>() } } }; await DataContext.WorkflowSections.AddRangeAsync(workflowSections); await DataContext.WorkflowSequences.AddRangeAsync(new[] { new WorkflowSequence { WorkflowId = WorkflowId, SectionId = workflowSections[0].Id, SectionNo = 1, SequenceNo = 1, IsActive = true }, new WorkflowSequence { WorkflowId = WorkflowId, SectionId = workflowSections[1].Id, SectionNo = 2, SequenceNo = 1, IsActive = true }, new WorkflowSequence { WorkflowId = WorkflowId, SectionId = workflowSections[2].Id, SectionNo = 3, SequenceNo = 1, IsActive = true }, new WorkflowSequence { WorkflowId = WorkflowId, SectionId = workflowSections[3].Id, SectionNo = 4, SequenceNo = 2, IsActive = false }, new WorkflowSequence { WorkflowId = Guid.NewGuid() }, new WorkflowSequence { WorkflowId = Guid.NewGuid() }, }); await DataContext.Projects.AddAsync(new Project { Id = projectId, ApplicationDataSchema = "" }); await DataContext.SaveChangesAsync(); }
public async Task SetUp() { DataContext = DataContextHelpers.GetInMemoryDataContext(); Handler = new ResetPageAnswersHandler(DataContext, new NotRequiredProcessor(), new TagProcessingService(DataContext)); GetApplicationDataHandler = new GetApplicationDataHandler(DataContext); GetPageHandler = new GetPageHandler(DataContext); 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", QuestionTag = "Q1", Input = new Input() } }, PageOfAnswers = new List <PageOfAnswers> { new PageOfAnswers { Answers = new List <Answer> { new Answer { QuestionId = "Q1", Value = "Yes" } } } }, 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 = "3", Conditions = new List <Condition>() { new Condition { QuestionId = "Q1", MustEqual = "No" } } } }, Feedback = new List <Feedback> { new Feedback { IsCompleted = true } }, Active = true, Complete = 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 = "ReturnToSequence", Conditions = new List <Condition>() }, }, Active = true, 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 = "ReturnToSequence", Conditions = new List <Condition>() } }, Active = false, ActivatedByPageId = "1" } } } }); await DataContext.Applications.AddAsync(new Data.Entities.Application() { Id = ApplicationId, ApplicationData = "{ \"Q1\" : \"Yes\" }" }); await DataContext.SaveChangesAsync(); }
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(); }
public async Task SetUp() { DataContext = DataContextHelpers.GetInMemoryDataContext(); var fileStorageConfig = GetFileStorageConfig(); var logger = Substitute.For <ILogger <CreateSnapshotHandler> >(); Handler = new CreateSnapshotHandler(DataContext, fileStorageConfig, logger); ApplicationId = Guid.NewGuid(); SequenceId = Guid.NewGuid(); SectionId = Guid.NewGuid(); PageId = "1"; QuestionId = "Q1"; Filename = "file.txt"; Container = await GetContainer(fileStorageConfig); await DataContext.Applications.AddAsync(new Data.Entities.Application() { Id = ApplicationId, ApplicationData = "{}" }); await DataContext.ApplicationSequences.AddAsync(new ApplicationSequence() { ApplicationId = ApplicationId, Id = SequenceId }); await DataContext.ApplicationSections.AddAsync(new ApplicationSection() { ApplicationId = ApplicationId, Id = SectionId, SequenceId = SequenceId, QnAData = new QnAData() { Pages = new List <Page> { new Page() { SectionId = SectionId, SequenceId = SequenceId, PageId = PageId, Questions = new List <Question> { new Question() { QuestionId = QuestionId, Input = new Input { Type = "FileUpload" } } }, PageOfAnswers = new List <PageOfAnswers>() { new PageOfAnswers { Id = Guid.NewGuid(), Answers = new List <Answer> { new Answer { QuestionId = QuestionId, Value = Filename } } } }, Next = new List <Next>(), Active = true } } } }); await DataContext.SaveChangesAsync(); await AddFile(ApplicationId, SequenceId, SectionId, PageId, QuestionId, Filename, Container); }