Exemple #1
0
 private void SeedDbContext()
 {
     using (ShowNTellDbContext context = GetDbContext())
     {
         Seed(context);
         context.SaveChanges();
     }
 }
Exemple #2
0
        public async Task Delete_WithExistingComment_ReturnsTrue()
        {
            Comment            comment = new Comment();
            ShowNTellDbContext context = GetDbContext();

            context.Add(comment);
            context.SaveChanges();

            bool actual = await _commentService.Delete(comment.Id);

            Assert.IsTrue(actual);
        }
Exemple #3
0
        public async Task GetRandom_WithExistingImagePosts_ReturnsImagePost()
        {
            using (ShowNTellDbContext context = GetDbContext())
            {
                context.ImagePosts.Add(new ImagePost());
                context.SaveChanges();
            }

            ImagePost actual = await _randomImagePostService.GetRandom();

            Assert.IsNotNull(actual);
        }
Exemple #4
0
        public async Task IsCommentOwner_WithExistingCommentNotOwnedByUser_ReturnsFalse()
        {
            string             userEmail = "*****@*****.**";
            Comment            comment   = new Comment();
            ShowNTellDbContext context   = GetDbContext();

            context.Add(comment);
            context.SaveChanges();

            bool actual = await _commentService.IsCommentOwner(comment.Id, userEmail);

            Assert.IsFalse(actual);
        }
Exemple #5
0
        public async Task Update_WithExistingComment_ReturnsCommentWithNewContent()
        {
            Comment            comment = new Comment();
            ShowNTellDbContext context = GetDbContext();

            context.Add(comment);
            context.SaveChanges();
            string expectedContent = "new content";

            Comment actualComment = await _commentService.Update(comment.Id, expectedContent);

            string actualContent = actualComment.Content;

            Assert.AreEqual(expectedContent, actualContent);
        }
Exemple #6
0
        public async Task GetByEmail_WithExistingEmail_ReturnsUserWithEmail()
        {
            string             expectedEmail = "*****@*****.**";
            ShowNTellDbContext context       = _contextFactory.CreateDbContext();

            context.Add(new User()
            {
                Email = expectedEmail
            });
            context.SaveChanges();

            User user = await _userService.GetByEmail(expectedEmail);

            string actualEmail = user.Email;

            Assert.AreEqual(expectedEmail, actualEmail);
        }
        public void Seed()
        {
            using (ShowNTellDbContext context = _contextFactory.CreateDbContext())
            {
                context.Database.Migrate();

                if (context.Users.Count() == 0)
                {
                    context.Users.Add(new User()
                    {
                        Email    = "*****@*****.**",
                        Username = "******"
                    });
                }

                context.SaveChanges();
            }
        }
Exemple #8
0
        public async Task CanDelete_WithExistingCommentOwnedByUser_ReturnsTrue()
        {
            string  userEmail = "*****@*****.**";
            Comment comment   = new Comment()
            {
                User = new User {
                    Email = userEmail
                },
                ImagePost = new ImagePost()
            };
            ShowNTellDbContext context = GetDbContext();

            context.Add(comment);
            context.SaveChanges();

            bool actual = await _commentService.CanDelete(comment.Id, userEmail);

            Assert.IsTrue(actual);
        }
Exemple #9
0
        public async Task GetByEmail_WithUserFollowingOthers_ReturnsUserWithFollows()
        {
            int expectedFollowingCount = 3;
            ShowNTellDbContext context = _contextFactory.CreateDbContext();

            context.Add(new User()
            {
                Email = string.Empty, Following = new List <Follow>()
                {
                    new Follow()
                    {
                        User = new User()
                        {
                            Email = "*****@*****.**"
                        }
                    },
                    new Follow()
                    {
                        User = new User()
                        {
                            Email = "*****@*****.**"
                        }
                    },
                    new Follow()
                    {
                        User = new User()
                        {
                            Email = "*****@*****.**"
                        }
                    }
                }
            });
            context.SaveChanges();

            User user = await _userService.GetByEmail(string.Empty);

            int actualFollowingCount = user.Following.Count;

            Assert.IsNotNull(user.Following);
            Assert.AreEqual(expectedFollowingCount, actualFollowingCount);
        }
Exemple #10
0
        public void Create_WithExistingEmail_ThrowsArgumentExceptionForEmail()
        {
            string             expectedInvalidParamName = "email";
            string             existingEmail            = "*****@*****.**";
            ShowNTellDbContext context = _contextFactory.CreateDbContext();

            context.Add(new User()
            {
                Email = existingEmail
            });
            context.SaveChanges();
            User newUser = new User()
            {
                Email = existingEmail
            };

            ArgumentException exception = Assert.ThrowsAsync <ArgumentException>(() => _userService.Create(newUser));
            string            actualInvalidParamName = exception.ParamName;

            Assert.AreEqual(expectedInvalidParamName, actualInvalidParamName);
        }