public void GetApplicableGLasses_ShouldReturnNeededItems()
        {
            var vehicle = new Vehicle()
            {
                MakeId         = 1, ModelId = 1, BodyTypeId = 1,
                VehicleGlasses = new List <VehicleGlass>()
                {
                    new VehicleGlass()
                    {
                        Id = 1
                    }, new VehicleGlass()
                    {
                        Id = 2
                    }
                }
            };

            var repositoryMock = new Mock <IInternalDbRepository <Vehicle> >();

            var service = new VehiclesService(repositoryMock.Object);

            var response = service.GetApplicableGLasses(vehicle).ToList();

            Assert.AreEqual(response.Count, 2);
            Assert.AreEqual(response[0].Id, 1);
            Assert.AreEqual(response[1].Id, 2);
        }
Ejemplo n.º 2
0
        public VehiclesServiceTest()
        {
            CustomersRepositoryMock = new Mock <ICustomersRepository>();
            VehiclesRepositoryMock  = new Mock <IVehiclesRepository>();
            UnitOfWorkFactoryMock   = new Mock <IUnitOfWorkFactory>();
            UnitOfWorkMock          = new Mock <IUnitOfWork>();

            ServiceUnderTest = new VehiclesService(VehiclesRepositoryMock.Object);

            UnitOfWorkFactoryMock
            .Setup(x => x.GetInstance())
            .Returns(UnitOfWorkMock.Object);

            UnitOfWorkMock
            .Setup(x => x.CustomersRepository)
            .Returns(CustomersRepositoryMock.Object);

            UnitOfWorkMock
            .Setup(x => x.VehiclesRepository)
            .Returns(VehiclesRepositoryMock.Object);

            pagingOptions = new PagingOptions {
                Offset = 0, Limit = 5
            };
        }
        public void GetVehicleByMakeModelAndBodyTypeIds_ShouldReturnNeededItem()
        {
            int id    = 2;
            var items = new List <Vehicle>()
            {
                new Vehicle()
                {
                    MakeId = id, ModelId = id, BodyTypeId = 10
                },
                new Vehicle()
                {
                    MakeId = id, ModelId = 3, BodyTypeId = 3, Id = 1
                },
                new Vehicle()
                {
                    MakeId = id, ModelId = id, BodyTypeId = id, Id = 2
                },
                new Vehicle()
                {
                    MakeId = id, ModelId = 3, BodyTypeId = id
                },
            }.AsQueryable();

            var repositoryMock = new Mock <IInternalDbRepository <Vehicle> >();

            repositoryMock.Setup(x => x.All()).Returns(() => items);

            var service = new VehiclesService(repositoryMock.Object);

            var response = service.GetVehicleByMakeModelAndBodyTypeIds(id, id, id);

            Assert.AreEqual(response.Id, 2);
            repositoryMock.VerifyAll();
        }
        public void GetApplicableGLassesByProductType_ShouldReturnNeededItems()
        {
            string productType = "windscreen";
            var    vehicle     = new Vehicle()
            {
                MakeId         = 1,
                ModelId        = 1,
                BodyTypeId     = 1,
                VehicleGlasses = new List <VehicleGlass>()
                {
                    new VehicleGlass()
                    {
                        Id = 1, ProductType = productType
                    },
                    new VehicleGlass()
                    {
                        Id = 2, ProductType = "test"
                    },
                    new VehicleGlass()
                    {
                        Id = 3, ProductType = productType
                    }
                }
            };

            var repositoryMock = new Mock <IInternalDbRepository <Vehicle> >();

            var service = new VehiclesService(repositoryMock.Object);

            var response = service.GetApplicableGLassesByProductType(vehicle, productType).ToList();

            Assert.AreEqual(response.Count, 2);
            Assert.AreEqual(response[0].Id, 1);
            Assert.AreEqual(response[1].Id, 3);
        }
Ejemplo n.º 5
0
        public void GetAllShouldReturnEmptyListOnEmptyRepository()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();

            repository.Setup(r => r.All()).Returns(new List <Vehicle>().AsQueryable());
            var service = new VehiclesService(repository.Object);

            Assert.Equal(0, service.GetAll().Count);
        }
Ejemplo n.º 6
0
        public void GetByVinShouldReturnNullOnEmptyCollection()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();

            repository.Setup(r => r.All()).Returns(new List <Vehicle>().AsQueryable());
            var    service   = new VehiclesService(repository.Object);
            string randomVIN = "WAUZZZ1KZ8N123456";

            Assert.Null(service.GetByVin(randomVIN));
        }
