Beispiel #1
0
        private static void ClearDatabase()
        {
            var context = new TweeterLikeContext();

            context.Replies.Delete();
            context.Posts.Delete();
            context.Users.Delete();
            context.SaveChanges();
        }
Beispiel #2
0
        public void TestGetAllRepliesForTopicWhenTopicHasInvalidIdShouldReturnBadRequest()
        {
            var invalidId = 100000;
            var context   = new TweeterLikeContext();
            var dbPost    = context.Posts.FirstOrDefault(p => p.Id == invalidId);

            Assert.IsNull(dbPost);

            var response = this.GetRepliesForPost(invalidId);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Beispiel #3
0
        public void TestReplyToTopicWhenTopicHasValidIdButReplyDataIsInvalidShouldReturnBadRequest()
        {
            var data = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("cont", "InvalidComment#2"),
            });

            var context  = new TweeterLikeContext();
            var postId   = context.Posts.First().Id;
            var response = this.ReplyToPost(postId, data);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);

            var dbReply = context.Replies.FirstOrDefault(r => r.Comment == "InvalidComment#2");

            Assert.IsNull(dbReply);
        }
Beispiel #4
0
        private static void SeedPosts(TweeterLikeContext context)
        {
            context.Posts.Add(new Post()
            {
                Title   = "PostWithoutReplies",
                Comment = "PostWithoutReplies",
                Replies = new List <Reply>(),
                Author  = new ApplicationUser()
                {
                    UserName = "******", Id = "SeedSeed"
                }
            });
            context.Posts.Add(new Post()
            {
                Title   = "PostWithReplies",
                Comment = "PostWithReplies",
                Replies = new List <Reply>()
                {
                    new Reply()
                    {
                        Author = new ApplicationUser()
                        {
                            UserName = "******", Id = "SeedSeed2"
                        },
                        Comment = "FirstReply"
                    },
                    new Reply()
                    {
                        Author = new ApplicationUser()
                        {
                            UserName = "******", Id = "SeedSeed3"
                        },
                        Comment = "SecondReply"
                    },
                },
                Author = new ApplicationUser()
                {
                    UserName = "******", Id = "SeedSeed4"
                }
            });

            context.SaveChanges();
        }
Beispiel #5
0
        public void TestGetAllRepliesForTopicWhenTopicHasValidIdAndHasRepliesShouldReturnAllReplies()
        {
            var context  = new TweeterLikeContext();
            var postId   = context.Posts.First(p => p.Title == "PostWithReplies").Id;
            var response = this.GetRepliesForPost(postId);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            var replies = response.Content.ReadAsAsync <IEnumerable <ReplyViewModel> >()
                          .Result
                          .Select(r => r.Comment)
                          .ToList();

            var dbReplies = context.Posts.First(p => p.Id == postId).Replies
                            .Select(r => r.Comment)
                            .ToList();

            CollectionAssert.AreEqual(dbReplies, replies);
        }
Beispiel #6
0
        private static void SeedDatabase()
        {
            var context     = new TweeterLikeContext();
            var userStore   = new UserStore <ApplicationUser>(context);
            var userManager = new ApplicationUserManager(userStore);

            var user = new ApplicationUser()
            {
                UserName = Username,
                Email    = Username
            };

            var result = userManager.CreateAsync(user, Password).Result;

            if (!result.Succeeded)
            {
                Assert.Fail(string.Join(Environment.NewLine, result.Errors));
            }

            SeedPosts(context);
        }
