private static void ClearDatabase() { var context = new TweeterLikeContext(); context.Replies.Delete(); context.Posts.Delete(); context.Users.Delete(); context.SaveChanges(); }
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); }
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); }
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(); }
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); }
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); }
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); }
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); }
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>(); }