public void WhenGetAllFromEmptyDatabase_ThenReturnsEmptyCollection()
        {
            var repository = new VehicleRepository(new MileageStatsDbContext());
            IEnumerable<Vehicle> actual = repository.GetVehicles(this.defaultTestUser.UserId);

            Assert.NotNull(actual);
            List<Vehicle> actualList = new List<Vehicle>(actual);
            Assert.Equal(0, actualList.Count);
        }
        public void WhenVehicleAdded_ThenPersists()
        {
            int userId = this.defaultTestUser.UserId;
            var repository = new VehicleRepository(new MileageStatsDbContext());

            Vehicle vehicle1 = new Vehicle {Name = "Vehicle1"};
            Vehicle vehicle2 = new Vehicle {Name = "Vehicle2"};

            repository.Create(userId, vehicle1);
            repository.Create(userId, vehicle2);

            // I use a new context and repository to verify the data was stored
            var repository2 = new VehicleRepository(new MileageStatsDbContext());

            var retrievedVehicles = repository2.GetVehicles(userId);

            Assert.NotNull(retrievedVehicles);
            List<Vehicle> actualList = new List<Vehicle>(retrievedVehicles);

            Assert.Equal(2, actualList.Count);
            Assert.Equal(vehicle1.Name, actualList[0].Name);
            Assert.Equal(vehicle2.Name, actualList[1].Name);
        }
        public void WhenVehicleModifiedInSameContext_ThenPersistsChange()
        {
            IUnitOfWork uow = new MileageStatsDbContext();
            int userId = this.defaultTestUser.UserId;
            var repository = new VehicleRepository(uow);

            Vehicle vehicle = new Vehicle {Name = "Vehicle", UserId = userId};
            repository.Create(userId, vehicle);

            // I use a new context and repository to verify the data was stored
            var repositoryForUpdate = new VehicleRepository(uow);

            var retrievedVehicle = repositoryForUpdate.GetVehicles(userId).First();

            retrievedVehicle.Name = "Updated Vehicle Name";
            repositoryForUpdate.Update(retrievedVehicle);
            int updatedVehicleId = retrievedVehicle.VehicleId;

            var repositoryForVerify = new VehicleRepository(uow);
            var updatedVehicle = repositoryForVerify.GetVehicle(userId, updatedVehicleId);

            Assert.Equal("Updated Vehicle Name", updatedVehicle.Name);
        }
        public void WhenVehicleDeleted_ThenPersists()
        {
            int userId = this.defaultTestUser.UserId;
            var repository = new VehicleRepository(new MileageStatsDbContext());

            Vehicle vehicle1 = new Vehicle {Name = "Vehicle1"};
            repository.Create(userId, vehicle1);

            var retrievedVehicles = repository.GetVehicles(userId);
            Assert.Equal(1, retrievedVehicles.Count());
            repository.Delete(retrievedVehicles.First().VehicleId);

            // I use a new context and repository to verify the vehicle was deleted
            var repository2 = new VehicleRepository(new MileageStatsDbContext());

            var verifyVehicles = repository2.GetVehicles(userId);

            Assert.NotNull(retrievedVehicles);
            Assert.Equal(0, verifyVehicles.Count());
        }
        public void WhenVehicleAdded_ThenUpdatesVehicleId()
        {
            int userId = this.defaultTestUser.UserId;
            var repository = new VehicleRepository(new MileageStatsDbContext());

            Vehicle vehicle = new Vehicle {Name = "Vehicle"};

            repository.Create(userId, vehicle);

            IEnumerable<Vehicle> retrievedVehicles = repository.GetVehicles(userId);

            Assert.NotNull(retrievedVehicles);
            List<Vehicle> actualList = new List<Vehicle>(retrievedVehicles);

            Assert.Equal(1, actualList.Count);
            Assert.Equal(1, actualList[0].VehicleId);
        }