예제 #1
0
        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
        }
예제 #2
0
        public void DoPhotoTest()
        {
            MockManager.Init();

            using (var photoGetMock = new FakeFlickrRepository <PhotoRepository, Photo>())
            {
                photoGetMock.FakeElementCall("Linq.Flickr.Test.Responses.Search.xml");

                var searchQuery = (from p in context.Photos
                                   where p.SearchText == "macbook" && p.FilterMode == FilterMode.Safe &&
                                   p.Extras == (ExtrasOption.Views | ExtrasOption.Date_Taken | ExtrasOption.Date_Upload | ExtrasOption.Tags | ExtrasOption.Date_Upload)
                                   orderby PhotoOrder.Interestingness ascending
                                   select p).Take(100);

                int count = searchQuery.Count();

                Photo first = searchQuery.First();

                Assert.IsTrue(first.SharedProperty.Perpage == count);
                Assert.IsTrue(first.Title == "test" && first.Id == "505611561");
                Assert.IsTrue(first.ExtrasResult.Views == 8);

                Photo last = searchQuery.Last();

                Assert.IsTrue(last.SharedProperty.Page == 1);
                Assert.IsTrue(last.SharedProperty.Total == 66604);
                Assert.IsTrue(last.Title == "DSCN0355" && last.Id == "2373030074");

                DateTime dateTime = DateTime.Parse("2008-03-29 20:25:05");

                Assert.IsTrue(dateTime == last.TakeOn);

                dateTime = GetDate("1206847505");

                Assert.IsTrue(dateTime == last.UploadedOn);

                dateTime = GetDate("1206847506");

                Assert.IsTrue(dateTime == last.UpdatedOn);

                Assert.IsTrue(last.Tags.Length == 2);

                //Assert.IsTrue();

                string constructedWebUrl = string.Format("http://www.flickr.com/photos/{0}/{1}/", last.NsId, last.Id);

                Assert.IsTrue(string.Compare(constructedWebUrl, last.WebUrl, StringComparison.Ordinal) == 0);
            }

            Photo authPhoto = null;



            using (var authenticatedMock = new FakeFlickrRepository <PhotoRepository, Photo>())
            {
                var authRepo = MockManager.MockAll <AuthRepository>(Constructor.NotMocked);

                AuthToken token = new AuthToken
                {
                    FullName = "Mehfuz Hossain",
                    Id       = "1",
                    Perm     = "delete",
                    UserId   = "x@y"
                };

                authRepo.ExpectAndReturn("Authenticate", token, 1).Args(true, Permission.Delete);
                ///validates user call
                authenticatedMock.FakeGetNsidByUsername("neetulee");
                authenticatedMock.FakeElementCall("Linq.Flickr.Test.Responses.Owner.xml");

                var authQuery = from photo in context.Photos
                                where photo.ViewMode == ViewMode.Owner && photo.User == "neetulee"
                                select photo;

                authPhoto = authQuery.Last();

                Assert.IsTrue(authPhoto.ViewMode == ViewMode.Private);
                authRepo.Verify();
            }

            using (FakeFlickrRepository <PhotoRepository, Photo> authenticatedMockU = new FakeFlickrRepository <PhotoRepository, Photo>())
            {
                var authRepo = MockManager.MockAll <AuthRepository>(Constructor.Mocked);

                authRepo.ExpectAndReturn("Authenticate", "1234", 1).Args(Permission.Delete);

                const string updatedTitle = "NewTitle";

                // line verfies if the text is passed properly for update.
                authenticatedMockU.FakeSignatureCall("flickr.photos.setMeta", true, "photo_id", authPhoto.Id, "title", updatedTitle,
                                                     "description", authPhoto.Description ?? " ", "auth_token", "1234");

                authenticatedMockU.FakeDoHttpPostAndReturnStringResult(ResourceNs + ".DeletePhoto.xml");

                authPhoto.Title = updatedTitle;
                // will raise a update call.
                context.SubmitChanges();

                authRepo.Verify();
            }
        }