コード例 #1
0
        public async Task AllowCreateSignatureIfValid()
        {
            var assignmentId = 1;
            var planId       = 1;
            var patrolId     = 1;
            var sectionId    = 1;
            var userId       = 1;


            _assignmentRepositoryMock.Setup(x => x.GetAssignment(assignmentId))
            .Returns(Task.FromResult(new Assignment()
            {
                Id          = assignmentId,
                PlanId      = planId,
                CompletedAt = DateTime.UtcNow
            })).Verifiable();

            int sectionSkillId = 5;
            int sectionLevelId = 6;

            _planRepositoryMock.Setup(x => x.GetPlan(planId)).Returns(Task.FromResult(new Plan()
            {
                Id       = planId,
                Name     = "Name",
                PatrolId = patrolId
            }));

            _planRepositoryMock.Setup(x => x.GetSectionsForPlan(planId)).Returns(Task.FromResult((new List <Section>()
            {
                new Section()
                {
                    Id = sectionId,
                    PatrolId = patrolId,
                    Name = "Name"
                }
            }).AsEnumerable()));

            _planRepositoryMock.Setup(x => x.GetSectionLevelsForPlan(planId)).Returns(Task.FromResult((new List <SectionLevelDto>()
            {
                new SectionLevelDto()
                {
                    Id = sectionLevelId,
                    ColumnIndex = 0,
                    SectionId = sectionId
                }
            }).AsEnumerable()));

            _planRepositoryMock.Setup(x => x.GetSectionSkillsForPlan(planId)).Returns(Task.FromResult((new List <SectionSkillDto>()
            {
                new SectionSkillDto()
                {
                    Id = sectionSkillId,
                    RowIndex = 0,
                    SectionId = sectionId
                }
            }).AsEnumerable()));

            _groupRepositoryMock.Setup(x => x.GetSectionIdsInPlanThatUserCanSign(userId, planId))
            .Returns(Task.FromResult((new List <int>()
            {
                sectionId
            }).AsEnumerable()));

            _patrolRepository.Setup(x => x.GetPatrolsForUser(userId))
            .Returns(Task.FromResult((new List <CurrentUserPatrolDto>()
            {
                new CurrentUserPatrolDto()
                {
                    Id = patrolId,
                    Name = "Patrol"
                }
            }).AsEnumerable()));


            var result = await _assignmentService.AllowCreateSignatures(assignmentId, 1, new List <NewSignatureDto>() { new NewSignatureDto()
                                                                                                                        {
                                                                                                                            SectionLevelId = sectionLevelId, SectionSkillId = sectionSkillId
                                                                                                                        } });

            _assignmentRepositoryMock.Verify();
            Assert.True(result);
        }