コード例 #1
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IOfficerCapabilitiesService, IOfficerCapabilitiesRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <OfficerCapabilities>(null));
            var service = new OfficerCapabilitiesService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.OfficerCapabilitiesModelValidatorMock.Object,
                                                         mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
コード例 #2
0
        public async void All_ShouldReturnRecords()
        {
            var mock    = new ServiceMockFacade <IOfficerCapabilitiesService, IOfficerCapabilitiesRepository>();
            var records = new List <OfficerCapabilities>();

            records.Add(new OfficerCapabilities());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            var service = new OfficerCapabilitiesService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.OfficerCapabilitiesModelValidatorMock.Object,
                                                         mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock);

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

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
コード例 #3
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IOfficerCapabilitiesService, IOfficerCapabilitiesRepository>();
            var model = new ApiOfficerCapabilitiesServerRequestModel();

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

            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.OfficerCapabilitiesModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <OfficerCapabilitiesDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
コード例 #4
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IOfficerCapabilitiesService, IOfficerCapabilitiesRepository>();
            var model         = new ApiOfficerCapabilitiesServerRequestModel();
            var validatorMock = new Mock <IApiOfficerCapabilitiesServerRequestModelValidator>();

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

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