Ejemplo n.º 7
0
        public void GetByIdShouldReturnNullOnEmptyCollection()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();

            repository.Setup(r => r.All()).Returns(new List <Vehicle>().AsQueryable());
            var service  = new VehiclesService(repository.Object);
            int randomId = 1;

            Assert.Null(service.GetById(randomId));
        }
Ejemplo n.º 8
0
        public void CheckForValidInsuranceShouldReturnNullOnEmptyCollection()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();
            var service    = new VehiclesService(repository.Object);
            var vehicle    = new Vehicle
            {
                Policies = new List <Policy>(),
            };

            Assert.Null(service.CheckForValidInsurance(vehicle));
        }
Ejemplo n.º 9
0
        public void VehicleExistsShouldReturnFalseOnEmptyRepository()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();

            repository.Setup(r => r.All()).Returns(new List <Vehicle>().AsQueryable());
            var    service   = new VehiclesService(repository.Object);
            string randomVIN = "WAUZZZ1KZ8N123456";

            Assert.False(service.VihicleExists(randomVIN));
            repository.Verify(x => x.All(), Times.Once);
        }
Ejemplo n.º 10
0
        public void CheckOwnershipShouldReturnFalseOnEmptyRepository()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();

            repository.Setup(r => r.All()).Returns(new List <Vehicle>().AsQueryable());
            var    service         = new VehiclesService(repository.Object);
            string randomUserId    = "testId";
            int    randomVehicleId = 1;

            Assert.False(service.CheckOwnership(randomUserId, randomVehicleId));
        }
        public void GetBodyTypeIdsByModelIdAndMakeId_ShouldReturnNeededItems_WhenModelIdIsNull()
        {
            int id    = 2;
            var items = new List <Vehicle>()
            {
                new Vehicle()
                {
                    MakeId = id, ModelId = null, BodyTypeId = 1
                },
                new Vehicle()
                {
                    MakeId = id, ModelId = null, BodyTypeId = 2
                },
                new Vehicle()
                {
                    MakeId = id, ModelId = null, BodyTypeId = 2
                },
                new Vehicle()
                {
                    MakeId = id, ModelId = null, BodyTypeId = null
                },
                new Vehicle()
                {
                    MakeId = id, ModelId = null, BodyTypeId = null
                },
                new Vehicle()
                {
                    MakeId = id, ModelId = null, BodyTypeId = 2, Id = 1
                },
                new Vehicle()
                {
                    MakeId = id, ModelId = 10, BodyTypeId = id, Id = 2
                },
                new Vehicle()
                {
                    MakeId = 3, ModelId = id, BodyTypeId = id
                },
            }.AsQueryable();

            var repositoryMock = new Mock <IInternalDbRepository <Vehicle> >();

            repositoryMock.Setup(x => x.All()).Returns(() => items);

            var service = new VehiclesService(repositoryMock.Object);

            var response = service.GetBodyTypeIdsByModelIdAndMakeId(id, null);

            Assert.AreEqual(response.Count, 3);
            Assert.AreEqual(response[0], 1);
            Assert.AreEqual(response[1], 2);
            Assert.AreEqual(response[2], null);
            repositoryMock.VerifyAll();
        }
Ejemplo n.º 12
0
        public async Task DeleteShouldDoNothingOnEmptyCollection()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb3")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service    = new VehiclesService(repository);
            int randomId   = 1;
            await service.Delete(randomId);

            Assert.Equal(0, service.GetAll().Count);
        }
Ejemplo n.º 13
0
        public void Test1()
        {
            var repo = new Mock <IRepository <string, Car> >();

            repo.Setup(r => r.Exists(It.IsAny <string>())).Returns(false);
            var unitUnderTest = new VehiclesService(repo.Object);

            for (int i = 0; i < 10000; i++)
            {
                unitUnderTest.Add(VehiclesTestData.CreateCarRequest());
            }


            Assert.Pass();
        }
Ejemplo n.º 14
0
        public async Task CreateShouldIncreaseCountOnEmptyCollection()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb1")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service    = new VehiclesService(repository);
            var newVehicle = new Vehicle();

            Assert.Equal(0, service.GetAll().Count);
            await service.Create(newVehicle);

            Assert.Equal(1, service.GetAll().Count);
        }
Ejemplo n.º 15
0
        public void VehicleExistsShouldReturnTrueOnExistingVIN()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();

            repository.Setup(r => r.All()).Returns(new List <Vehicle>
            {
                new Vehicle()
                {
                    VIN = "WAUZZZ1KZ8N123456"
                },
            }.AsQueryable());
            var    service     = new VehiclesService(repository.Object);
            string existingVIN = "WAUZZZ1KZ8N123456";

            Assert.True(service.VihicleExists(existingVIN));
        }
Ejemplo n.º 16
0
        public void GetByIdShouldReturnNullOnNonExistingId()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();

            repository.Setup(r => r.All()).Returns(new List <Vehicle>
            {
                new Vehicle()
                {
                    Id = 2
                },
            }.AsQueryable());
            var service       = new VehiclesService(repository.Object);
            int nonExistingId = 1;

            Assert.Null(service.GetById(nonExistingId));
        }
Ejemplo n.º 17
0
        public void CheckOwnershipShouldReturnTrueOnCorrectVehicleId()
        {
            var    repository        = new Mock <IDeletableEntityRepository <Vehicle> >();
            string randomUserId      = "testId";
            int    existingVehicleId = 1;

            repository.Setup(r => r.All()).Returns(new List <Vehicle>
            {
                new Vehicle {
                    Id = existingVehicleId, OwnerId = randomUserId
                },
            }.AsQueryable());
            var service = new VehiclesService(repository.Object);

            Assert.True(service.CheckOwnership(randomUserId, existingVehicleId));
        }
Ejemplo n.º 18
0
        public void GetByVinShouldReturnNullOnOnNonExistingVIN()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();

            repository.Setup(r => r.All()).Returns(new List <Vehicle>
            {
                new Vehicle()
                {
                    VIN = "ZFA131BAR00000000"
                },
            }.AsQueryable());
            var    service        = new VehiclesService(repository.Object);
            string nonExistingVIN = "WAUZZZ1KZ8N123456";

            Assert.Null(service.GetByVin(nonExistingVIN));
        }
Ejemplo n.º 19
0
        public void CheckForValidInsuranceShouldReturnNullOnCollectionWithInvalidPolicies()
        {
            var    repository = new Mock <IDeletableEntityRepository <Vehicle> >();
            var    service    = new VehiclesService(repository.Object);
            string policyId   = "test";
            var    vehicle    = new Vehicle
            {
                Policies = new List <Policy>
                {
                    new Policy {
                        Id = policyId, IsValid = false
                    },
                },
            };

            Assert.Null(service.CheckForValidInsurance(vehicle));
        }
Ejemplo n.º 20
0
        public void CheckForValidInsuranceShouldReturnCorrectString()
        {
            var    repository = new Mock <IDeletableEntityRepository <Vehicle> >();
            var    service    = new VehiclesService(repository.Object);
            string policyId   = "test";
            var    vehicle    = new Vehicle
            {
                Policies = new List <Policy>
                {
                    new Policy {
                        Id = policyId, IsValid = true
                    },
                },
            };

            Assert.Equal(policyId, service.CheckForValidInsurance(vehicle));
        }
Ejemplo n.º 21
0
        public async Task EditShouldDoNothingOnEmptyCollection()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb6")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service    = new VehiclesService(repository);
            var inputModel = new VehicleEditViewModel
            {
                Id = 1,
            };
            await service.Edit(inputModel);

            Assert.Equal(0, service.GetAll().Count);
        }
Ejemplo n.º 22
0
        public async Task CreateShouldAddTheCorrectObject()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb2")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service    = new VehiclesService(repository);
            var newVehicle = new Vehicle {
                Id = 1, Make = "Mercedes", Model = "S500"
            };
            await service.Create(newVehicle);

            var vehicleFromDb = service.GetById(newVehicle.Id);

            Assert.Equal <Vehicle>(newVehicle, vehicleFromDb);
        }
Ejemplo n.º 23
0
        public async Task EditShouldUpdateEntityWithExistingId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb8")
                          .Options;
            var dbContext  = new ApplicationDbContext(options);
            var newVehicle = new Vehicle
            {
                Id                = 1,
                Make              = "Mercedes",
                Model             = "S500",
                VIN               = "WDB2221KZ8N654321",
                NumberPlate       = "CA1111PA",
                FirstRegistration = new DateTime(2019, 1, 1),
                Type              = VehicleType.Truck,
            };

            dbContext.Vehicles.Add(newVehicle);
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service    = new VehiclesService(repository);
            var inputModel = new VehicleEditViewModel
            {
                Id                = 1,
                Make              = "BMW",
                Model             = "760Li",
                VIN               = "WBNX6X6D30300G980",
                NumberPlate       = "CA2222PA",
                FirstRegistration = "31-12-2018",
                Type              = "Car",
            };
            await service.Edit(inputModel);

            Assert.Equal("BMW", service.GetById(1).Make);
            Assert.Equal("760Li", service.GetById(1).Model);
            Assert.Equal("WBNX6X6D30300G980", service.GetById(1).VIN);
            Assert.Equal("CA2222PA", service.GetById(1).NumberPlate);
            var expectedDate = new DateTime(2018, 12, 31);

            Assert.Equal <DateTime>(expectedDate, service.GetById(1).FirstRegistration);
            Assert.Equal <VehicleType>(VehicleType.Car, service.GetById(1).Type);
        }
Ejemplo n.º 24
0
        public async Task DeleteShouldDoNothingWithNonExistingId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb4")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Vehicles.Add(new Vehicle {
                Id = 1
            });
            await dbContext.SaveChangesAsync();

            var repository    = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service       = new VehiclesService(repository);
            int nonExistingId = 2;
            await service.Delete(nonExistingId);

            Assert.Equal(1, service.GetAll().Count);
        }
Ejemplo n.º 25
0
        public void GetMyVehiclesShouldReturnCorrectCountOnNonEmptyRepositoryIfVehicleExist()
        {
            var repository = new Mock <IDeletableEntityRepository <Vehicle> >();

            repository.Setup(r => r.All()).Returns(new List <Vehicle>
            {
                new Vehicle()
                {
                    OwnerId = "Pesho"
                },
                new Vehicle()
                {
                    OwnerId = "Gosho"
                },
            }.AsQueryable());
            var    service          = new VehiclesService(repository.Object);
            string existingClientId = "Pesho";

            Assert.Equal(1, service.GetMyVehicles(existingClientId).Count);
        }
Ejemplo n.º 26
0
        public async Task EditShouldDoNothingWithNonExistingId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb7")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Vehicles.Add(new Vehicle {
                Id = 1, Make = "Mercedes"
            });
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service    = new VehiclesService(repository);
            var inputModel = new VehicleEditViewModel
            {
                Id   = 2,
                Make = "BMW",
            };
            await service.Edit(inputModel);

            Assert.Equal("Mercedes", service.GetById(1).Make);
        }
        public void GetAllByMakeId_ShouldReturnNeededItems()
        {
            int id    = 2;
            var items = new List <Vehicle>()
            {
                new Vehicle()
                {
                    MakeId = 3, ModelId = id, BodyTypeId = id
                },
                new Vehicle()
                {
                    Id = 1, MakeId = id, ModelId = 2, BodyTypeId = 2
                },
                new Vehicle()
                {
                    Id = 2, MakeId = id, ModelId = 1, BodyTypeId = 1
                },
                new Vehicle()
                {
                    MakeId = 10, ModelId = 2, BodyTypeId = 2
                },
            }.AsQueryable();

            var repositoryMock = new Mock <IInternalDbRepository <Vehicle> >();

            repositoryMock.Setup(x => x.All()).Returns(() => items);

            var service = new VehiclesService(repositoryMock.Object);

            var response = service.GetAllByMakeId(id).ToList();

            Assert.AreEqual(response.Count, 2);
            Assert.AreEqual(response[0].Id, 1);
            Assert.AreEqual(response[1].Id, 2);
            repositoryMock.VerifyAll();
        }
Ejemplo n.º 28
0
 public VehiclesController(VehiclesService vehiclesService, ILogger <VehiclesController> logger)
 {
     _vehiclesService = vehiclesService;
     _logger          = logger;
 }
 public VehiclesServiceTest()
 {
     vehiclesRepository = Substitute.For <IVehiclesRepository>();
     vehiclesService    = new VehiclesService(vehiclesRepository);
 }
Ejemplo n.º 30
0
 public VehiclesController(VehiclesService vehiclesService)
 {
     this.vehiclesService = vehiclesService;
 }