示例#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);
        }
示例#2
0
 public void deleteMediaTest()
 {
     Media testMedia = new Media(0, 2, 18, "fileLocation", "title", "desc", 22, "avi");
     int id = restService.postMedia(testMedia);
     restService.deleteMedia(id.ToString());
     Media checkMedia = restService.getMedia(id.ToString());
     Assert.AreEqual(null, checkMedia);
 }
        public static void insertMediaFile(DatabaseConnection db, Stream file, int id, Permissions per)
        {
            PreparedStatement stmt1 = db.Prepare("SELECT * FROM media WHERE id = " + id.ToString());
            SqlDataReader reader = db.Query(null, stmt1);
            Media mediaMeta = null;
            while (reader.Read())
            {
                int mediaId = reader.GetInt32(reader.GetOrdinal("id"));
                int mediaCategory = reader.GetInt32(reader.GetOrdinal("media_category_id"));
                int user = reader.GetInt32(reader.GetOrdinal("user_account_id"));
                string mediaFileLocation = reader.GetString(reader.GetOrdinal("file_location"));
                string title = reader.GetString(reader.GetOrdinal("title"));
                string description = reader.GetString(reader.GetOrdinal("description"));
                int mediaLength = reader.GetInt32(reader.GetOrdinal("minutes"));
                string format = reader.GetString(reader.GetOrdinal("format"));

                mediaMeta = new Media(mediaId, mediaCategory, user, mediaFileLocation, title, description, mediaLength, format);
            }
            reader.Close();

            string fileLocation = @"C:\RentItServices\Rentit26\MediaFiles\" + mediaMeta.id.ToString();
            System.IO.Directory.CreateDirectory(fileLocation);
            string fileDir = fileLocation + @"\" + mediaMeta.title + "." + mediaMeta.format;

            FileStream writer = new FileStream(fileDir, FileMode.Create, FileAccess.Write);

            byte[] bytes = new Byte[4096];

            int bytesRead = 0;

            while ((bytesRead = file.Read(bytes, 0, bytes.Length)) != 0)
            {
                writer.Write(bytes, 0, bytesRead);
            }

            file.Close();
            writer.Close();

            string fileStream = "http://rentit.itu.dk/RentIt26/MediaFiles/" + mediaMeta.id.ToString() + "/" + mediaMeta.title + "." + mediaMeta.format;

            PreparedStatement stmt2 = db.Prepare("UPDATE media SET file_location = '"+fileStream+"' WHERE id = "+mediaMeta.id.ToString());

            db.Command(null, stmt2);
        }
        public Response<Media> putMedia(Media media, string id)
        {
            IncomingWebRequestContext requestContext = WebOperationContext.Current.IncomingRequest;

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

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

            data.Add("id", id);
            data.Add("type", "");
            data.Add("description", media.description);
            data.Add("format", media.format);
            data.Add("media_category_id", media.mediaCategory.ToString());
            data.Add("minutes", media.mediaLength.ToString());
            data.Add("title", media.title);
            data.Add("user_account_id", media.user.ToString()); ;

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

            MediaController controller = new MediaController();

            return controller.Call(request);
        }
示例#5
0
 public MediaList(int pageCount, Media[] medias)
 {
     this.pageCount = pageCount;
     this.medias = medias;
 }
示例#6
0
 public void insertAndGetMediaTest()
 {
     Media testMedia = new Media(0, 2, 18, "someFileLocation", "someTitle", "someDescription", 22, "avi");
     int id = restService.postMedia(testMedia);
     idList.Add(id);
     Media checkMedia = restService.getMedia(id.ToString());
     Assert.AreEqual(testMedia.title, checkMedia.title);
 }
示例#7
0
 public void updateMediaTest()
 {
     Media testMedia = new Media(0, 2, 18, "someFileLocation", "titleTest", "desc", 22, "mpg");
     int id = restService.postMedia(testMedia);
     idList.Add(id);
     Media editMedia = new Media(id, 3, 18, "lol", "editedTitle", "editedDesc", 22, "mpg");
     restService.putMedia(editMedia, id.ToString());
     testMedia = restService.getMedia(id.ToString());
     Assert.AreEqual(editMedia.title, testMedia.title);
 }