BrowserFileTest.cs 987 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using System.IO;
  5. using Xunit;
  6. namespace Microsoft.AspNetCore.Components.Forms
  7. {
  8. public class BrowserFileTest
  9. {
  10. [Fact]
  11. public void SetSize_ThrowsIfSizeIsNegative()
  12. {
  13. // Arrange
  14. var file = new BrowserFile();
  15. // Act & Assert
  16. var ex = Assert.Throws<ArgumentOutOfRangeException>(() => file.Size = -7);
  17. }
  18. [Fact]
  19. public void OpenReadStream_ThrowsIfFileSizeIsLargerThanAllowedSize()
  20. {
  21. // Arrange
  22. var file = new BrowserFile { Size = 100 };
  23. // Act & Assert
  24. var ex = Assert.Throws<IOException>(() => file.OpenReadStream(80));
  25. Assert.Equal("Supplied file with size 100 bytes exceeds the maximum of 80 bytes.", ex.Message);
  26. }
  27. }
  28. }