private void TestDetailsGET()
        {
            // Arrange
            var id    = Guid.Empty;
            var car   = GetCar();
            var model = GetCarDetailsViewModel(car);

            MockCarData
            .Setup(_ => _.GetById(id))
            .ReturnsAsync(car);
            MockMapper
            .Setup(_ => _.Map <CarDetailsViewModel>(car))
            .Returns(model);

            // Act
            dynamic response = ControllerUnderTest.Details(id);

            // Assert
            MockCarData.Verify(_ => _.GetById(id), Times.Once);
            MockMapper.Verify(_ => _.Map <CarDetailsViewModel>(car), Times.Once);

            Assert.True(response.Model.Id.Equals(model.Id));
            Assert.True(response.Model.Brand.Equals(model.Brand));
            Assert.True(response.Model.Model.Equals(model.Model));
            Assert.True(response.Model.VIN.Equals(model.VIN));
        }
Exemplo n.º 2
0
        public async void CarsService_GetAll_NoCars()
        {
            // Arrange
            var mockCar           = MockCarData.GetEmptyEntityListAsync();
            var mockCarRepo       = new MockCarRepository().MockGetAll(mockCar);
            var mockCarLoggerRepo = new MockLoggerRepository <CarsService>();
            var mockCarsService   = new CarsService(mockCarRepo.Object, mockCarLoggerRepo.Object);

            // Act
            var cars = await mockCarsService.GetCars();

            // Assert
            Assert.Empty(cars);
            mockCarRepo.VerifyGetAllForCar(Times.Once());
        }
Exemplo n.º 3
0
        public async void CarsService_GetById_ValidId()
        {
            // Arrange
            var mockId            = 2;
            var mockCar           = MockCarData.GetSingleEntityAsync();
            var mockCarRepo       = new MockCarRepository().MockGetById(mockCar);
            var mockCarLoggerRepo = new MockLoggerRepository <CarsService>();
            var mockCarsService   = new CarsService(mockCarRepo.Object, mockCarLoggerRepo.Object);

            // Act
            var cars = await mockCarsService.GetCar(mockId);

            // Assert
            Assert.Equal(mockId, cars.id);
            mockCarRepo.VerifyGetByIdForCar(Times.Once());
        }
        public async void CarsController_GetById_Empty()
        {
            // Arrange
            var mockCarYear    = 1980;
            var mockCar        = MockCarData.GetSingleEmptyModelAsync();
            var mockCarService = new MockCarService().MockGetById(mockCar);
            var mockLogging    = new Mock <ILogger <CarsController> >();
            var controller     = new CarsController(mockCarService.Object, mockLogging.Object);

            // Act
            var result = await controller.Get(mockCarYear);

            // Assert
            result.Should().BeOfType <NotFoundResult>();
            mockCarService.VerifyGetById(Times.Once());
        }
        public async void CarsController_GetById_Valid()
        {
            // Arrange
            var mockCarYear    = 2020;
            var mockCar        = MockCarData.GetSingleModelAsync();
            var mockCarService = new MockCarService().MockGetById(mockCar);
            var mockLogging    = new Mock <ILogger <CarsController> >();
            var controller     = new CarsController(mockCarService.Object, mockLogging.Object);

            // Act
            var result = await controller.Get(mockCarYear);

            // Assert
            Assert.IsAssignableFrom <IActionResult>(result);
            mockCarService.VerifyGetById(Times.Once());
        }
        private async Task TestIndexGET()
        {
            // Arrange
            int carsCount = 3;
            var cars      = GetListCar(carsCount).AsQueryable();
            var model     = new CarListViewModel(cars, 1, 10);

            MockCarData
            .Setup(_ => _.GetAllActive())
            .ReturnsAsync(cars);

            // Act
            dynamic response = await ControllerUnderTest.Index(1, 3);

            // Assert
            Assert.True(response.Model.Count.Equals(carsCount));
        }
        public async void CarsController_GetAll_Valid()
        {
            // Arrange
            var mockCar = MockCarData.GetAllModelListAsync();
            CarsResourceParameters parameters = new CarsResourceParameters {
            };
            var mockCarService = new MockCarService().MockGetAll(mockCar);
            var mockLogging    = new Mock <ILogger <CarsController> >();
            var controller     = new CarsController(mockCarService.Object, mockLogging.Object);

            // Act
            var result = await controller.Get(parameters);

            // Assert
            Assert.IsAssignableFrom <IActionResult>(result);
            mockCarService.VerifyGetAll(Times.Once());
        }
Exemplo n.º 8
0
        public async void CarsService_GetAllFilter_NoCars()
        {
            // Arrange
            var mockCar = MockCarData.GetEmptyEntityListAsync();
            CarsResourceParameters parameters = new CarsResourceParameters {
                Name = "M2B", Year = "1966"
            };
            var mockCarFilterRepo = new MockCarRepository().MockGetByYear(mockCar);
            var mockCarLoggerRepo = new MockLoggerRepository <CarsService>();
            var mockCarsService   = new CarsService(mockCarFilterRepo.Object, mockCarLoggerRepo.Object);

            // Act
            var cars = await mockCarsService.GetCars(parameters);

            // Assert
            Assert.Empty(cars);
            mockCarFilterRepo.VerifyGetByNameForCar(Times.Once());
            mockCarFilterRepo.VerifyGetByYearForCar(Times.Once());
        }
        public async void CarsController_GetAll_Empty()
        {
            // Arrange
            var mockCar = MockCarData.GetEmptyModelListAsync();
            CarsResourceParameters parameters = new CarsResourceParameters {
            };
            var mockCarService = new MockCarService().MockGetAll(mockCar);
            var mockLogging    = new Mock <ILogger <CarsController> >();
            var controller     = new CarsController(mockCarService.Object, mockLogging.Object);

            // Act
            var result = await controller.Get(parameters);

            // Assert
            var okResult = result.Should().BeOfType <OkObjectResult>().Subject;
            var car      = okResult.Value.Should().BeAssignableTo <IEnumerable <CarDto> >().Subject;

            car.Count().Should().Be(0);
            mockCarService.VerifyGetAll(Times.Once());
        }
        private async Task TestEditPOST()
        {
            // Arrange
            var id    = Guid.Empty;
            var car   = GetCar();
            var model = GetCarEditViewModel(car);

            MockCarData
            .Setup(_ => _.GetById(id))
            .ReturnsAsync(car);
            MockMapper
            .Setup(_ => _.Map <Car>(model))
            .Returns(car);

            // Act
            dynamic response = await ControllerUnderTest.Edit(model);

            // Assert
            MockCarData.Verify(_ => _.GetById(model.Id), Times.Once);
            MockCarData.Verify(_ => _.Update(car), Times.Once);
            Assert.True(response.RouteValues.Values[0].Equals(car.Id));
        }
        private async Task TestEditGET()
        {
            // Arrange
            var id    = Guid.Empty;
            var car   = GetCar();
            var model = GetCarEditViewModel(car);

            MockCarData
            .Setup(_ => _.GetById(id))
            .ReturnsAsync(car);
            MockMapper
            .Setup(_ => _.Map <CarEditViewModel>(car))
            .Returns(model);
            MockShowroomData
            .Setup(_ => _.GetAllActive())
            .ReturnsAsync(new List <Showroom>().AsEnumerable());

            // Act
            dynamic response = await ControllerUnderTest.Edit(id);

            // Assert
            MockCarData.Verify(_ => _.GetById(id), Times.Once);
            Assert.True(response.Model.Brand.Equals(model.Brand));
        }