Beispiel #1
0
        protected Action CreateAction(
            string questionId,
            string assignedToId,
            string description            = null,
            System.DateTimeOffset?dueDate = null,
            Priority?priority             = null,
            string title = null)
        {
            if (title == null)
            {
                title = Randomize.String();
            }

            if (description == null)
            {
                description = Randomize.String();
            }

            Action action = _mutation.CreateAction(
                questionId: questionId,
                assignedToId: assignedToId,
                description: description,
                dueDate: dueDate.GetValueOrDefault(System.DateTimeOffset.Now),
                priority: priority.GetValueOrDefault(Randomize.Priority()),
                title: title
                );

            return(action);
        }
Beispiel #2
0
        public void RemoveFromSeveralProjectCategories()
        {
            var projectCategoryService = new ProjectCategoryService(fixture.context);
            var projectCategory1       = projectCategoryService.Create(Randomize.String());
            var projectCategory2       = projectCategoryService.Create(Randomize.String());
            var projectCategoryIds     = new List <string> {
                projectCategory1.Id, projectCategory2.Id
            };

            var service  = new QuestionTemplateService(fixture.context);
            var template = service.GetAll().First();

            service.AddToProjectCategory(template.Id, projectCategory1.Id);
            service.AddToProjectCategory(template.Id, projectCategory2.Id);

            var nActiveFirstCategory  = service.ActiveQuestions(projectCategory1).Count();
            var nActiveSecondCategory = service.ActiveQuestions(projectCategory2).Count();
            var nTemplates            = service.GetAll().Count();

            var updatedQT  = service.RemoveFromProjectCategories(template.Id, projectCategoryIds);
            var updatedPC1 = projectCategoryService.Get(projectCategory1.Id);
            var updatedPC2 = projectCategoryService.Get(projectCategory2.Id);

            Assert.False(updatedQT.ProjectCategories.Contains(updatedPC1));
            Assert.False(updatedQT.ProjectCategories.Contains(updatedPC2));
            Assert.False(updatedPC1.QuestionTemplates.Contains(updatedQT));
            Assert.False(updatedPC2.QuestionTemplates.Contains(updatedQT));

            Assert.Equal(nActiveFirstCategory - 1, service.ActiveQuestions(projectCategory1).Count());
            Assert.Equal(nActiveSecondCategory - 1, service.ActiveQuestions(projectCategory2).Count());
            Assert.Equal(nTemplates, service.GetAll().Count());
        }
Beispiel #3
0
        protected Action EditAction(
            string actionId,
            string assignedToId,
            string description            = null,
            System.DateTimeOffset?dueDate = null,
            Priority?priority             = null,
            string title   = null,
            bool onHold    = false,
            bool completed = false)
        {
            if (title == null)
            {
                title = Randomize.String();
            }

            if (description == null)
            {
                description = Randomize.String();
            }

            Action action = _mutation.EditAction(
                actionId: actionId,
                assignedToId: assignedToId,
                description: description,
                dueDate: dueDate.GetValueOrDefault(System.DateTimeOffset.Now),
                priority: priority.GetValueOrDefault(Randomize.Priority()),
                title: title,
                onHold: onHold,
                completed: completed
                );

            return(action);
        }
Beispiel #4
0
        /* Mutation wrappers with default values */

        protected Evaluation CreateEvaluation(
            string name                 = null,
            string projectId            = null,
            string previousEvaluationId = null,
            string projectCategoryId    = null)
        {
            if (name == null)
            {
                name = Randomize.String();
            }

            if (projectId == null)
            {
                projectId = _project.Id;
            }

            if (previousEvaluationId == null)
            {
                previousEvaluationId = "";
            }

            if (projectCategoryId == null)
            {
                projectCategoryId = _projectCategoryService.GetAll().First().Id;
            }

            Evaluation evaluation = _mutation.CreateEvaluation(
                name:                 name,
                projectId:            projectId,
                previousEvaluationId: previousEvaluationId,
                projectCategoryId:    projectCategoryId
                );

            return(evaluation);
        }
Beispiel #5
0
        public void RemoveFromProjectCategory()
        {
            var projectCategoryService = new ProjectCategoryService(fixture.context);
            var projectCategory        = projectCategoryService.Create(Randomize.String());

            var service  = new QuestionTemplateService(fixture.context);
            var template = service.GetAll().First();

            service.AddToProjectCategory(template.Id, projectCategory.Id);

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

            var updatedQT = service.RemoveFromProjectCategories(template.Id, new List <string> {
                projectCategory.Id
            });
            var updatedPC = projectCategoryService.Get(projectCategory.Id);

            Assert.False(updatedQT.ProjectCategories.Contains(updatedPC));
            Assert.False(updatedPC.QuestionTemplates.Contains(updatedQT));

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

            /* Removing the same QuestionTemplate should fail */
            Assert.Throws <Exception>(() =>
                                      service.RemoveFromProjectCategories(template.Id, new List <string> {
                projectCategory.Id
            })
                                      );
        }
