public async Task RegiterAndConfirmEmail_Success()
        {
            var client = await Utilities.GetClientWithCsrfAsync();

            var email = Utilities.UniqueEmail();
            var form  = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("email", email)
            });
            var result = await client.PostAsync("api/account/register", form);

            result.EnsureSuccessStatusCode();
            Assert.IsNotNull(TestEmailSender.Emails[email]);
            GetGuidAndToken(TestEmailSender.Emails[email], out var guid, out var token);
            var form2 = Form(new
            {
                guid,
                token,
                username = Utilities.UniqueUserName(),
                password = "******"
            });
            var result2 = await client.PostAsync("api/account/confirmemail", form2);

            Assert.AreEqual(HttpStatusCode.OK, result2.StatusCode);

            var result3 = await client.GetAsync("api/account/current");

            result3.EnsureSuccessStatusCode();
            var json = JObject.Parse(await result3.Content.ReadAsStringAsync());
            // Assert.AreEqual(email, json["email"]);
        }
        public async Task ConfirmEmail_BadGuid()
        {
            var client = await Utilities.GetClientWithCsrfAsync();

            var email = Utilities.UniqueEmail();
            var form  = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("email", email)
            });
            var result = await client.PostAsync("api/account/register", form);

            result.EnsureSuccessStatusCode();

            Assert.IsNotNull(TestEmailSender.Emails[email]);
            GetGuidAndToken(TestEmailSender.Emails[email], out _, out var token);

            var form2 = Form(new
            {
                guid = "badguid",
                token,
                username = Utilities.UniqueUserName(),
                password = "******"
            });

            var result2 = await client.PostAsync("api/account/confirmemail", form2);

            Assert.AreEqual(HttpStatusCode.Unauthorized, result2.StatusCode);
            Assert.IsTrue(string.IsNullOrEmpty(await result2.Content.ReadAsStringAsync()));
        }
        public async Task ConfirmEmail_UserNameConflict()
        {
            var client = await Utilities.GetClientWithCsrfAsync();

            var email = Utilities.UniqueEmail();
            var form  = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("email", email)
            });
            var result = await client.PostAsync("api/account/register", form);

            result.EnsureSuccessStatusCode();

            Assert.IsNotNull(TestEmailSender.Emails[email]);

            var usermanager  = Utilities.GetService <UserManager <AppUser> >();
            var mockid       = Guid.NewGuid().ToString();
            var mockemail    = Utilities.UniqueEmail();
            var mockusername = Utilities.UniqueUserName();
            await usermanager.CreateAsync(new AppUser()
            {
                Id       = mockid,
                UserName = mockusername,
                Email    = mockemail
            });

            Assert.IsNotNull(await usermanager.FindByIdAsync(mockid));
            GetGuidAndToken(TestEmailSender.Emails[email], out var guid, out var token);

            var form2 = Form(new
            {
                guid,
                token,
                username = mockusername,
                password = "******"
            });

            var result2 = await client.PostAsync("api/account/confirmemail", form2);

            Assert.AreEqual(HttpStatusCode.Unauthorized, result2.StatusCode);
            // Assert.AreEqual("DuplicateUserName", await result2.Content.ReadAsStringAsync());
        }