コード例 #1
0
        public async Task AuthenticateAsync_ShouldReturnDto()
        {
            // ARRANGE
            var mockQuery = new Mock <ITeachersQuery>();

            mockQuery
            .Setup(s => s.Authenticate(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(GetTestAuthenticateUser());

            var mockContextFactory = SetupContextFactory(mockQuery.Object);

            _sut = new TeacherUserService(mockContextFactory.Object);
            var userDto = new UserDto {
                Login = "******", Password = "******"
            };

            // ACT
            var actual = await _sut.AuthenticateAsync(userDto);

            userDto.Id    = 1;
            userDto.Name  = "Name1";
            userDto.Roles = new List <string> {
                "Role1"
            };

            //ASSERT
            Assert.Equal(ComparableObject.Convert(userDto), ComparableObject.Convert(actual.Entity));
            Assert.Null(actual.Entity.Password);
        }
コード例 #2
0
        public async Task GetFileByMessageAsync_ShouldReturnDto()
        {
            // ARRANGE
            var expectedFileName = GetTestMessageFiles().First().Name;
            var expectedFileType = GetTestFileTypes().First().Type;
            var expected         = new FileDto {
                FileBytes = new byte[] { 1, 0, 1, 0 }, FileName = expectedFileName, FileType = expectedFileType
            };

            var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >();

            mockFileService
            .Setup(f => f.GetFileBytes(It.IsAny <string>()))
            .Returns(expected.FileBytes);

            var mockContextFactory = SetupContextFactory(null, null, null);

            _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper);

            // ACT
            var actual = await _sut.GetFileByMessageAsync(1);

            // ASSERT
            Assert.Equal(ComparableObject.Convert(expected), ComparableObject.Convert(actual.Entity));
        }
コード例 #3
0
        public void GetFileById_ShouldReturnFileDto()
        {
            // ARRANGE
            var expectedFileName = GetTestUmkFiles().First().FileName;
            var expectedFileType = GetTestFileTypes().First().Type;
            var expected         = new FileDto {
                FileBytes = new byte[] { 1, 0, 1, 0 }, FileName = expectedFileName, FileType = expectedFileType
            };

            var mockFileService = new Mock <IFileService <UmkFilesConfiguration> >();

            mockFileService
            .Setup(f => f.GetFileBytes(It.IsAny <string>()))
            .Returns(expected.FileBytes);

            var mockContextFactory = SetupContextFactory(null, null, null);

            _sut = new UmkFileService(mockContextFactory.Object, _mapper, mockFileService.Object);

            // ACT
            var actual = _sut.GetFileById(1);

            // ASSERT
            Assert.Equal(ComparableObject.Convert(expected), ComparableObject.Convert(actual.Entity));
        }
コード例 #4
0
        public async Task GetBySubjectAndTermAsync_ShouldReturnListToTeacher()
        {
            // ARRANGE
            var expected = new GetBySubjectAndTermResponse(new List <UmkFile>(), "SubjectName1");

            var mockCurriculum = new Mock <ICurriculumQuery>();

            mockCurriculum.Setup(c => c.GetNameById(It.IsAny <int>()))
            .ReturnsAsync(new SPGetName {
                Name = expected.SubjectName
            });

            var mockRaspredelenie = new Mock <IRaspredelenieQuery>();

            mockRaspredelenie.Setup(r => r.CheckTeacherBySubjectAndTerm(It.IsAny <short>(), It.IsAny <int>(), It.IsAny <byte>()))
            .ReturnsAsync(new SPBoolResult {
                Result = true
            });

            var mockContextFactory = SetupContextFactory(null, mockCurriculum.Object, mockRaspredelenie.Object);

            var mockFileService = new Mock <IFileService <UmkFilesConfiguration> >();

            _sut = new UmkFileService(mockContextFactory.Object, _mapper, mockFileService.Object);
            var request = new GetBySubjectAndTermRequest(1, 1);

            // ACT
            var actual = await _sut.GetBySubjectAndTermAsync(request);

            // ASSERT
            Assert.Equal(2, actual.Entity.UmkFiles.Count);
            Assert.Equal(ComparableObject.Convert(expected.SubjectName), ComparableObject.Convert(actual.Entity.SubjectName));
        }
コード例 #5
0
        public async Task GetSeasonsAllAsync_ShouldReturnList()
        {
            // ARRANGE
            var mockContextFactory = SetupContextFactory();

            _sut = new TermService(mockContextFactory.Object);

            // ACT
            var actual = await _sut.GetSeasonsAllAsync();

            // ASSERT
            Assert.Equal(GetTestSeasons().Count, actual.Entity.Count);
            Assert.Equal(ComparableObject.Convert(GetTestSeasons().First()), ComparableObject.Convert(actual.Entity.First()));
        }
コード例 #6
0
        public void GetById_ShouldReturnData()
        {
            var mockContextFactory = SetupContextFactory(null, null, null);

            var mockFileService = new Mock <IFileService <UmkFilesConfiguration> >();

            _sut = new UmkFileService(mockContextFactory.Object, _mapper, mockFileService.Object);
            var expected = GetTestUmkFiles().First();

            expected.FileTypeId = 1;

            // ACT
            var actual = _sut.GetById(1);

            // ASSERT
            Assert.Equal(ComparableObject.Convert(expected), ComparableObject.Convert(actual.Entity));
        }
コード例 #7
0
        public async Task Update_ShouldReturnValue()
        {
            // ARRANGE
            var mockQuery = new Mock <IControlScheduleQuery>();

            mockQuery
            .Setup(tq => tq.Update(
                       It.IsAny <int>(), It.IsAny <short>(), It.IsAny <DateTime>(),
                       It.IsAny <DateTime?>(), It.IsAny <DateTime?>(), It.IsAny <DateTime?>(), It.IsAny <DateTime?>(),
                       It.IsAny <DateTime?>(), It.IsAny <DateTime?>(), It.IsAny <DateTime?>()))
            .ReturnsAsync((int a, short c, DateTime d, DateTime? e, DateTime? f,
                           DateTime? g, DateTime? h, DateTime? i, DateTime? j, DateTime? k) =>
                          new ControlSchedule
            {
                Id            = a,
                YearId        = 1,
                SeasonId      = 1,
                UserId        = c,
                DateStart     = d,
                DateEnd       = e,
                Mod1DateStart = f,
                Mod1DateEnd   = g,
                Mod2DateStart = h,
                Mod2DateEnd   = i,
                ItogDateStart = j,
                ItogDateEnd   = k
            }
                          );
            var mockContextFactory = SetupContextFactory(mockQuery.Object);

            _sut = new ControlScheduleService(mockContextFactory.Object, _mapper);

            var testModel = GetTestControlSchedules().First();
            var dto       = _mapper.Map <ControlScheduleDto>(testModel);

            dto.Year   = GetTestYears().First();
            dto.Season = GetTestSeasons().First();

            // ACT
            var result = await _sut.UpdateAsync(dto);

            // ASSERT
            Assert.Equal(ComparableObject.Convert(dto), ComparableObject.Convert(result.Entity));
        }
コード例 #8
0
        public async Task GetMessageContactsByUserAsync_ShouldReturnList()
        {
            var mockMessagesQuery = new Mock <IMessagesQuery>();

            mockMessagesQuery.Setup(m => m.GetContactsByUser(It.IsAny <int>(), It.IsAny <byte>()))
            .ReturnsAsync(GetTestContactsByUser());

            var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >();

            var mockContextFactory = SetupContextFactory(mockMessagesQuery.Object, null, null);

            _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper);

            // ACT
            var actual = await _sut.GetMessageContactsByUserAsync(1);

            // ASSERT
            Assert.Equal(GetTestContactsByUser().Count, actual.Entity.Count);
            Assert.Equal(ComparableObject.Convert(GetTestContactsByUser().First()), ComparableObject.Convert(actual.Entity.First()));
        }