Beispiel #6
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 #7
0
 private void AssertIsNotAuthorized(string azureUniqueId)
 {
     _authService.LoginUser(azureUniqueId);
     Assert.Throws <UnauthorizedAccessException>(() =>
                                                 _mutation.SetSummary(
                                                     evaluationId: _evaluation.Id,
                                                     summary: Randomize.String()
                                                     )
                                                 );
 }
Beispiel #8
0
        public void Create()
        {
            var service = new ProjectCategoryService(fixture.context);

            int nCategories = service.GetAll().Count();

            service.Create(Randomize.String());

            Assert.Equal(nCategories + 1, service.GetAll().Count());
        }
Beispiel #9
0
        public void GetNonExisting()
        {
            var service = new ProjectCategoryService(fixture.context);

            var nonExistingId = Randomize.String();

            Assert.Throws <NotFoundInDBException>(
                () => service.Get(nonExistingId)
                );
        }
Beispiel #10
0
        public void GetExising()
        {
            var service = new ProjectCategoryService(fixture.context);

            var name      = Randomize.String();
            var exisingId = service.Create(name).Id;
            var exists    = service.Get(exisingId);

            Assert.Equal(name, exists.Name);
        }
 private void AssertIsNotAuthorized(string azureUniqueId)
 {
     _authService.LoginUser(azureUniqueId);
     Assert.Throws <UnauthorizedAccessException>(() =>
                                                 CreateClosingRemark(
                                                     actionId: _action.Id,
                                                     text: Randomize.String()
                                                     )
                                                 );
 }
        /* Helper methods */

        private void AssertCanCreate(Participant user)
        {
            _authService.LoginUser(user);
            int notes = NumberOfClosingRemarks(_action);

            CreateClosingRemark(
                actionId: _action.Id,
                text: Randomize.String()
                );
            Assert.True(NumberOfClosingRemarks(_action) == notes + 1);
        }
Beispiel #13
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 #14
0
        public void CopyFrom()
        {
            var service            = new ProjectCategoryService(fixture.context);
            var nProjectCategories = service.GetAll().Count();
            var other      = service.GetAll().First();
            var nTemplates = other.QuestionTemplates.Count();

            var projectCategory = service.CopyFrom(Randomize.String(), other);

            Assert.Equal(nProjectCategories + 1, service.GetAll().Count());
            Assert.Equal(nTemplates, projectCategory.QuestionTemplates.Count());
        }
Beispiel #15
0
        /* Helper methods */

        private void AssertCanSet(Participant user)
        {
            _authService.LoginUser(user);

            string summary = Randomize.String();

            _mutation.SetSummary(
                evaluationId: _evaluation.Id,
                summary: summary
                );

            Assert.True(_evaluation.Summary == summary);
        }
Beispiel #16
0
        protected Note CreateNote(
            string actionId,
            string text = null)
        {
            if (text == null)
            {
                text = Randomize.String();
            }

            Note note = _mutation.CreateNote(
                actionId: actionId,
                text: text
                );

            return(note);
        }
Beispiel #17
0
        protected ClosingRemark CreateClosingRemark(
            string actionId,
            string text = null)
        {
            if (text == null)
            {
                text = Randomize.String();
            }

            ClosingRemark remark = _mutation.CreateClosingRemark(
                actionId: actionId,
                text: text
                );

            return(remark);
        }
Beispiel #18
0
        /* Helper methods */

        private void AssertCanEdit(Participant user)
        {
            _authService.LoginUser(user);
            int    answers     = NumberOfActions(_question);
            string description = _action.Description;
            string actionId    = _action.Id;

            var action = EditAction(
                actionId: actionId,
                assignedToId: Randomize.Value <Participant>(_evaluation.Participants).Id,
                description: Randomize.String()
                );

            Assert.True(NumberOfActions(_question) == answers);
            Assert.True(actionId == action.Id);
            Assert.False(description == action.Description);
        }
Beispiel #19
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);
        }
Beispiel #20
0
        protected Answer SetAnswer(
            string questionId,
            Severity?severity       = null,
            string text             = null,
            Progression?progression = null)
        {
            if (text == null)
            {
                text = Randomize.String();
            }

            Answer answer = _mutation.SetAnswer(
                questionId: questionId,
                severity: severity.GetValueOrDefault(Randomize.Severity()),
                text: text,
                progression: progression.GetValueOrDefault(Randomize.Progression())
                );

            return(answer);
        }
