Example #1
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IEventService, IEventRepository>();
            var model = new ApiEventServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new EventService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.EventModelValidatorMock.Object,
                                           mock.DALMapperMockFactory.DALEventMapperMock,
                                           mock.DALMapperMockFactory.DALEventStudentMapperMock,
                                           mock.DALMapperMockFactory.DALEventTeacherMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.EventModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <EventDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Example #2
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IUserRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <User>(null));
            var service = new UserService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.UserModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLUserMapperMock,
                                          mock.DALMapperMockFactory.DALUserMapperMock,
                                          mock.BOLMapperMockFactory.BOLAdminMapperMock,
                                          mock.DALMapperMockFactory.DALAdminMapperMock,
                                          mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                          mock.DALMapperMockFactory.DALStudentMapperMock,
                                          mock.BOLMapperMockFactory.BOLTeacherMapperMock,
                                          mock.DALMapperMockFactory.DALTeacherMapperMock);

            ApiUserResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Example #3
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <ISpaceFeatureService, ISpaceFeatureRepository>();

            var model = new ApiSpaceFeatureServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SpaceFeature>())).Returns(Task.FromResult(new SpaceFeature()));
            var service = new SpaceFeatureService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.SpaceFeatureModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALSpaceFeatureMapperMock,
                                                  mock.DALMapperMockFactory.DALSpaceSpaceFeatureMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.SpaceFeatureModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSpaceFeatureServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SpaceFeature>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SpaceFeatureCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Example #4
0
        public async void TeachersByUserId_Not_Exists()
        {
            var mock = new ServiceMockFacade <IUserRepository>();

            mock.RepositoryMock.Setup(x => x.TeachersByUserId(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <Teacher> >(new List <Teacher>()));
            var service = new UserService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.UserModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLUserMapperMock,
                                          mock.DALMapperMockFactory.DALUserMapperMock,
                                          mock.BOLMapperMockFactory.BOLAdminMapperMock,
                                          mock.DALMapperMockFactory.DALAdminMapperMock,
                                          mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                          mock.DALMapperMockFactory.DALStudentMapperMock,
                                          mock.BOLMapperMockFactory.BOLTeacherMapperMock,
                                          mock.DALMapperMockFactory.DALTeacherMapperMock);

            List <ApiTeacherResponseModel> response = await service.TeachersByUserId(default(int));

            response.Should().BeEmpty();
            mock.RepositoryMock.Verify(x => x.TeachersByUserId(default(int), It.IsAny <int>(), It.IsAny <int>()));
        }
Example #5
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IEventTeacherService, IEventTeacherRepository>();
            var model         = new ApiEventTeacherServerRequestModel();
            var validatorMock = new Mock <IApiEventTeacherServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new EventTeacherService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  validatorMock.Object,
                                                  mock.DALMapperMockFactory.DALEventTeacherMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <EventTeacherDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Example #6
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IStudioService, IStudioRepository>();
            var model         = new ApiStudioServerRequestModel();
            var validatorMock = new Mock <IApiStudioServerRequestModelValidator>();

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

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiStudioServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <StudioCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Example #7
0
        public async void Update_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()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).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);

            UpdateResponse <ApiTeacherSkillServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.TeacherSkillModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiTeacherSkillServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <TeacherSkill>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TeacherSkillUpdatedNotification>(), It.IsAny <CancellationToken>()));
        }
Example #8
0
        public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ITeacherTeacherSkillService, ITeacherTeacherSkillRepository>();
            var model         = new ApiTeacherTeacherSkillServerRequestModel();
            var validatorMock = new Mock <IApiTeacherTeacherSkillServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiTeacherTeacherSkillServerRequestModel>())).Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new TeacherTeacherSkill()));
            var service = new TeacherTeacherSkillService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         validatorMock.Object,
                                                         mock.DALMapperMockFactory.DALTeacherTeacherSkillMapperMock);

            UpdateResponse <ApiTeacherTeacherSkillServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiTeacherTeacherSkillServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TeacherTeacherSkillUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Example #9
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IUserRepository>();
            var model = new ApiUserRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <User>())).Returns(Task.FromResult(new User()));
            var service = new UserService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.UserModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLUserMapperMock,
                                          mock.DALMapperMockFactory.DALUserMapperMock,
                                          mock.BOLMapperMockFactory.BOLAdminMapperMock,
                                          mock.DALMapperMockFactory.DALAdminMapperMock,
                                          mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                          mock.DALMapperMockFactory.DALStudentMapperMock,
                                          mock.BOLMapperMockFactory.BOLTeacherMapperMock,
                                          mock.DALMapperMockFactory.DALTeacherMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.UserModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiUserRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <User>()));
        }
Example #10
0
        public async void All()
        {
            var mock    = new ServiceMockFacade <IUserRepository>();
            var records = new List <User>();

            records.Add(new User());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            var service = new UserService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.UserModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLUserMapperMock,
                                          mock.DALMapperMockFactory.DALUserMapperMock,
                                          mock.BOLMapperMockFactory.BOLAdminMapperMock,
                                          mock.DALMapperMockFactory.DALAdminMapperMock,
                                          mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                          mock.DALMapperMockFactory.DALStudentMapperMock,
                                          mock.BOLMapperMockFactory.BOLTeacherMapperMock,
                                          mock.DALMapperMockFactory.DALTeacherMapperMock);

            List <ApiUserResponseModel> response = await service.All();

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Example #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IUserRepository>();
            var model = new ApiUserRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new UserService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.UserModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLUserMapperMock,
                                          mock.DALMapperMockFactory.DALUserMapperMock,
                                          mock.BOLMapperMockFactory.BOLAdminMapperMock,
                                          mock.DALMapperMockFactory.DALAdminMapperMock,
                                          mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                          mock.DALMapperMockFactory.DALStudentMapperMock,
                                          mock.BOLMapperMockFactory.BOLTeacherMapperMock,
                                          mock.DALMapperMockFactory.DALTeacherMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.UserModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }