public async Task <IActionResult> Start()
        {
            var job = new Sync.SyncJob();

            _db.SyncJobs.Add(job);
            await _db.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = job.ID }, job));
        }
        public async Task CreateAndUpdateUser()
        {
            var appFactory = new ApplicationFactory();

            using (var scoped = appFactory.CreateScope())
                using (var syncDB = scoped.ServiceProvider.GetRequiredService <Sync.SyncDataContext>())
                {
                    var userManager    = appFactory.Builder.ApplicationServices.GetRequiredService <UserManager <Identity.IdentityUser> >();
                    var passwordHasher = appFactory.Builder.ApplicationServices.GetRequiredService <IPasswordHasher <Identity.IdentityUser> >();

                    //create the sync job
                    var job = new Sync.SyncJob();
                    syncDB.SyncJobs.Add(job);
                    await syncDB.SaveChangesAsync();

                    List <Sync.IUserSyncItem> usersToSync = new List <Sync.IUserSyncItem>();
                    Guid userID = Guid.NewGuid();
                    usersToSync.Add(new TestSyncUserItem {
                        ID = userID, UserName = "******" + userID.ToString("D"), Email = userID.ToString("D") + "@autotest.test", PasswordHash = passwordHasher.HashPassword(null, "Password1!")
                    });
                    usersToSync.Add(new TestSyncUserItem {
                        ID = userID, UserName = "******", Email = userID.ToString("D") + "*****@*****.**", PasswordHash = passwordHasher.HashPassword(null, "Password2@")
                    });

                    var errors = await job.SyncUsersAsync(userManager, usersToSync);

                    //save the log items, and end the job
                    if (errors != null && errors.Any())
                    {
                        job.StopWithErrors("There were errors processing the user sync.");
                    }
                    else
                    {
                        job.Stop();
                    }

                    await syncDB.SaveChangesAsync();

                    if (errors != null && errors.Any())
                    {
                        foreach (var error in errors)
                        {
                            Console.WriteLine(error);
                        }

                        Assert.Fail("There were errors syncing the users.");
                    }
                }
        }