Beispiel #1
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ITeacherSkillService, ITeacherSkillRepository>();
            var model         = new ApiTeacherSkillServerRequestModel();
            var validatorMock = new Mock <IApiTeacherSkillServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiTeacherSkillServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new TeacherSkillService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  validatorMock.Object,
                                                  mock.DALMapperMockFactory.DALTeacherSkillMapperMock,
                                                  mock.DALMapperMockFactory.DALRateMapperMock,
                                                  mock.DALMapperMockFactory.DALTeacherTeacherSkillMapperMock);

            CreateResponse <ApiTeacherSkillServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTeacherSkillServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TeacherSkillCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Beispiel #2
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ITeacherSkillRepository>();
            var model = new ApiTeacherSkillRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TeacherSkill>())).Returns(Task.FromResult(new TeacherSkill()));
            var service = new TeacherSkillService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.TeacherSkillModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLTeacherSkillMapperMock,
                                                  mock.DALMapperMockFactory.DALTeacherSkillMapperMock,
                                                  mock.BOLMapperMockFactory.BOLRateMapperMock,
                                                  mock.DALMapperMockFactory.DALRateMapperMock);

            CreateResponse <ApiTeacherSkillResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.TeacherSkillModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTeacherSkillRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TeacherSkill>()));
        }
Beispiel #3
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <ITeacherSkillService, ITeacherSkillRepository>();

            var model = new ApiTeacherSkillServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TeacherSkill>())).Returns(Task.FromResult(new TeacherSkill()));
            var service = new TeacherSkillService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.TeacherSkillModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALTeacherSkillMapperMock,
                                                  mock.DALMapperMockFactory.DALRateMapperMock,
                                                  mock.DALMapperMockFactory.DALTeacherTeacherSkillMapperMock);

            CreateResponse <ApiTeacherSkillServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.TeacherSkillModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTeacherSkillServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TeacherSkill>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TeacherSkillCreatedNotification>(), It.IsAny <CancellationToken>()));
        }