public async Task InitializePageTest() { //Arrange var postId1 = new Guid("8e864dcc-5e0e-49c2-9f66-b3da6cee735f"); var postId2 = new Guid("46c7656f-6a77-4a48-817f-ec45c5cf5bf7"); var tags = new string[2] { "tag1", "tag2" }; var tagText = "tag1, tag2"; //Act await _postsViewModel.InitializeAsync(null); //Assert Assert.AreEqual(2, _postsViewModel.PostList.Count); Assert.AreEqual(0, _postsViewModel.PostList[0].Comments); Assert.AreEqual(0, _postsViewModel.PostList[0].CommentList.Count); Assert.AreEqual("UserName1", _postsViewModel.PostList[0].CreatedBy); Assert.AreEqual(DateTime.MinValue, _postsViewModel.PostList[0].CreatedOn); Assert.AreEqual("Description1", _postsViewModel.PostList[0].Description); Assert.AreEqual(postId1, _postsViewModel.PostList[0].Id); Assert.AreEqual(true, _postsViewModel.PostList[0].IsLikedByUser); Assert.AreEqual(2, _postsViewModel.PostList[0].Likes); Assert.AreEqual(null, _postsViewModel.PostList[0].Tags); Assert.AreEqual(false, _postsViewModel.PostList[0].HasTags); Assert.AreEqual("", _postsViewModel.PostList[0].TagsText); Assert.AreEqual(1, _postsViewModel.PostList[1].Comments); Assert.AreEqual(1, _postsViewModel.PostList[1].CommentList.Count); Assert.AreEqual("UserName2", _postsViewModel.PostList[1].CreatedBy); Assert.AreEqual(DateTime.MinValue, _postsViewModel.PostList[1].CreatedOn); Assert.AreEqual("Description2", _postsViewModel.PostList[1].Description); Assert.AreEqual(postId2, _postsViewModel.PostList[1].Id); Assert.AreEqual(false, _postsViewModel.PostList[1].IsLikedByUser); Assert.AreEqual(2, _postsViewModel.PostList[1].Likes); Assert.AreEqual(tags[0], _postsViewModel.PostList[1].Tags[0]); Assert.AreEqual(true, _postsViewModel.PostList[1].HasTags); Assert.AreEqual(tagText, _postsViewModel.PostList[1].TagsText); _postServiceMock.Verify(x => x.GetAllPosts("", _runtimeContextMock.Object.Token), Times.Once); }
protected override async void OnAppearing() { await postsViewModel.InitializeAsync(null); }