private async Task <IActionResult> HandleVideoUpload(string ulToken, Stream fileStream, long streamLength) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (videoStore.GetUploadModel(ulToken, out Video video)) { if (await this.User(db) is Admin) { video.Properties = await videoStore.StoreVideoAsync(fileStream, video.Properties, streamLength, HttpContext.RequestAborted); if (video.Properties != null) { db.Videos.Add(video); await db.SaveChangesAsync(); //Save and get Id video.StreamUrl = $"{StreamBaseUrl}{video.Id}"; await db.SaveChangesAsync(); //Update URL with Id return(Ok(video)); } } } return(BadRequest()); }
public async Task StoreVideoAsync_GivenEnvVideoRootAndMockedVideo_MockedVideoIsStored() { //arrange var webhost = new Mock <IWebHostEnvironment>(); var config = new Mock <IConfiguration>(); config.Setup(_ => _["VideoStoreRoot"]).Returns <IConfiguration, string>(null); webhost.Setup(_ => _.ContentRootPath).Returns(Directory.GetCurrentDirectory()); var service = new VideoStoreService(webhost.Object, config.Object); var video = MockVideoFactory(1024); var videoProps = new Model.VideoProperties(); using var cancel = new CancellationTokenSource(); //act await service.StoreVideoAsync(video, videoProps, 1024, cancel.Token); //assert File.Exists(Path.Combine(service.VideoRoot, videoProps.VirtualFilePath)).Should().BeTrue(); //clean await service.DeleteVideoAsync(videoProps); }