Exemplo n.º 1
0
        public void GetNameByIdShouldWorkCorrectly()
        {
            var posts    = new List <Post>();
            var appUsers = new List <ApplicationUser>();

            var mockPostRepo = new Mock <IDeletableEntityRepository <Post> >();

            mockPostRepo.Setup(x => x.All()).Returns(posts.AsQueryable());
            mockPostRepo.Setup(x => x.AddAsync(It.IsAny <Post>())).Callback((Post post) => posts.Add(post));

            var mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >();

            mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable());
            mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU));

            var service = new PostsService(mockAppUser.Object, mockPostRepo.Object);

            var post = new Post
            {
                Id       = "1",
                UserId   = "1",
                Content  = "Test",
                Title    = "Test",
                SentById = "1",
            };

            posts.Add(post);
            var appUser = new ApplicationUser
            {
                Id = "1",
                UserCharacteristics = new UserCharacteristic
                {
                    FirstName = "Pesho",
                },
            };

            appUsers.Add(appUser);

            var userName = service.GetNameById("1");

            var expectedOutput = "Pesho";

            Assert.Equal(expectedOutput, appUser.UserCharacteristics.FirstName);
        }