public async Task Given_an_ApplicationUserStore_when_a_user_is_created_then_it_can_be_retrieved_by_username()
        {
            // GIVEN a user store and user
            var userStore = new ApplicationUserStore(_authContext.Object);

            var user = new ApplicationUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            // WHEN the user is created
            await userStore.CreateAsync(user, false);

            // THEN the user should retrieved from the user store and match the original user
            var userFromStore = await userStore.FindByNameAsync(user.UserName, false);

            userFromStore.UserName.Should().Be(user.UserName, "because the user has been created in and retrieved from the ApplicationUserStore.");
        }
        public async Task Given_an_ApplicationUserStore_when_a_user_is_updated_then_it_can_be_retrieved()
        {
            // Given an ApplicationUserStore and ApplicationUser
            var userStore = new ApplicationUserStore(_authContext.Object);
            var user      = new ApplicationUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            // WHEN creating and upating a user.
            await userStore.CreateAsync(user, false);

            var userFromStore = await userStore.FindByNameAsync(user.UserName, false);

            userFromStore.UserName.Should().Be(user.UserName, "because the user has been created in and retrieved from the userstore.");

            // THEN the user should be the same in the store after being updated.
            await userStore.UpdateAsync(user, false);

            userFromStore.UserName.Should().Be(user.UserName, "because the user has been updated in the userstore.");
            await userStore.DeleteAsync(user, false);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            userName = Request.QueryString["id"];
            SqlDatabase database = new SqlDatabase();
            UserTable   users    = new UserTable(database);

            if (String.IsNullOrEmpty(userName) || !users.Exist(userName))
            {
                Response.Redirect(Page.ResolveUrl("~/"));
            }
            ApplicationUserStore   userStore = new ApplicationUserStore();
            Task <ApplicationUser> userTask  = userStore.FindByNameAsync(userName);

            userID = userTask.Result.Id;
            string date = users.GetRegistrationDate(userID);

            NameLabel.Text       = "Name: " + userName;
            RegisteredLabel.Text = "Registration date: " + date;

            DisplayPosts();
            if (Page.IsPostBack)
            {
                if (Request["__EVENTTARGET"] == "starClick")
                {
                    if (!User.Identity.IsAuthenticated)
                    {
                        Response.Redirect(Page.ResolveUrl("~/Account/Login"));
                        return;
                    }
                    ApplicationUserManager manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
                    string _userID = ApplicationUserStore.GetUserIDByName(manager, User);
                    string postID  = Request["__EVENTARGUMENT"];
                    UpdateStarsCount(postID, _userID);
                }
            }
            database.CloseConnection();
        }
示例#4
0
 public async Task <ApplicationUser> GetUserByNameAsync(string username)
 {
     return(await _store.FindByNameAsync(username));
 }