public void AddVehicle_shuold_add_vehicle() { // arrange Vehicle TestVehicle = new Vehicle { Id = 1, Color = "Red", RegNr = "ABH234", OwnerId = 1, TypeId = 1 }; var context = new TestGarageContext(); var repo = new GRepo(context); // Act int oldCount = repo.GetVehicles().Count(); repo.AddVehicle(TestVehicle); var result = repo.GetVehicle(1) as Vehicle; // Assert //Count has changed Assert.AreNotEqual(oldCount, repo.GetVehicles().Count()); //Count increased by only 1 Assert.AreEqual((oldCount + 1), repo.GetVehicles().Count()); //Vehicle added is the same as the vehicle returned from the repository Assert.AreEqual(TestVehicle, result); }
public void EditVehicle_shuold_edit_vehicle() { // arrange Vehicle OldTestVehicle = new Vehicle { Id = 1, Color = "Red", RegNr = "ABH234", OwnerId = 1, TypeId = 1 }; Vehicle TestVehicle = new Vehicle { Id = 1, Color = "Red", RegNr = "ABH234", OwnerId = 1, TypeId = 1 }; Vehicle TestVehicleEdit = new Vehicle { Id = 1, Color = "Green", RegNr = "ABH234", OwnerId = 1, TypeId = 1 }; var context = new TestGarageContext(); var repo = new GRepo(context); repo.AddVehicle(TestVehicle); // Act repo.EditVehicle(TestVehicleEdit); var result = repo.GetVehicle(1) as Vehicle; // Assert // Vehicle was changed Assert.AreNotEqual(OldTestVehicle.Color, TestVehicle.Color); // Vehicle color was changed to green Assert.AreEqual(TestVehicle.Color, "Green"); // TestVehicle is the same as the result Assert.AreEqual(result, TestVehicle); }
public void GetVehicle_should_return_object_of_vehicle() { // arrange IEnumerable <Vehicle> Vehicles = ObjectCreator.Vehicles(); var context = new TestGarageContext(); context.Vehicles.AddRange(Vehicles); var repo = new GRepo(context); // act var result = repo.GetVehicle(1) as Vehicle; //assert Assert.IsInstanceOfType(result, typeof(Vehicle)); Assert.IsTrue(Vehicles.Contains(result)); var testvehicle = Vehicles.SingleOrDefault(v => v.Id == result.Id); foreach (PropertyInfo p in result.GetType().GetProperties()) { Assert.AreEqual(p.GetValue(result), p.GetValue(testvehicle)); } }