Пример #1
0
        public void RemoveVehicle_shuold_remove_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);

            repo.AddVehicle(TestVehicle);

            // Act
            int OldCount = repo.GetVehicles().Count();

            repo.RemoveVehicle(TestVehicle);

            var result = repo.GetVehicles() as IEnumerable <Vehicle>;

            // Assert

            // Repository was changed
            Assert.AreNotEqual(OldCount, result.Count());

            // Count decresed by only 1
            Assert.AreEqual((OldCount - 1), result.Count());

            // TestVehicle doesn't exist in the result
            Assert.IsFalse(result.Contains(TestVehicle));
        }
Пример #2
0
        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);
        }
Пример #3
0
        public void GetVehicles_should_return_ienumberable_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.GetVehicles() as IEnumerable <Vehicle>;

            //assert
            Assert.IsInstanceOfType(result, typeof(IEnumerable <Vehicle>));
            Assert.AreEqual(Vehicles.Count(), result.Count());

            IEnumerator <Vehicle> e1 = Vehicles.GetEnumerator();
            IEnumerator <Vehicle> e2 = result.GetEnumerator();

            while (e1.MoveNext() && e2.MoveNext())
            {
                Assert.AreEqual(e1.Current, e2.Current);
            }
        }