Пример #1
0
        public void getAndPostRatingTest()
        {
            bool success = false;

            // Insert test user
            User testUser = new User(0, "*****@*****.**", "testpass", null);
            int userId = restService.insertUser(testUser);
            userIdList.Add(userId);

            // Insert test media
            Media testMedia = new Media(0, 2, userId, "FileLocation", "test title", "some description", 223, "avi");
            int mediaId = restService.postMedia(testMedia);
            mediaIdList.Add(mediaId);

            // Insert new rating
            Rating testRating = new Rating(0, userId, mediaId, 3, "title of test comment", "content of test comment");
            restService.postRating(testRating);

            Rating[] checkRating = restService.getRating(mediaId.ToString(), userId.ToString());

            // Check that there is only one rating and that it matches the inserted rating.
            if (checkRating.Length == 1 && checkRating[0].commentTitle == testRating.commentTitle) {
                success = true;
            }
            Assert.IsTrue(success);
        }
        public Response<Rating> postRating(Rating rating)
        {
            IncomingWebRequestContext requestContext = WebOperationContext.Current.IncomingRequest;

            Dictionary<string, string> data = new Dictionary<string, string>();

            string authString = requestContext.Headers[HttpRequestHeader.Authorization];

            data.Add("media_id", rating.mediaId.ToString());
            data.Add("user_account_id", rating.userId.ToString());
            data.Add("comment", rating.comment);
            data.Add("comment_title", rating.commentTitle);
            data.Add("rating", rating.rating.ToString());

            Request request = makeRequest(requestContext, trimData(data), authString);

            RatingController controller = new RatingController();

            return controller.Call(request);
        }