コード例 #9
0
        public async Task GetRecipientsAsync_ShouldReturnList()
        {
            // ARRANGE
            var mockStudentsQuery = new Mock <IStudentsQuery>();

            mockStudentsQuery
            .Setup(t => t.GetWithSpeciality())
            .ReturnsAsync(GetTestStudents());

            var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >();

            var mockContextFactory = SetupContextFactory(null, null, mockStudentsQuery.Object);

            _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper);

            // ACT
            var actual = await _sut.GetRecipientsAsync();

            // ASSERT
            Assert.Equal(GetTestStudents().Count, actual.Entity.Count);
            Assert.Equal(ComparableObject.Convert(GetTestStudents().First()), ComparableObject.Convert(actual.Entity.First()));
        }
コード例 #10
0
        public async Task GetByIdAsync_ShouldReturnValue()
        {
            // ARRANGE
            var mockQuery = new Mock <IControlScheduleQuery>();

            mockQuery
            .Setup(tq => tq.GetById(It.IsAny <int>()))
            .ReturnsAsync((int id) => GetTestControlSchedules().First(c => c.Id == id));
            var mockContextFactory = SetupContextFactory(mockQuery.Object);

            _sut = new ControlScheduleService(mockContextFactory.Object, _mapper);

            var expectedDto = _mapper.Map <ControlScheduleDto>(GetTestControlSchedules().First());

            expectedDto.Year   = GetTestYears().First();
            expectedDto.Season = GetTestSeasons().First();

            // ACT
            var result = await _sut.GetByIdAsync(1);

            // ASSERT
            Assert.Equal(ComparableObject.Convert(expectedDto), ComparableObject.Convert(result.Entity));
        }
コード例 #11
0
        public async Task GetByYearAndSeasonAsync_ShouldReturnList()
        {
            // ARRANGE
            var mockQuery = new Mock <IControlScheduleQuery>();

            mockQuery
            .Setup(tq => tq.GetByYearAndSeason(
                       It.IsAny <byte>(), It.IsAny <byte>()))
            .ReturnsAsync((byte year, byte season) => GetTestControlSchedules().Where(c => c.YearId == year && c.SeasonId == season).ToList());
            var mockContextFactory = SetupContextFactory(mockQuery.Object);

            _sut = new ControlScheduleService(mockContextFactory.Object, _mapper);

            byte yearId = 1, seasonId = 1;
            var  expectedDtoList = _mapper.Map <List <ControlScheduleListDto> >(GetTestControlSchedules().GetRange(0, 1));

            // ACT
            var result = await _sut.GetByYearAndSeasonAsync(new GetByYearAndSeasonRequest(yearId, seasonId));

            // ASSERT
            Assert.Equal(expectedDtoList.Count, result.Entity.Count);
            Assert.Equal(ComparableObject.Convert(expectedDtoList.First()), ComparableObject.Convert(result.Entity.First()));
        }