public async Task <Wagon> AddAsync(Wagon wagon) { _trainContext.Add(wagon); await _trainContext.SaveChangesAsync(); return(wagon); }
public async Task <Train> AddAsync(Train train) { _trainContext.Add(train); await _trainContext.SaveChangesAsync(); return(train); }
public async void Can_Update_Wagon() { // Arrange var chairs = new List <TrainApp.Data.Entities.Chair> { new TrainApp.Data.Entities.Chair { NearWindow = false, Number = 0, Reserved = false }, new TrainApp.Data.Entities.Chair { NearWindow = false, Number = 1, Reserved = false } }; var testWagon = new TrainApp.Data.Entities.Wagon { Chairs = chairs }; using (var context = new TrainContext(_contextOptions)) { await context.Wagons.AddAsync(testWagon); await context.SaveChangesAsync(); } var updatedWagon = testWagon; updatedWagon.Chairs[1].NearWindow = true; // Act using (var context = new TrainContext(_contextOptions)) { var repository = new WagonRepository(context); var wagon = await repository.UpdateAsync(updatedWagon); } // Assert using (var context = new TrainContext(_contextOptions)) { var wagon = await context.Wagons.Include(c => c.Chairs).FirstOrDefaultAsync(x => x.WagonId == testWagon.WagonId); Assert.Equal(testWagon.Chairs.Count, wagon.Chairs.Count); Assert.Equal(testWagon.Chairs[1].Number, wagon.Chairs[1].Number); Assert.True(wagon.Chairs[1].NearWindow); } }