Пример #1
0
        public void AddPostTest()
        {
            //Arrange
            var repo = new FakeRepository();

            AddTestData(repo);
            var controller = new HomeController(repo);

            //Act
            AppUser u = repo.GetUserByUserName("test");
            Post    p = new Post()
            {
                User    = u,
                Message = "This is amazing"
            };

            u.AddPost(p);

            //Assert
            Assert.Single(u.Posts);
            Assert.Equal("This is amazing", u.Posts[0].Message);
        }
Пример #2
0
        public async Task <IActionResult> Index(string postMessage)
        {
            AppUser u = await CurrentUser;

            if (postMessage != null)
            {
                Post p = new Post()
                {
                    UserName = u,
                    Message  = postMessage
                };
                u.AddPost(p);
                Repository.AddPost(p, u);
                await userManager.UpdateAsync(u);
            }
            List <AppUser> dbUsers = userManager.Users.ToList();
            List <Post>    dbLists = Repository.Posts;

            dbLists.Reverse();
            ViewBag.userName  = u.UserName;
            ViewBag.postCount = u.Posts.Count;
            return(View(dbLists));
        }