Beispiel #7
0
        public void TestReplyToTopicWhenTopicHasValidIdShouldAddReplyToPost()
        {
            var data = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("comment", "firstComment"),
            });

            var context  = new TweeterLikeContext();
            var postId   = context.Posts.First().Id;
            var response = this.ReplyToPost(postId, data);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                Assert.Fail(response.Content.ReadAsStringAsync().Result);
            }

            var createdReply = response.Content.ReadAsAsync <ReplyViewModel>().Result;

            Assert.AreEqual("firstComment", createdReply.Comment);
            Assert.AreEqual(Username, createdReply.AuthorName);
            Assert.AreEqual(postId, createdReply.RepliedPostId);
        }
        public void TestGetAllRepliesForTopicWhenTopicHasInvalidIdShouldReturnBadRequest()
        {
            var invalidId = 100000;
            var context = new TweeterLikeContext();
            var dbPost = context.Posts.FirstOrDefault(p => p.Id == invalidId);
            Assert.IsNull(dbPost);

            var response = this.GetRepliesForPost(invalidId);
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        private static void SeedPosts(TweeterLikeContext context)
        {
            context.Posts.Add(new Post()
            {
                Title = "PostWithoutReplies",
                Comment = "PostWithoutReplies",
                Replies = new List<Reply>(),
                Author = new ApplicationUser() { UserName = "******", Id = "SeedSeed" }
            });
            context.Posts.Add(new Post()
            {
                Title = "PostWithReplies",
                Comment = "PostWithReplies",
                Replies = new List<Reply>()
                {
                    new Reply()
                    {
                        Author = new ApplicationUser() {UserName = "******", Id = "SeedSeed2"},
                        Comment = "FirstReply"
                    },
                    new Reply()
                    {
                        Author = new ApplicationUser() {UserName = "******", Id = "SeedSeed3"},
                        Comment = "SecondReply"
                    },
                },
                Author = new ApplicationUser() {UserName = "******", Id = "SeedSeed4"}
            });

            context.SaveChanges();
        }
        private static void SeedDatabase()
        {
            var context = new TweeterLikeContext();
            var userStore = new UserStore<ApplicationUser>(context);
            var userManager = new ApplicationUserManager(userStore);

            var user = new ApplicationUser()
            {
                UserName = Username,
                Email = Username
            };

            var result = userManager.CreateAsync(user, Password).Result;
            if (!result.Succeeded)
            {
                Assert.Fail(string.Join(Environment.NewLine, result.Errors));
            }

            SeedPosts(context);
        }
 private static void ClearDatabase()
 {
     var context = new TweeterLikeContext();
     context.Replies.Delete();
     context.Posts.Delete();
     context.Users.Delete();
     context.SaveChanges();
 }
        public void TestReplyToTopicWhenTopicHasValidIdShouldAddReplyToPost()
        {
            var data = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("comment", "firstComment"),
            });

            var context = new TweeterLikeContext();
            var postId = context.Posts.First().Id;
            var response = this.ReplyToPost(postId, data);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                Assert.Fail(response.Content.ReadAsStringAsync().Result);
            }

            var createdReply = response.Content.ReadAsAsync<ReplyViewModel>().Result;
            Assert.AreEqual("firstComment", createdReply.Comment);
            Assert.AreEqual(Username, createdReply.AuthorName);
            Assert.AreEqual(postId, createdReply.RepliedPostId);
        }
        public void TestReplyToTopicWhenTopicHasValidIdButReplyDataIsInvalidShouldReturnBadRequest()
        {
            var data = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("cont", "InvalidComment#2"),
            });

            var context = new TweeterLikeContext();
            var postId = context.Posts.First().Id;
            var response = this.ReplyToPost(postId, data);
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);

            var dbReply = context.Replies.FirstOrDefault(r => r.Comment == "InvalidComment#2");
            Assert.IsNull(dbReply);
        }
        public void TestGetAllRepliesForTopicWhenTopicHasValidIdAndHasRepliesShouldReturnAllReplies()
        {
            var context = new TweeterLikeContext();
            var postId = context.Posts.First(p => p.Title == "PostWithReplies").Id;
            var response = this.GetRepliesForPost(postId);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            var replies = response.Content.ReadAsAsync<IEnumerable<ReplyViewModel>>()
                .Result
                .Select(r => r.Comment)
                .ToList();

            var dbReplies = context.Posts.First(p => p.Id == postId).Replies
                .Select(r => r.Comment)
                .ToList();
            CollectionAssert.AreEqual(dbReplies, replies);
        }
 public TweeterLikeData(TweeterLikeContext context)
 {
     this.Context      = context;
     this.repositories = new Dictionary <Type, object>();
 }
 public Repository(TweeterLikeContext context)
 {
     this.Context = context;
     this.DbSet   = this.Context.Set <T>();
 }