public void ClearDb()
 {
     using (var context = new scriberContext(options))
     {
         // clear the db
         context.Transcription.RemoveRange(context.Transcription);
         context.SaveChanges();
     };
 }
 public void SetupDb()
 {
     using (var context = new scriberContext(options))
     {
         context.Transcription.Add(transcriptions[0]);
         context.Transcription.Add(transcriptions[1]);
         context.SaveChanges();
     }
 }
예제 #3
0
 public void SetupDb()
 {
     using (var context = new scriberContext(options))
     {
         // populate the db
         context.Tasks.Add(datavalues[0]);
         context.Tasks.Add(datavalues[1]);
         context.SaveChanges();
     }
 }
        public async Task TestGetSuccessfully()
        {
            using (var context = new scriberContext(options))
            {
                TranscriptionsController transcriptionsController  = new TranscriptionsController(context);
                ActionResult <IEnumerable <Transcription> > result = await transcriptionsController.GetTranscription();

                Assert.IsNotNull(result);
            }
        }
        public async Task <ActionResult <Video> > PostVideo([FromBody] URLDTO data)
        {
            String videoURL;
            String videoId;
            Video  video;

            try
            {
                // Constructing the video object from our helper function
                videoURL = data.URL;
                videoId  = YouTubeHelper.GetVideoIdFromURL(videoURL);
                video    = YouTubeHelper.GetVideoInfo(videoId);
            } catch {
                return(BadRequest("Invalid YouTube URL"));
            }

            // Determine if we can get transcriptions from YouTube
            if (!YouTubeHelper.CanGetTranscriptions(videoId))
            {
                return(BadRequest("Subtitle does not exist on YouTube, failed to add video"));
            }

            // Add this video object to the database
            _context.Video.Add(video);
            await _context.SaveChangesAsync();

            // Get the primary key of the newly created video record
            int id = video.VideoId;

            // This is needed because context are NOT thread safe, therefore we create another context for the following task.
            // We will be using this to insert transcriptions into the database on a seperate thread
            // So that it doesn't block the API.
            scriberContext           tempContext = new scriberContext();
            TranscriptionsController transcriptionsController = new TranscriptionsController(tempContext);

            // This will be executed in the background.
            Task addCaptions = Task.Run(async() =>
            {
                List <Transcription> transcriptions = new List <Transcription>();
                transcriptions = YouTubeHelper.GetTranscriptions(videoId);

                for (int i = 0; i < transcriptions.Count; i++)
                {
                    // Get the transcription objects form transcriptions and assign VideoId to id, the primary key of the newly inserted video
                    Transcription transcription = transcriptions.ElementAt(i);
                    transcription.VideoId       = id;
                    // Add this transcription to the database
                    await transcriptionsController.PostTranscription(transcription);
                }
            });

            // Return success code and the info on the video object
            return(CreatedAtAction("GetVideo", new { id = video.VideoId }, video));
        }
        public async Task TestGetSuccessfully()
        {
            using (var context = new scriberContext(options))
            {
                TranscriptionsController transcriptionsController  = new TranscriptionsController(context);
                ActionResult <IEnumerable <Transcription> > result = await transcriptionsController.GetTranscription();

                Assert.IsNotNull(result);
                // i should really check to make sure the exact transcriptions are in there, but that requires an equality comparer,
                // which requires a whole nested class, thanks to C#'s lack of anonymous classes that implement interfaces
            }
        }
        public async Task TestPutTranscriptionNoContentStatus()
        {
            using (var context = new scriberContext(options))
            {
                string        title          = "this is now a different phrase";
                Transcription transcription1 = context.Transcription.Where(x => x.Phrase == transcriptions[0].Phrase).Single();
                transcription1.Phrase = title;

                TranscriptionsController transcriptionsController = new TranscriptionsController(context);
                IActionResult            result = await transcriptionsController.PutTranscription(transcription1.TranscriptionId, transcription1) as IActionResult;

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(NoContentResult));
            }
        }
예제 #8
0
        public async Task TestPutTasksNoContentStatusCode()
        {
            using (var context = new scriberContext(options))
            {
                string newPhrase = "New Task 5";
                Tasks  tasks1    = context.Tasks.Where(x => x.TaskName == datavalues[0].TaskName).Single();
                //tasks1 = datavalues[0];
                tasks1.TaskName = newPhrase;

                TasksController tasksController1 = new TasksController(context);
                IActionResult   result           = await tasksController1.PutTasks(tasks1.TaskId, tasks1);

                // PutTasks(tasks1.TaskId, tasks1) as IActionResult

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(NoContentResult));
            }
        }
예제 #9
0
        public async Task <ActionResult <Video> > PostVideo([FromBody] URLDTO data)
        {
            Video  video;
            String videoURL;
            String videoId;

            try
            {
                videoURL = data.URL;
                videoId  = YouTubeHelper.GetVideoIdFromURL(videoURL);
                video    = YouTubeHelper.GetVideoInfo(videoId);
            } catch
            {
                return(BadRequest("Invalid YouTube URL"));
            }
            _context.Video.Add(video);
            await _context.SaveChangesAsync();

            int id = video.VideoId;

            scriberContext           tempContext = new scriberContext();
            TranscriptionsController transcriptionsController = new TranscriptionsController(tempContext);

            Task addCaptions = Task.Run(async() =>
            {
                List <Transcription> transcriptions = new List <Transcription>();
                transcriptions = YouTubeHelper.GetTranscriptions(videoId);

                for (int i = 0; i < transcriptions.Count; i++)
                {
                    Transcription transcription = transcriptions.ElementAt(i);
                    transcription.VideoId       = id;
                    await transcriptionsController.PostTranscription(transcription);
                }
            });

            return(CreatedAtAction("GetVideo", new { id = video.VideoId }, video));
        }
예제 #10
0
 public TranscriptionsController(scriberContext context)
 {
     _context = context;
 }
 public VideosController(scriberContext context)
 {
     _context = context;
 }
예제 #12
0
 public VideosController(scriberContext context, IMapper mapper)
 {
     _context             = context;
     _mapper              = mapper;
     this.videoRepository = new VideoRepository(new scriberContext());
 }
예제 #13
0
 public VideoRepository(scriberContext context)
 {
     this.context = context;
 }
예제 #14
0
 public TasksController(scriberContext context)
 {
     _context = context;
 }