Exemplo n.º 1
0
        public async Task CheckIfDbIsEmptyDeleteAsyncShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <ElectricTravelDbContext>()
                          .UseInMemoryDatabase(databaseName: "ChargingStationsTestDb").Options;

            using var dbContext = new ElectricTravelDbContext(options);

            using var repo = new EfDeletableEntityRepository <ChargingStation>(dbContext);
            var service = new ChargingStationsService(repo);

            var isTrue = await service.DeleteAsync(2);

            Assert.True(!isTrue);
        }
Exemplo n.º 2
0
        public async Task CheckThatDeleteAsyncShouldReturnTrueIfStationIsDeleted()
        {
            var options = new DbContextOptionsBuilder <ElectricTravelDbContext>()
                          .UseInMemoryDatabase(databaseName: "ChargingStationsTestDb").Options;

            using var dbContext = new ElectricTravelDbContext(options);

            using var repo = new EfDeletableEntityRepository <ChargingStation>(dbContext);
            var service = new ChargingStationsService(repo);

            var stationName = "ElDrive";
            var address     = "Drujba 1";
            var cityId      = 1;
            var description = "Something";
            var isFree      = false;
            var workingTime = "10-22";

            var stationToAdd = new ChargingStation
            {
                Name           = stationName,
                Address        = address,
                CityId         = cityId,
                Description    = description,
                IsFreeOfCharge = isFree,
                WorkTime       = workingTime,
            };

            await repo.AddAsync(stationToAdd);

            await repo.SaveChangesAsync();

            var stations = repo.All().ToList();

            var id = 0;

            if (stations.Count == 1)
            {
                var station = stations.SingleOrDefault();
                id = station.Id;
            }

            var isTrue = await service.DeleteAsync(id);

            Assert.True(isTrue);
        }