예제 #1
0
        public async Task <Wagon> AddAsync(Wagon wagon)
        {
            _trainContext.Add(wagon);
            await _trainContext.SaveChangesAsync();

            return(wagon);
        }
예제 #2
0
        public async Task <Train> AddAsync(Train train)
        {
            _trainContext.Add(train);
            await _trainContext.SaveChangesAsync();

            return(train);
        }
예제 #3
0
        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);
            }
        }