Example #1
0
 public void NotThrowException_WhenValidUnitOfWorkIsPassed()
 {
     //arrange
     var validUnitOfWork = new Mock <IUnitOfWork>();
     //act
     var carService = new Services.CarService(validUnitOfWork.Object);
 }
        public void ThrowServiceExcpetion_WhenNullArgumentIsPassed()
        {
            //arrange
            var fakeUnitOfWork = new Mock <IUnitOfWork>();
            var sut            = new Services.CarService(fakeUnitOfWork.Object);

            //act
            //assert
            Assert.ThrowsException <ServiceException>(() => sut.AddCar(null));
        }
Example #3
0
        public void NotThrowException_WhenValidUnitOfWorkIsPassed()
        {
            //arrange
            var contexOptions = new DbContextOptionsBuilder <DealershipContext>()
                                .UseInMemoryDatabase(databaseName: "AddCarToDatabase_WhenValidParametersArePassed").Options;
            var extrasServiceMock = new Mock <IExtraService>();

            //act
            using (var dealershipContext = new DealershipContext(contexOptions))
            {
                var carService = new Services.CarService(dealershipContext, extrasServiceMock.Object);
            }
        }
        public void AddCarToDatabase_WhenValidParametersArePassed()
        {
            var contexOptions = new DbContextOptionsBuilder <DealershipContext>()
                                .UseInMemoryDatabase(databaseName: "AddCarToDatabase_WhenValidParametersArePassed").Options;

            var testCar = new Mock <Car>();

            DealershipContext dealershipContext;

            using (dealershipContext = new DealershipContext(contexOptions))
            {
                var unitofWork = new UnitOfWork(dealershipContext);
                var carService = new Services.CarService(unitofWork);


                carService.AddCar(testCar.Object);
            }
            using (dealershipContext = new DealershipContext(contexOptions))
            {
                Assert.IsTrue(dealershipContext.Cars.Count() == 1);
            }
        }