public void DoPhoto_CommentTest() { MockManager.Init(); Comment comment = new Comment(); #region Add comment var addRepo = MockManager.MockAll <AuthRepository>(Constructor.Mocked); addRepo.ExpectAndReturn("Authenticate", "1234", 1).Args(Permission.Delete); using (var commentAddMock = new FakeFlickrRepository <CommentRepository, Comment>()) { commentAddMock.FakeDoHttpPostAndReturnStringResult(ResourceNs + ".AddComment.xml"); comment.PhotoId = COMMENT_PHOTO_ID; comment.Text = "Testing comment add [LINQ.Flickr]"; context.Photos.Comments.Add(comment); context.SubmitChanges(); Assert.IsTrue(comment.Id == "1"); } addRepo.Verify(); #endregion #region Get added comment Comment commentGet = null; using (var commentGetMock = new FakeFlickrRepository <CommentRepository, Comment>()) { commentGetMock.FakeSignatureCall(); commentGetMock.MockRESTBuilderGetElement(ResourceNs + ".GetComment.xml"); var query = from c in context.Photos.Comments where c.PhotoId == COMMENT_PHOTO_ID && c.Id == comment.Id select c; commentGet = query.Single(); Assert.IsTrue(commentGet.Author == "11" && commentGet.PhotoId == COMMENT_PHOTO_ID && commentGet.AuthorName == "John Doe"); } #endregion #region update comment var updateRepo = MockManager.MockAll <AuthRepository>(Constructor.Mocked); updateRepo.ExpectAndReturn("Authenticate", "1234", 1).Args(Permission.Delete); using (var commentUpdateMock = new FakeFlickrRepository <CommentRepository, Comment>()) { const string updatedText = "#123#"; // line verfies if the text is passed properly for update. commentUpdateMock.FakeSignatureCall("flickr.photos.comments.editComment", true, "comment_id", "1", "comment_text", updatedText, "auth_token", "1234"); commentUpdateMock.FakeDoHttpPostAndReturnStringResult(ResourceNs + ".UpdateComment.xml"); commentGet.Text = updatedText; context.SubmitChanges(); } updateRepo.Verify(); #endregion #region Delete added var deleteRepo = MockManager.MockAll <AuthRepository>(Constructor.Mocked); deleteRepo.ExpectAndReturn("Authenticate", "1234", 1).Args(Permission.Delete); using (var commentDeleteMock = new FakeFlickrRepository <CommentRepository, Comment>()) { commentDeleteMock.FakeSignatureCall(); commentDeleteMock.FakeDoHttpPostAndReturnStringResult(ResourceNs + ".DeleteComment.xml"); context.Photos.Comments.Remove(commentGet); context.SubmitChanges(); } deleteRepo.Verify(); #endregion }
public void DoPhoto_CommentTest() { MockManager.Init(); Comment comment = new Comment(); #region Add comment using (FakeFlickrRepository <CommentRepository, Comment> commentAddMock = new FakeFlickrRepository <CommentRepository, Comment>()) { commentAddMock.MockAuthenticateCall(Permission.Delete, 1); commentAddMock.MockSignatureCall(); commentAddMock.MockDoHttpPostAndReturnStringResult(RESOURCE_NS + ".AddComment.xml"); comment.PhotoId = COMMENT_PHOTO_ID; comment.Text = "Testing comment add [LINQ.Flickr]"; _context.Photos.Comments.Add(comment); _context.SubmitChanges(); Assert.IsTrue(comment.Id == "1"); } #endregion #region Get added comment Comment commentGet = null; using (FakeFlickrRepository <CommentRepository, Comment> commentGetMock = new FakeFlickrRepository <CommentRepository, Comment>()) { commentGetMock.MockSignatureCall(); commentGetMock.MockRESTBuilderGetElement(RESOURCE_NS + ".GetComment.xml"); var query = from c in _context.Photos.Comments where c.PhotoId == COMMENT_PHOTO_ID && c.Id == comment.Id select c; commentGet = query.Single(); Assert.IsTrue(commentGet.Author == "11" && commentGet.PhotoId == COMMENT_PHOTO_ID && commentGet.AuthorName == "John Doe"); } #endregion #region update comment using (FakeFlickrRepository <CommentRepository, Comment> commentUpdateMock = new FakeFlickrRepository <CommentRepository, Comment>()) { const string updateText = "#123#"; commentUpdateMock.MockAuthenticateCall(Permission.Delete, 1); // line verfies if the text is passed properly for update. commentUpdateMock.MockSignatureCall("flickr.photos.comments.editComment", true, "comment_id", "1", "comment_text", updateText, "auth_token", "1234"); commentUpdateMock.MockDoHttpPostAndReturnStringResult(RESOURCE_NS + ".UpdateComment.xml"); commentGet.Text = updateText; _context.SubmitChanges(); } #endregion #region Delete added using (FakeFlickrRepository <CommentRepository, Comment> commentDeleteMock = new FakeFlickrRepository <CommentRepository, Comment>()) { commentDeleteMock.MockAuthenticateCall(Permission.Delete, 1); commentDeleteMock.MockSignatureCall(); commentDeleteMock.MockDoHttpPostAndReturnStringResult(RESOURCE_NS + ".DeleteComment.xml"); _context.Photos.Comments.Remove(comment); _context.SubmitChanges(); } #endregion MockManager.Verify(); }