Beispiel #21
0
        public void Delete()
        {
            var service            = new ProjectCategoryService(fixture.context);
            int nCategories        = service.GetAll().Count();
            var oldProjectCategory = service.GetAll().First();
            var newProjectCategory = service.CopyFrom(Randomize.String(), oldProjectCategory);

            var qtService        = new QuestionTemplateService(fixture.context);
            var questionTemplate = qtService
                                   .GetAll()
                                   .Include(x => x.ProjectCategories)
                                   .First(x => x.ProjectCategories.Contains(newProjectCategory))
            ;

            service.Delete(newProjectCategory);

            questionTemplate = qtService.GetQuestionTemplate(questionTemplate.Id);
            Assert.False(questionTemplate.ProjectCategories.Contains(newProjectCategory));

            Assert.Equal(nCategories, service.GetAll().Count());
        }
Beispiel #22
0
        public void CreateAddsCorrectQuestions()
        {
            var projectCategory = _projectCategoryService
                                  .GetAll()
                                  .First()
            ;

            var nActiveTemplates = projectCategory.QuestionTemplates
                                   .Where(x => x.Status.Equals(Status.Active))
                                   .Count()
            ;

            var evaluation = _mutation.CreateEvaluation(
                name: Randomize.String(),
                projectId: _projectService.GetAll().First().Id,
                previousEvaluationId: "",
                projectCategoryId: projectCategory.Id
                );

            Assert.Equal(evaluation.Questions.Count(), nActiveTemplates);
        }
Beispiel #23
0
        public void QuestionsHaveCorrectOrder()
        {
            var projectCategory = _projectCategoryService
                                  .GetAll()
                                  .Where(pc => pc.Name == "SquareField")
                                  .First()
            ;

            var evaluation = _mutation.CreateEvaluation(
                name: Randomize.String(),
                projectId: _projectService.GetAll().First().Id,
                previousEvaluationId: "",
                projectCategoryId: projectCategory.Id
                );

            var createdEvaluation = _evaluationService.GetEvaluation(evaluation.Id);
            int maxQuestionOrder  = createdEvaluation.Questions.Max(q => q.Order);
            var firstQuestion     = createdEvaluation.Questions.OrderBy(q => q.Order).First();

            Assert.Equal(1, firstQuestion.Order);
            Assert.Equal(createdEvaluation.Questions.Count(), maxQuestionOrder);
        }
Beispiel #24
0
        public void DoNotReorderInactiveQuestionTemplate()
        {
            QuestionTemplateService       questionTemplateService = new QuestionTemplateService(fixture.context);
            IQueryable <QuestionTemplate> getAll = questionTemplateService.GetAll();
            // Edit a question template to make sure an inactive question template exists
            var originalQT = getAll.First();
            var updatedQT  = questionTemplateService.Edit(
                questionTemplate: originalQT,
                barrier:          originalQT.Barrier,
                organization:     Randomize.Organization(),
                text:             Randomize.String(),
                supportNotes:     Randomize.String(),
                status:           Status.Active
                );

            var inactiveQuestionTemplate = getAll
                                           .Where(qt => qt.Status == Status.Inactive)
                                           .First()
            ;

            QuestionTemplate resultingQuestionTemplate = questionTemplateService.ReorderQuestionTemplate(inactiveQuestionTemplate);

            Assert.Equal(inactiveQuestionTemplate.Order, resultingQuestionTemplate.Order);
        }
Beispiel #25
0
        public void AddToProjectCategory()
        {
            var projectCategoryService = new ProjectCategoryService(fixture.context);
            var projectCategory        = projectCategoryService.Create(Randomize.String());

            var service    = new QuestionTemplateService(fixture.context);
            var nActive    = service.ActiveQuestions(projectCategory).Count();
            var nTemplates = service.GetAll().Count();
            var template   = service.GetAll().First();

            var updatedQT = service.AddToProjectCategory(template.Id, projectCategory.Id);
            var updatedSP = projectCategoryService.Get(projectCategory.Id);

            Assert.True(updatedQT.ProjectCategories.Contains(updatedSP));
            Assert.True(updatedSP.QuestionTemplates.Contains(updatedQT));

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

            /* Adding the same QuestionTemplate should fail */
            Assert.Throws <Exception>(() =>
                                      service.AddToProjectCategory(template.Id, projectCategory.Id)
                                      );
        }