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

            using var context = new FleetManagmentContext(options);

            IInsuranceRepository insuranceRepository = new InsuranceRepository(context);

            InsuranceTO insurance = new InsuranceTO
            {
                Name = "AG",
            };

            InsuranceTO insurance2 = new InsuranceTO
            {
                Name = "Ethias",
            };

            //ACT

            var addedInsurance  = insuranceRepository.Insert(insurance);
            var addedInsurance2 = insuranceRepository.Insert(insurance2);

            context.SaveChanges();

            //ASSERT
            Assert.IsNotNull(addedInsurance);
            Assert.AreNotEqual(0, addedInsurance.Id);
            Assert.AreEqual("AG", addedInsurance.Name);
        }
Beispiel #2
0
        public InsuranceTO Insert(InsuranceTO entity)
        {
            if (entity is null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(context.Insurances.Add(entity.ToEntity()).Entity.ToTransfertObject());
        }
Beispiel #3
0
        public InsuranceTO Update(InsuranceTO entity)
        {
            if (entity is null)
            {
                throw new ArgumentException(nameof(entity));
            }
            var insuranceModified = context.Insurances.FirstOrDefault(x => x.Id == entity.Id);

            insuranceModified.Name      = entity.Name;
            insuranceModified.StartDate = entity.StartDate;
            insuranceModified.EndDate   = entity.EndDate;
            insuranceModified.Car       = entity.Car?.ToEntity();

            return(insuranceModified.ToTransfertObject());
        }
        public static Insurance ToEntity(this InsuranceTO insurance)
        {
            if (insurance is null)
            {
                throw new ArgumentNullException(nameof(insurance));
            }

            return(new Insurance
            {
                Id = insurance.Id,
                Name = insurance.Name,
                StartDate = insurance.StartDate,
                EndDate = insurance.EndDate,
                Car = insurance.Car?.ToEntity(),
            });
        }
Beispiel #5
0
        public void DeleteInsurance_With_InsuranceTO_Parameter()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FleetManagmentContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FleetManagmentContext(options);

            IInsuranceRepository insuranceRepository = new InsuranceRepository(context);

            InsuranceTO insurance = new InsuranceTO
            {
                Name = "AG",
            };

            InsuranceTO insurance2 = new InsuranceTO
            {
                Name = "Ethias",
            };

            var addedInsurance  = insuranceRepository.Insert(insurance);
            var addedInsurance2 = insuranceRepository.Insert(insurance2);

            context.SaveChanges();

            //List<InsuranceTO> insurances = new List<InsuranceTO>();
            var insurances = insuranceRepository.GetAll().ToList();

            //ACT
            insuranceRepository.Remove(addedInsurance);
            context.SaveChanges();
            insurances = insuranceRepository.GetAll().ToList();

            //ASSERT
            Assert.IsNotNull(addedInsurance);
            Assert.IsNotNull(addedInsurance2);
            Assert.AreNotEqual(0, addedInsurance.Id);
            Assert.AreNotEqual(0, addedInsurance2.Id);
            Assert.AreEqual("AG", addedInsurance.Name);
            Assert.AreEqual("Ethias", addedInsurance2.Name);
            Assert.AreEqual(1, insurances.Count);
        }
Beispiel #6
0
 public bool Remove(InsuranceTO entity)
 => RemoveById(entity.Id);