Example #1
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IOfficerService, IOfficerRepository>();
            var model         = new ApiOfficerServerRequestModel();
            var validatorMock = new Mock <IApiOfficerServerRequestModelValidator>();

            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 OfficerService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             validatorMock.Object,
                                             mock.DALMapperMockFactory.DALOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALNoteMapperMock,
                                             mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock,
                                             mock.DALMapperMockFactory.DALUnitOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALVehicleOfficerMapperMock);

            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 <OfficerDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Example #2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IOfficerService, IOfficerRepository>();

            var model = new ApiOfficerServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Officer>())).Returns(Task.FromResult(new Officer()));
            var service = new OfficerService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.OfficerModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALNoteMapperMock,
                                             mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock,
                                             mock.DALMapperMockFactory.DALUnitOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALVehicleOfficerMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.OfficerModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiOfficerServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Officer>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <OfficerCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Example #3
0
        public IHttpActionResult Get(int id)
        {
            OfficerService officerService = CreateOfficerService();
            var            officer        = officerService.ReadOfficerById(id);

            return(Ok(officer));
        }
Example #4
0
        private OfficerService CreateOfficerService()
        {
            var userId         = Guid.Parse(User.Identity.GetUserId());
            var officerService = new OfficerService(userId);

            return(officerService);
        }
Example #5
0
        public IHttpActionResult Get()
        {
            OfficerService officerService = CreateOfficerService();
            var            officers       = officerService.ReadOfficers();

            return(Ok(officers));
        }
Example #6
0
        // GET: Officer
        public ActionResult Index()
        {
            var userID  = Guid.Parse(User.Identity.GetUserId());
            var service = new OfficerService(userID);
            var model   = service.GetOfficers();

            return(View(model));
        }
Example #7
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IOfficerService, IOfficerRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Officer>(null));
            var service = new OfficerService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.OfficerModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALNoteMapperMock,
                                             mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock,
                                             mock.DALMapperMockFactory.DALUnitOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALVehicleOfficerMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Example #8
0
        public async void VehicleOfficersByOfficerId_Not_Exists()
        {
            var mock = new ServiceMockFacade <IOfficerService, IOfficerRepository>();

            mock.RepositoryMock.Setup(x => x.VehicleOfficersByOfficerId(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <VehicleOfficer> >(new List <VehicleOfficer>()));
            var service = new OfficerService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.OfficerModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALNoteMapperMock,
                                             mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock,
                                             mock.DALMapperMockFactory.DALUnitOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALVehicleOfficerMapperMock);

            List <ApiVehicleOfficerServerResponseModel> response = await service.VehicleOfficersByOfficerId(default(int));

            response.Should().BeEmpty();
            mock.RepositoryMock.Verify(x => x.VehicleOfficersByOfficerId(default(int), It.IsAny <int>(), It.IsAny <int>()));
        }
Example #9
0
        public async void All_ShouldReturnRecords()
        {
            var mock    = new ServiceMockFacade <IOfficerService, IOfficerRepository>();
            var records = new List <Officer>();

            records.Add(new Officer());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            var service = new OfficerService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.OfficerModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALNoteMapperMock,
                                             mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock,
                                             mock.DALMapperMockFactory.DALUnitOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALVehicleOfficerMapperMock);

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

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }