コード例 #1
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IAirTransportRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <AirTransport>(null));
            var service = new AirTransportService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.AirTransportModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLAirTransportMapperMock,
                                                  mock.DALMapperMockFactory.DALAirTransportMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
コード例 #2
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IAirTransportRepository>();
            var model = new ApiAirTransportRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <AirTransport>())).Returns(Task.FromResult(new AirTransport()));
            var service = new AirTransportService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.AirTransportModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLAirTransportMapperMock,
                                                  mock.DALMapperMockFactory.DALAirTransportMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.AirTransportModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiAirTransportRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <AirTransport>()));
        }
コード例 #3
0
        public async void All()
        {
            var mock    = new ServiceMockFacade <IAirTransportRepository>();
            var records = new List <AirTransport>();

            records.Add(new AirTransport());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            var service = new AirTransportService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.AirTransportModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLAirTransportMapperMock,
                                                  mock.DALMapperMockFactory.DALAirTransportMapperMock);

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

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
コード例 #4
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IAirTransportRepository>();
            var model = new ApiAirTransportRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new AirTransportService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.AirTransportModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLAirTransportMapperMock,
                                                  mock.DALMapperMockFactory.DALAirTransportMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.AirTransportModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
コード例 #5
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IAirTransportService, IAirTransportRepository>();
            var model = new ApiAirTransportServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new AirTransportService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.AirTransportModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALAirTransportMapperMock);

            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.AirTransportModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <AirTransportDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
コード例 #6
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IAirTransportService, IAirTransportRepository>();
            var model         = new ApiAirTransportServerRequestModel();
            var validatorMock = new Mock <IApiAirTransportServerRequestModelValidator>();

            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 AirTransportService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  validatorMock.Object,
                                                  mock.DALMapperMockFactory.DALAirTransportMapperMock);

            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 <AirTransportDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }