public void File_CanSupplySingle() { var file = new BrowserFile(); var instance = new InputFileChangeEventArgs(new[] { file }); Assert.Same(file, instance.File); }
public void OpenReadStream_ReturnsStreamWhoseDisposalReleasesTheJSObject() { // Arrange: JS runtime that always returns a specific mock IJSStreamReference var jsRuntime = new Mock <IJSRuntime>(MockBehavior.Strict); var jsStreamReference = new Mock <IJSStreamReference>(); jsRuntime.Setup(x => x.InvokeAsync <IJSStreamReference>(It.IsAny <string>(), It.IsAny <CancellationToken>(), It.IsAny <object[]>())) .Returns(ValueTask.FromResult(jsStreamReference.Object)); // Arrange: InputFile var inputFile = new InputFile { JSRuntime = jsRuntime.Object }; var file = new BrowserFile { Owner = inputFile, Size = 5 }; var stream = file.OpenReadStream(); // Assert 1: IJSStreamReference isn't disposed yet jsStreamReference.Verify(x => x.DisposeAsync(), Times.Never); // Act _ = stream.DisposeAsync(); // Assert: IJSStreamReference is disposed now jsStreamReference.Verify(x => x.DisposeAsync()); }
public void SetSize_ThrowsIfSizeIsNegative() { // Arrange var file = new BrowserFile(); // Act & Assert var ex = Assert.Throws <ArgumentOutOfRangeException>(() => file.Size = -7); }
internal async ValueTask <IBrowserFile> ConvertToImageFileAsync(BrowserFile file, string format, int maxWidth, int maxHeight) { var imageFile = await JSRuntime.InvokeAsync <BrowserFile>(InputFileInterop.ToImageFile, _inputFileElement, file.Id, format, maxWidth, maxHeight); imageFile.Owner = this; return(imageFile); }
public void OpenReadStream_ThrowsIfFileSizeIsLargerThanAllowedSize() { // Arrange var file = new BrowserFile { Size = 100 }; // Act & Assert var ex = Assert.Throws <IOException>(() => file.OpenReadStream(80)); Assert.Equal("Supplied file with size 100 bytes exceeds the maximum of 80 bytes.", ex.Message); }
internal async ValueTask <IBrowserFile> ConvertToImageFileAsync(BrowserFile file, string format, int maxWidth, int maxHeight) { var imageFile = await JSRuntime.InvokeAsync <BrowserFile>(InputFileInterop.ToImageFile, _inputFileElement, file.Id, format, maxWidth, maxHeight); if (imageFile is null) { throw new InvalidOperationException("ToImageFile returned an unexpected null result."); } imageFile.Owner = this; return(imageFile); }
public BrowserFileStream( IJSRuntime jsRuntime, ElementReference inputFileElement, BrowserFile file, long maxAllowedSize, CancellationToken cancellationToken) { _jsRuntime = jsRuntime; _inputFileElement = inputFileElement; _file = file; _maxAllowedSize = maxAllowedSize; _openReadStreamCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); OpenReadStreamTask = OpenReadStreamAsync(_openReadStreamCts.Token); }
public RemoteBrowserFileStream( IJSRuntime jsRuntime, ElementReference inputFileElement, BrowserFile file, RemoteBrowserFileStreamOptions options, CancellationToken cancellationToken) : base(file) { _jsRuntime = jsRuntime; _inputFileElement = inputFileElement; _maxSegmentSize = options.MaxSegmentSize; _segmentFetchTimeout = options.SegmentFetchTimeout; var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: options.MaxBufferSize, resumeWriterThreshold: options.MaxBufferSize)); _pipeReader = pipe.Reader; _fillBufferCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); _ = FillBuffer(pipe.Writer, _fillBufferCts.Token); }
public async Task OpenReadStream_ReturnsStreamWhoseDisposalReleasesTheJSObject_ToleratesDisposalException() { // Arrange: JS runtime that always returns a specific mock IJSStreamReference whose disposal throws var jsRuntime = new Mock <IJSRuntime>(MockBehavior.Strict); var jsStreamReference = new Mock <IJSStreamReference>(); jsRuntime.Setup(x => x.InvokeAsync <IJSStreamReference>(It.IsAny <string>(), It.IsAny <CancellationToken>(), It.IsAny <object[]>())) .Returns(ValueTask.FromResult(jsStreamReference.Object)); jsStreamReference.Setup(x => x.DisposeAsync()).Throws(new InvalidTimeZoneException()); // Arrange: InputFile var inputFile = new InputFile { JSRuntime = jsRuntime.Object }; var file = new BrowserFile { Owner = inputFile, Size = 5 }; var stream = file.OpenReadStream(); // Act/Assert. Not throwing is success here. await stream.DisposeAsync(); }
internal Stream OpenReadStream(BrowserFile file, CancellationToken cancellationToken) => _jsUnmarshalledRuntime != null ? (Stream) new SharedBrowserFileStream(JSRuntime, _jsUnmarshalledRuntime, _inputFileElement, file) : new RemoteBrowserFileStream(JSRuntime, _inputFileElement, file, Options.Value, cancellationToken);
protected BrowserFileStream(BrowserFile file) { File = file; }
public SharedBrowserFileStream(IJSRuntime jsRuntime, IJSUnmarshalledRuntime jsUnmarshalledRuntime, ElementReference inputFileElement, BrowserFile file) : base(file) { _jsRuntime = jsRuntime; _jsUnmarshalledRuntime = jsUnmarshalledRuntime; _inputFileElement = inputFileElement; }