public void Should_not_create_or_update_service_on_post_put_when_provided_null_post_service()
        {
            //Arrange
            var _serviceRepo       = new Mock <IRepository <ServiceModel> >();
            var _vehicleRepo       = new Mock <IRepository <VehicleModel> >();
            var _serviceValidation = new Mock <IServicesValidation>();

            _controller = new ServicesController(_serviceRepo.Object, _serviceValidation.Object, _vehicleRepo.Object);

            //Act
            var result  = JsonConvert.DeserializeObject <ResultModel>(_controller.Post(null));
            var result1 = JsonConvert.DeserializeObject <ResultModel>(_controller.Put(null));

            //Assert
            Assert.True(result.IsError);
            Assert.True(result1.IsError);
        }
        public async Task Put_ReturnsBadRequest_GivenNull()
        {
            // Arrange
            var mockRepo  = new Mock <IServiceService <Service> >();
            var returning = "invalid";
            var dbMock    = GetService(null, returning);

            mockRepo.Setup(x => x.Put(It.IsAny <int>(), It.IsAny <Service>()))
            .Returns(dbMock);

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.Put(1, new ServiceDTO(1, "Test One", "Description One"));

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
        public async Task Put_ReturnsServiceDTO_GivenServiceDTO()
        {
            // Arrange
            var mockRepo = new Mock <IServiceService <Service> >();
            var dbMock   = GetService(CodeServiceUsersControllerTests.GetListSync());

            mockRepo.Setup(x => x.Put(It.IsAny <int>(), It.IsAny <Service>()))
            .Returns(dbMock).Verifiable();

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.Put(1, new ServiceDTO(1, "Test One", "Description One"));

            // Assert
            mockRepo.VerifyAll();
            var okResult      = Assert.IsType <OkObjectResult>(result);
            var returnService = Assert.IsType <ServiceDTO>(okResult.Value);

            Assert.Equal("Test One", returnService.Name);
        }
        public void Should_not_create_or_update_service_on_post_put_when_provided_invalid_service_vehicle()
        {
            //Arrange
            var _serviceRepo = new Mock <IRepository <ServiceModel> >();
            var _vehicleRepo = new Mock <IRepository <VehicleModel> >();

            var id = Guid.NewGuid();

            _vehicleRepo.Setup(setup => setup.Read()).Returns(new System.Collections.Generic.List <VehicleModel>()
            {
                new VehicleModel()
                {
                    Id = id, VehicleType = VehicleTypeEnum.Diesel
                }
            });

            var post = new PostServiceModel()
            {
                VehicleId   = id,
                ProviderId  = Guid.NewGuid(),
                ServiceType = MaintenanceTypeEnum.BatteryChange,
                Cost        = 12,
                Date        = DateTime.Now,
                Note        = "",
                Odometer    = 0
            };

            _controller = new ServicesController(_serviceRepo.Object, new ServicesValidation(), _vehicleRepo.Object);

            //Act
            var result  = JsonConvert.DeserializeObject <ResultModel>(_controller.Post(post));
            var result1 = JsonConvert.DeserializeObject <ResultModel>(_controller.Put(post.ToServiceModel()));

            //Assert
            Assert.True(result.IsError);
            Assert.True(result1.IsError);
        }