Beispiel #1
0
        public void GetTechnicalControl_ById()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FleetManagmentContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FleetManagmentContext(options);

            ITechnicalControlRepository technicalControlRepository = new TechnicalControlRepository(context);
            TechnicalControlTO          technicalControl           = new TechnicalControlTO
            {
                Comment = "nothing",
            };

            TechnicalControlTO technicalControl2 = new TechnicalControlTO
            {
                Comment = "change tyre",
            };

            //ACT
            var addedTechnicalControl  = technicalControlRepository.Insert(technicalControl);
            var addedTechnicalControl2 = technicalControlRepository.Insert(technicalControl2);

            context.SaveChanges();

            //ASSERT
            Assert.IsNotNull(addedTechnicalControl);
            Assert.AreNotEqual(0, addedTechnicalControl.Id);
            Assert.AreEqual("nothing", addedTechnicalControl.Comment);
            Assert.AreEqual(1, technicalControlRepository.GetByID(1).Id);
        }
Beispiel #2
0
        public void UpdapteTechnicalControl_With_Correct_Parameter()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FleetManagmentContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FleetManagmentContext(options);

            ITechnicalControlRepository technicalControlRepository = new TechnicalControlRepository(context);

            TechnicalControlTO technicalControl = new TechnicalControlTO {
                Comment = "Nothing"
            };

            //ACT
            var addedTechnicalControl = technicalControlRepository.Insert(technicalControl);

            context.SaveChanges();

            addedTechnicalControl.Comment = "Refused";
            technicalControlRepository.Update(addedTechnicalControl);
            context.SaveChanges();

            //ASSERT
            Assert.IsNotNull(addedTechnicalControl);
            Assert.AreNotEqual(0, addedTechnicalControl.Id);
            Assert.AreEqual("Refused", addedTechnicalControl.Comment);
        }
Beispiel #3
0
        public void DeleteTechnicalControl_With_TechnicalControlTO_Parameter()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FleetManagmentContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FleetManagmentContext(options);

            ITechnicalControlRepository technicalControlRepository = new TechnicalControlRepository(context);

            TechnicalControlTO technicalControl = new TechnicalControlTO
            {
                Comment = "nothing",
            };

            TechnicalControlTO technicalControl2 = new TechnicalControlTO
            {
                Comment = "change tyre",
            };

            var addedTechnicalControl  = technicalControlRepository.Insert(technicalControl);
            var addedTechnicalControl2 = technicalControlRepository.Insert(technicalControl2);

            context.SaveChanges();

            //List<TechnicalControlTO> technicalControls = new List<TechnicalControlTO>();
            var technicalControls = technicalControlRepository.GetAll().ToList();

            //ACT
            technicalControlRepository.Remove(addedTechnicalControl);
            context.SaveChanges();
            technicalControls = technicalControlRepository.GetAll().ToList();

            //ASSERT
            Assert.IsNotNull(addedTechnicalControl);
            Assert.IsNotNull(addedTechnicalControl2);
            Assert.AreNotEqual(0, addedTechnicalControl.Id);
            Assert.AreNotEqual(0, addedTechnicalControl2.Id);
            Assert.AreEqual("nothing", addedTechnicalControl.Comment);
            Assert.AreEqual("change tyre", addedTechnicalControl2.Comment);
            Assert.AreEqual(1, technicalControls.Count);
        }
Beispiel #4
0
        public void AddTechnicalControl_ThrowsException_WhenNullIsProvided()
        {
            var options = new DbContextOptionsBuilder <FleetManagmentContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FleetManagmentContext(options);

            ITechnicalControlRepository technicalControlRepository = new TechnicalControlRepository(context);
            TechnicalControlTO          technicalControl           = new TechnicalControlTO
            {
                Comment = "nothing",
            };

            //ACT
            var addedTechnicalControl = technicalControlRepository.Insert(technicalControl);

            context.SaveChanges();
            //ASSERT
            Assert.ThrowsException <ArgumentNullException>(() => technicalControlRepository.Insert(null));
        }