Ejemplo n.º 1
0
        public void Post_CarClass_IsTrue()
        {
            var carclass = new CarClass()
            {
                Class = "Ichwerdegeloescht", CostsPerDay = 1000m
            };
            DbContextOptionsBuilder <CarRentDBContext> builder = new DbContextOptionsBuilder <CarRentDBContext>();

            builder.UseInMemoryDatabase("CarRent");
            DbContextOptions <CarRentDBContext> options = builder.Options;
            CarRentDBContext carrent = new CarRentDBContext(options);

            ExampleData.ExampleData.InitTestData(carrent);
            var carclasscontroller = new CarClassesController(carrent);

            if (carrent.CarClasses.Any(e => e.Class == carclass.Class))
            {
                int index        = 0;
                var carclasslist = carclasscontroller.GetCarClasses();
                foreach (var cclass in carclasslist)
                {
                    if (!cclass.Class.Equals(carclass.Class))
                    {
                        continue;
                    }
                    index = cclass.Id;
                }

                carclasscontroller.DeleteCarClass(index);
            }

            carclasscontroller.PostCarClass(carclass);

            var bOk = false;
            var ind = 0;

            foreach (var carsclasses in carclasscontroller.GetCarClasses())
            {
                if (carsclasses.Class.Equals(carclass.Class) && carsclasses.CostsPerDay == carclass.CostsPerDay)
                {
                    bOk = true;
                    ind = carsclasses.Id;
                    break;
                }
            }

            carclasscontroller.DeleteCarClass(ind);
            Assert.IsTrue(bOk);
        }
Ejemplo n.º 2
0
        public void Delete_CarClass_IsTrue()
        {
            var carclass = new CarClass()
            {
                Class = "Ichwerdegeloeschtzwei", CostsPerDay = 1000m
            };
            DbContextOptionsBuilder <CarRentDBContext> builder = new DbContextOptionsBuilder <CarRentDBContext>();

            builder.UseInMemoryDatabase("CarRent");
            DbContextOptions <CarRentDBContext> options = builder.Options;
            CarRentDBContext carrent = new CarRentDBContext(options);

            ExampleData.ExampleData.InitTestData(carrent);
            var carclasscontroller = new CarClassesController(carrent);

            carclasscontroller.PostCarClass(carclass);
            bool isAdded = false;
            int  id      = 0;

            foreach (var cclass in carclasscontroller.GetCarClasses())
            {
                if (cclass.Class.Equals(carclass.Class) && cclass.CostsPerDay == carclass.CostsPerDay)
                {
                    id      = cclass.Id;
                    isAdded = true;
                    break;
                }
            }

            carclasscontroller.DeleteCarClass(id);
            Assert.IsTrue(isAdded && carclasscontroller.GetCarClass(id) == null);
        }