Example #1
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IEventTeacherService, IEventTeacherRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <EventTeacher>(null));
            var service = new EventTeacherService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.EventTeacherModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALEventTeacherMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Example #2
0
        public async void ByEventId_Not_Exists()
        {
            var mock = new ServiceMockFacade <IEventTeacherService, IEventTeacherRepository>();

            mock.RepositoryMock.Setup(x => x.ByEventId(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <EventTeacher> >(new List <EventTeacher>()));
            var service = new EventTeacherService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.EventTeacherModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALEventTeacherMapperMock);

            List <ApiEventTeacherServerResponseModel> response = await service.ByEventId(default(int));

            response.Should().BeEmpty();
            mock.RepositoryMock.Verify(x => x.ByEventId(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()));
        }
Example #3
0
        public async void All_ShouldReturnRecords()
        {
            var mock    = new ServiceMockFacade <IEventTeacherService, IEventTeacherRepository>();
            var records = new List <EventTeacher>();

            records.Add(new EventTeacher());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            var service = new EventTeacherService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.EventTeacherModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALEventTeacherMapperMock);

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

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Example #4
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IEventTeacherService, IEventTeacherRepository>();
            var model = new ApiEventTeacherServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new EventTeacherService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.EventTeacherModelValidatorMock.Object,
                                                  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.EventTeacherModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <EventTeacherDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
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());
        }