Exemple #1
0
 public async Task TestSingleInitialization()
 {
     var t1 = _client.EnsureInitAsync();
     var t2 = _client.EnsureInitAsync();
     var t3 = _client.EnsureInitAsync();
     await Task.WhenAll(t1, t2, t3);
 }
        private async Task InitAsync()
        {
            Client = new GraphApiClient(
                Config.ApplicationId,
                Config.ApplicationSecret,
                Config.Tenant
                );

            await Client.EnsureInitAsync();

            var b2cApp = await Client.GetB2cExtensionsApplicationAsync();

            var extProperties = await Client.GetApplicationExtensionsAsync(b2cApp.ObjectId);

            ExtensionPropertyName = extProperties.FirstOrDefault()?.GetSimpleName();

            TestUser = CreateTestUser();
            TestUser = await Client.UserCreateAsync(TestUser);

            var group = CreateTestGroup();

            group = await Client.GroupCreateAsync(group);

            TestGroupObjectId = group.ObjectId;

            await Client.GroupAddMemberAsync(group.ObjectId, TestUserObjectId);
        }
        public async Task TestWithAuthDelegate()
        {
            var client = new GraphApiClient(Config.Tenant, GetAccessTokenAsync);
            await client.EnsureInitAsync();

            // If something is wrong with init call (authorization issues etc), exception will be thrown.
            Assert.True(true);
        }
        public async Task TestWithCredentials()
        {
            var client = new GraphApiClient(Config.ApplicationId, Config.ApplicationSecret, Config.Tenant);
            await client.EnsureInitAsync();

            // If something is wrong with init call (authorization issues etc), exception will be thrown.
            Assert.True(true);
        }
Exemple #5
0
        static async Task Main(string[] args)
        {
            Console.Write("Checking GraphAPI client credentials...");
            client = new GraphApiClient(applicationId, applicationSecret, tenant);
            await client.EnsureInitAsync();

            var demoEmail = "*****@*****.**";
            var demoUser  = await client.UserGetBySigninNameAsync(demoEmail);

            if (demoUser == null)
            {
                demoUser = await CreateDemoUser(demoEmail, demoEmail.Substring(0, demoEmail.IndexOf("@")));
            }

            await client.UserUpdateAsync(demoUser.ObjectId, new
            {
                passwordProfile = new PasswordProfile
                {
                    EnforceChangePasswordPolicy  = false,
                    ForceChangePasswordNextLogin = true,
                    Password = "******"
                }
            });

            demoUser = await client.UserGetBySigninNameAsync(demoEmail);


            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("DONE.");
            Console.ForegroundColor = ConsoleColor.White;

            var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            await TestUpdates();

            await DeleteTestUsers();

            // Load local users
            var userRepository = new UserRepository(connectionString);
            var users          = await userRepository.GetUsersAsync();

            // Migrate first 20 user to B2C
            var createdUsers = new List <User>();
            var timespans    = new List <long>();

            foreach (var user in users.Take(20))
            {
                user.DisplayName = "test " + user.DisplayName;
                var sw      = Stopwatch.StartNew();
                var newUser = await client.UserCreateAsync(user);

                var elapsedMs = sw.ElapsedMilliseconds;
                Console.WriteLine($"User added: ({elapsedMs} ms): {user.DisplayName} ({user.SignInNames.First().Value})");
                timespans.Add(elapsedMs);
                createdUsers.Add(newUser);
            }

            Console.WriteLine($"Users created: {users.Count} -Avg creation: {timespans.Average()} ms.");
            Console.WriteLine();
            Console.WriteLine("Do you want to delete the created users? (Y/N)");
            var confirmation = Console.ReadLine();

            if (!string.Equals(confirmation, "Y", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            foreach (var user in createdUsers)
            {
                var sw = Stopwatch.StartNew();
                client.UserDeleteAsync(user.ObjectId).Wait();
                Console.WriteLine($"User Deleted: ({sw.ElapsedMilliseconds} ms): {user.DisplayName} ({user.SignInNames.First().Value})");
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Console.Write("Checking GraphAPI client credentials...");
            client = new GraphApiClient(applicationId, applicationSecret, tenant);

            try
            {
                client.EnsureInitAsync().Wait();

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("DONE.");
                Console.ForegroundColor = ConsoleColor.White;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Graph API credentials probably are not correct. Please fix and try again.");
                Console.WriteLine($"Error: {ex}");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
                return;
            }

            // Deletes test users (from previous runs)
            DeleteTestUsers();

            var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            // Load local users
            Console.Write("Retrieving local users...");
            var userRepository = new UserRepository(connectionString);
            var users          = userRepository.GetUsersAsync().Result;

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("DONE.");
            Console.ForegroundColor = ConsoleColor.White;

            // Migrate first 20 users to B2C
            var createdUsers = new List <User>();
            var timespans    = new List <long>();

            foreach (var user in users.Take(20))
            {
                // Assign a test prefix during demo.
                user.DisplayName = "test " + user.DisplayName;

                var sw        = Stopwatch.StartNew();
                var newUser   = client.UserCreateAsync(user).Result;
                var elapsedMs = sw.ElapsedMilliseconds;
                Console.WriteLine($"User added: ({elapsedMs} ms): {user.DisplayName} ({user.SignInNames.First().Value})");
                timespans.Add(elapsedMs);
                createdUsers.Add(newUser);
            }

            Console.WriteLine($"Users created: {users.Count} -Avg creation: {timespans.Average()} ms.");
            Console.WriteLine();

            // Removing users just created for demo's purposes
            Console.WriteLine("Do you want to delete the created users? (Y/N)");
            var confirmation = Console.ReadLine();

            if (!string.Equals(confirmation, "Y", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            foreach (var user in createdUsers)
            {
                var sw = Stopwatch.StartNew();
                client.UserDeleteAsync(user.ObjectId).Wait();
                Console.WriteLine($"User Deleted: ({sw.ElapsedMilliseconds} ms): {user.DisplayName} ({user.SignInNames.First().Value})");
            }
        }