Exemplo n.º 1
0
        public async Task UpdateUserAsync_WhenPassingUpdatedUser_ShouldUpdateProperly()
        {
            var user = MigrationService.CreateUser();

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                using (var context = new EFCoreSampleDbContext(options))
                {
                    context.Users.Add(user);

                    await context.SaveChangesAsync();
                }

                var code = user.Codes.First();
                code.CityCode = 3333;

                using (var context = new EFCoreSampleDbContext(options))
                {
                    var dataService = new DataService(context);

                    await dataService.UpdateUserAsync(user);
                }

                using (var context = new EFCoreSampleDbContext(options))
                {
                    var dataService = new DataService(context);

                    var users = await dataService.GetUsersAsync();

                    var dbUser = users.Single(u => u.Id == user.Id);

                    dbUser.Codes.Single(c => c.Id == code.Id).CityCode.Should().Be(3333);
                }
            }
        }
Exemplo n.º 2
0
        public async Task GetUsersAsync_ValidateUser()
        {
            var user = MigrationService.CreateUser();

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                using (var context = new EFCoreSampleDbContext(options))
                {
                    context.Users.Add(user);

                    await context.SaveChangesAsync();
                }

                using (var context = new EFCoreSampleDbContext(options))
                {
                    var dataService = new DataService(context);

                    var users = await dataService.GetUsersAsync();

                    var dbUser = users.Single(u => u.Id == user.Id);

                    dbUser.Name.Should().Be(user.Name);
                    dbUser.Codes.Count.Should().Be(user.Codes.Count);
                }
            }
        }
Exemplo n.º 3
0
 public DataServiceTests()
 {
     using (var context = new EFCoreSampleDbContext(options))
     {
         context.Database.EnsureCreated();
         context.Database.Migrate();
     }
 }
        private async Task MigrateAsync(EFCoreSampleDbContext context)
        {
            await context.Database.EnsureCreatedAsync();

            await context.Database.MigrateAsync();

            if (!context.Users.Any())
            {
                var user = CreateUser();

                context.Users.Add(user);

                await context.SaveChangesAsync();
            }
        }
Exemplo n.º 5
0
 public DataService(EFCoreSampleDbContext context)
 {
     this.context = context;
 }