Esempio n. 1
0
        public async Task AsyncData()
        {
            using (var context = new WorldContext())
            {
                await context.Database.EnsureDeletedAsync();

                await context.Database.EnsureCreatedAsync();

                var america = new Continent {
                    Code = "AM", Name = "America"
                };
                var europe = new Continent {
                    Code = "EU", Name = "Europe"
                };
                var asia = new Continent {
                    Code = "AS", Name = "Asia"
                };
                var africa = new Continent {
                    Code = "AF", Name = "Africa"
                };

                await context.AddAsync(america);

                await context.AddRangeAsync(europe, asia, africa);

                var result = context.SaveChangesAsync();
                result.Wait(30_000);
                Assert.Null(result.Exception);
                Assert.Equal(4, result.Result);
            }

            using (var context = new WorldContext())
            {
                var continent = await context.FindAsync <Continent>("AS");

                Assert.Equal("Asia", continent.Name);

                var continents = await context.Continents.ToListAsync();

                Assert.Equal(4, continents.Count);
            }
        }