Beispiel #1
0
        public void Create()
        {
            QuestionTemplateService questionTemplateService = new QuestionTemplateService(fixture.context);
            Barrier barrier         = Randomize.Barrier();
            int     maxBarrierOrder = questionTemplateService.GetAll()
                                      .Where(qt => qt.Status == Status.Active)
                                      .Where(qt => qt.Barrier == barrier)
                                      .Max(qt => qt.Order)
            ;
            int maxAdminOrder = questionTemplateService.GetAll()
                                .Where(qt => qt.Status == Status.Active)
                                .Max(qt => qt.AdminOrder)
            ;

            int nQuestionTemplatesBefore = questionTemplateService.GetAll().Count();
            int maxOrderBefore           = questionTemplateService.GetAll().Where(qt => qt.Status == Status.Active).Max(qt => qt.Order);

            var newQuestionTemplate = questionTemplateService.Create(barrier, Organization.All, "text", "supportNotes");

            int nQuestionTemplatesAfter = questionTemplateService.GetAll().Count();
            int maxOrderAfter           = questionTemplateService.GetAll().Where(qt => qt.Status == Status.Active).Max(qt => qt.Order);

            Assert.Equal(nQuestionTemplatesBefore + 1, nQuestionTemplatesAfter);
            Assert.Equal(maxBarrierOrder + 1, newQuestionTemplate.Order);
            Assert.Equal(maxOrderBefore + 1, maxOrderAfter);
            Assert.Equal(maxAdminOrder + 1, newQuestionTemplate.AdminOrder);
        }
Beispiel #2
0
        public void CopyUsingCreate()
        {
            var service = new QuestionTemplateService(fixture.context);
            var questionTemplateToCopy = service.Create(
                barrier:      Randomize.Barrier(),
                organization: Randomize.Organization(),
                text:         Randomize.String(),
                supportNotes: Randomize.String()
                );
            int maxAdminOrder = service.GetAll()
                                .Where(qt => qt.Status == Status.Active)
                                .Max(qt => qt.AdminOrder)
            ;

            var newQuestionTemplate = service.Create(
                barrier:      questionTemplateToCopy.Barrier,
                organization: questionTemplateToCopy.Organization,
                text:         questionTemplateToCopy.Text,
                supportNotes: questionTemplateToCopy.SupportNotes,
                newOrder:     questionTemplateToCopy.Order + 1
                );

            Assert.Equal(questionTemplateToCopy.Order + 1, newQuestionTemplate.Order);
            Assert.Equal(maxAdminOrder + 1, newQuestionTemplate.AdminOrder);
        }
Beispiel #3
0
        public void DeleteQuestionTemplate()
        {
            var     service = new QuestionTemplateService(fixture.context);
            Barrier barrier = Randomize.Barrier();
            var     questionTemplateToDelete = service.Create(
                barrier:      barrier,
                organization: Randomize.Organization(),
                text:         Randomize.String(),
                supportNotes: Randomize.String()
                );

            var projectCategory = new ProjectCategoryService(fixture.context).GetAll().First();

            questionTemplateToDelete = service.AddToProjectCategory(questionTemplateToDelete.Id, projectCategory.Id);

            int maxOrderActive = service.GetAll()
                                 .Where(qt => qt.Status == Status.Active)
                                 .Max(qt => qt.Order)
            ;
            int maxBarrierOrder = service.GetAll()
                                  .Where(qt => qt.Status == Status.Active)
                                  .Where(qt => qt.Barrier == barrier)
                                  .Max(qt => qt.Order)
            ;
            int maxAdminOrder = service.GetAll()
                                .Where(qt => qt.Status == Status.Active)
                                .Max(qt => qt.AdminOrder)
            ;

            var deletedQuestionTemplate = service.Delete(questionTemplateToDelete);

            int maxOrderActiveAfter = service.GetAll()
                                      .Where(qt => qt.Status == Status.Active)
                                      .Max(qt => qt.Order)
            ;
            int maxBarrierOrderAfter = service.GetAll()
                                       .Where(qt => qt.Status == Status.Active)
                                       .Where(qt => qt.Barrier == barrier)
                                       .Max(qt => qt.Order)
            ;
            int maxAdminOrderAfter = service.GetAll()
                                     .Where(qt => qt.Status == Status.Active)
                                     .Max(qt => qt.AdminOrder)
            ;

            int maxOrder = fixture.context.QuestionTemplates.Max(qt => qt.Order);

            Assert.Equal(maxOrderActive - 1, maxOrderActiveAfter);
            Assert.Equal(maxBarrierOrder - 1, maxBarrierOrderAfter);
            Assert.Equal(maxAdminOrder - 1, maxAdminOrderAfter);
            Assert.Equal(deletedQuestionTemplate.Order, maxOrder);
            Assert.True(deletedQuestionTemplate.Status == Status.Voided);
            Assert.Equal(deletedQuestionTemplate.ProjectCategories, questionTemplateToDelete.ProjectCategories);
        }
Beispiel #4
0
        public void EditQuestionTemplate()
        {
            var     service    = new QuestionTemplateService(fixture.context);
            Barrier barrier    = Randomize.Barrier();
            var     originalQT = service.Create(
                barrier:      barrier,
                organization: Randomize.Organization(),
                text:         Randomize.String(),
                supportNotes: Randomize.String()
                );

            var projectCategory = new ProjectCategoryService(fixture.context).GetAll().First();

            originalQT = service.AddToProjectCategory(originalQT.Id, projectCategory.Id);

            var nTemplates = service.GetAll().Count();
            var nActive    = service.ActiveQuestions(projectCategory).Count();

            var newText         = Randomize.String();
            var newSupportNotes = Randomize.String();
            var newOrganization = Randomize.Organization();

            var updatedQT = service.Edit(
                questionTemplate: originalQT,
                barrier:          barrier,
                organization:     newOrganization,
                text:             newText,
                supportNotes:     newSupportNotes,
                status:           Status.Active
                );

            Assert.Equal(nTemplates + 1, service.GetAll().Count());
            Assert.Equal(nActive, service.ActiveQuestions(projectCategory).Count());

            Assert.Equal(newText, updatedQT.Text);
            Assert.Equal(newSupportNotes, updatedQT.SupportNotes);
            Assert.Equal(barrier, updatedQT.Barrier);
            Assert.Equal(newOrganization, updatedQT.Organization);

            Assert.Equal(originalQT, updatedQT.previous);
            Assert.True(updatedQT.ProjectCategories.Count() == 1);

            Assert.Equal(updatedQT.AdminOrder, originalQT.AdminOrder);
        }