Exemple #1
0
        public async Task UpdateAsync_WithOtherDataChanged_DoesNotUpdate()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var ride = new Ride
            {
                Title          = "Initial Title",
                PhoneNumber    = "0000000000",
                Notes          = "Initial Notes",
                Car            = new Car(),
                Date           = DateTime.UtcNow,
                AvailableSeats = 2,
                From           = "Test From",
                To             = "Test To"
            };

            await context.Rides.AddAsync(ride);

            var car = new Car();

            await context.Cars.AddAsync(car);

            await context.SaveChangesAsync();

            var ridesService = new RidesService(new EfRepository <Ride>(context), null, null, null);

            var serviceModel = new RideServiceModel()
            {
                Id             = ride.Id,
                Title          = ride.Title,
                PhoneNumber    = ride.PhoneNumber,
                Notes          = ride.Notes,
                CarId          = car.Id,
                AvailableSeats = 1,
                From           = "Updated From",
                To             = "Updated To"
            };

            var initialDate  = ride.Date;
            var initialSeats = ride.AvailableSeats;
            var initialFrom  = ride.From;
            var initialTo    = ride.To;

            // Act
            await ridesService.UpdateAsync(serviceModel);

            // Assert
            var dbModel = await context.Rides.SingleAsync();

            Assert.Equal(initialDate, dbModel.Date);
            Assert.Equal(initialSeats, dbModel.AvailableSeats);
            Assert.Equal(initialFrom, dbModel.From);
            Assert.Equal(initialTo, dbModel.To);
        }
Exemple #2
0
        public async Task UpdateAsync_WithValidModel_WorksCorrectly()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var ride = new Ride
            {
                Title          = "Initial Title",
                PhoneNumber    = "0000000000",
                Notes          = "Initial Notes",
                Car            = new Car(),
                Date           = DateTime.UtcNow,
                AvailableSeats = 1,
                From           = "Test From",
                To             = "Test To"
            };

            await context.Rides.AddAsync(ride);

            await context.SaveChangesAsync();

            var ridesService = new RidesService(new EfRepository <Ride>(context), null, null, null);

            var serviceModel = new RideServiceModel()
            {
                Id             = ride.Id,
                Title          = "Updated Title",
                PhoneNumber    = "0000000001",
                Notes          = "Updated Notes",
                CarId          = ride.CarId,
                AvailableSeats = ride.AvailableSeats,
                From           = ride.From,
                To             = ride.To
            };

            // Act
            var result = await ridesService.UpdateAsync(serviceModel);

            // Assert
            Assert.True(result);

            var dbModel = await context.Rides.SingleAsync();

            Assert.Equal(serviceModel.Title, dbModel.Title);
            Assert.Equal(serviceModel.PhoneNumber, dbModel.PhoneNumber);
            Assert.Equal(serviceModel.Notes, dbModel.Notes);
        }
Exemple #3
0
        public async Task UpdateAsync_WithNonExistentId_ReturnsFalse()
        {
            // Arrange
            var testRideId = Guid.NewGuid().ToString();

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var ride = new Ride
            {
                Title          = "Initial Title",
                PhoneNumber    = "0000000000",
                Notes          = "Initial Notes",
                Car            = new Car(),
                Date           = DateTime.UtcNow,
                AvailableSeats = 1,
                From           = "Test From",
                To             = "Test To"
            };

            await context.Rides.AddAsync(ride);

            await context.SaveChangesAsync();

            var ridesService = new RidesService(new EfRepository <Ride>(context), null, null, null);

            var serviceModel = new RideServiceModel()
            {
                Id             = testRideId,
                Title          = "Updated Title",
                PhoneNumber    = "0000000001",
                Notes          = "Updated Notes",
                CarId          = ride.CarId,
                AvailableSeats = ride.AvailableSeats,
                From           = ride.From,
                To             = ride.To
            };

            // Act
            var result = await ridesService.UpdateAsync(serviceModel);

            // Assert
            Assert.False(result);
        }