public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <ICallDispositionService, ICallDispositionRepository>();

            var model = new ApiCallDispositionServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <CallDisposition>())).Returns(Task.FromResult(new CallDisposition()));
            var service = new CallDispositionService(mock.LoggerMock.Object,
                                                     mock.MediatorMock.Object,
                                                     mock.RepositoryMock.Object,
                                                     mock.ModelValidatorMockFactory.CallDispositionModelValidatorMock.Object,
                                                     mock.DALMapperMockFactory.DALCallDispositionMapperMock,
                                                     mock.DALMapperMockFactory.DALCallMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.CallDispositionModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiCallDispositionServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <CallDisposition>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <CallDispositionCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Esempio n. 2
0
        public async void Update_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IVehCapabilityService, IVehCapabilityRepository>();
            var model = new ApiVehCapabilityServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <VehCapability>())).Returns(Task.FromResult(new VehCapability()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new VehCapability()));
            var service = new VehCapabilityService(mock.LoggerMock.Object,
                                                   mock.MediatorMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.VehCapabilityModelValidatorMock.Object,
                                                   mock.DALMapperMockFactory.DALVehCapabilityMapperMock,
                                                   mock.DALMapperMockFactory.DALVehicleCapabilitiesMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.VehCapabilityModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiVehCapabilityServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <VehCapability>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VehCapabilityUpdatedNotification>(), It.IsAny <CancellationToken>()));
        }
Esempio n. 3
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IVehicleService, IVehicleRepository>();
            var model = new ApiVehicleServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new VehicleService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.VehicleModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALVehicleMapperMock,
                                             mock.DALMapperMockFactory.DALVehicleCapabilitiesMapperMock,
                                             mock.DALMapperMockFactory.DALVehicleOfficerMapperMock);

            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.VehicleModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VehicleDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Esempio n. 4
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IVehicleCapabilitiesService, IVehicleCapabilitiesRepository>();
            var model         = new ApiVehicleCapabilitiesServerRequestModel();
            var validatorMock = new Mock <IApiVehicleCapabilitiesServerRequestModelValidator>();

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

            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 <VehicleCapabilitiesDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Esempio n. 5
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IUnitDispositionService, IUnitDispositionRepository>();
            var model         = new ApiUnitDispositionServerRequestModel();
            var validatorMock = new Mock <IApiUnitDispositionServerRequestModelValidator>();

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

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiUnitDispositionServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <UnitDispositionCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Esempio n. 6
0
        public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ICallAssignmentService, ICallAssignmentRepository>();
            var model         = new ApiCallAssignmentServerRequestModel();
            var validatorMock = new Mock <IApiCallAssignmentServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiCallAssignmentServerRequestModel>())).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 CallAssignment()));
            var service = new CallAssignmentService(mock.LoggerMock.Object,
                                                    mock.MediatorMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    validatorMock.Object,
                                                    mock.DALMapperMockFactory.DALCallAssignmentMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiCallAssignmentServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <CallAssignmentUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }