public async Task UploadFile_FromFileProvider_ExpectedSkylink() { // Arrange var fileProvider = new EmbeddedFileProvider(Assembly.GetExecutingAssembly()); // Act var skylink = await _skynetWebPortal.UploadFile(fileProvider, "assets/test-file.txt"); // Assert Assert.That(skylink.ToString() == "AAAox419FTqN04JIo3urNNtyxwY9i61cZVnbwNlhGluwOQ"); }
public async Task UploadFile_Request_CorrectUri() { // Arrange var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict).SetupHttpResponse(HttpStatusCode.OK, JsonSerializer.Serialize(ValidUploadResponse)); var httpClient = SetUpHttpClient(handlerMock.Object); var webPortalClient = new SkynetWebPortal(httpClient); var fileMock = new Mock <IFileInfo>().SetupValidFile(); // Act await webPortalClient.UploadFile(new UploadItem(fileMock.Object)); // Assert var expectedUriWithoutQuery = "https://siasky.net/skynet/skyfile"; handlerMock .Protected() .Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri.GetLeftPart(UriPartial.Path) == expectedUriWithoutQuery ), ItExpr.IsAny <CancellationToken>() ); }
public void UploadFile_FileProviderIsOfTypeNullFileProvider_ThrowsArgumentException() { // Arrange using var httpClient = SetUpHttpClientThatReturns(HttpStatusCode.OK, JsonSerializer.Serialize(ValidUploadResponse)); var webPortalClient = new SkynetWebPortal(httpClient); // Act Task UploadRequest() => webPortalClient.UploadFile(new NullFileProvider(), "foo.txt"); // Assert Assert.That(UploadRequest, Throws.ArgumentException); }
public void UploadFile_UploadItemIsNull_ThrowsArgumentNullException() { // Arrange using var httpClient = SetUpHttpClientThatReturns(HttpStatusCode.OK, JsonSerializer.Serialize(ValidUploadResponse)); var webPortalClient = new SkynetWebPortal(httpClient); // Act Task UploadRequest() => webPortalClient.UploadFile(null as UploadItem); // Assert Assert.That(UploadRequest, Throws.ArgumentNullException); }
public void UploadFile_FileExistsInvalidUploadResponse_ThrowsHttpResponseException() { // Arrange using var httpClient = SetUpHttpClientThatReturns(HttpStatusCode.OK, JsonSerializer.Serialize(InvalidUploadResponse)); var webPortalClient = new SkynetWebPortal(httpClient); var fileProvider = SetUpFileProvider(); // Act Task UploadRequest() => webPortalClient.UploadFile(fileProvider, "exists.txt"); // Assert Assert.That(UploadRequest, Throws.TypeOf <HttpResponseException>()); }
public void UploadFile_FilePathIsWhitespace_ThrowsArgumentException(string filePath) { // Arrange using var httpClient = SetUpHttpClientThatReturns(HttpStatusCode.OK, JsonSerializer.Serialize(ValidUploadResponse)); var webPortalClient = new SkynetWebPortal(httpClient); var fileProvider = SetUpFileProvider(); // Act Task UploadRequest() => webPortalClient.UploadFile(fileProvider, filePath); // Assert Assert.That(UploadRequest, Throws.ArgumentException); }
public async Task UploadFile_FileInfoIsValidFile_ReturnsSkylink() { // Arrange using var httpClient = SetUpHttpClientThatReturns(HttpStatusCode.OK, JsonSerializer.Serialize(ValidUploadResponse)); var webPortalClient = new SkynetWebPortal(httpClient); var fileMock = new Mock <IFileInfo>().SetupValidFile(); // Act var response = await webPortalClient.UploadFile(fileMock.Object); // Assert Assert.That(response, Is.EqualTo(Skylink.Parse(ValidUploadResponse.Skylink))); }
public void UploadFile_FileInfoIsValidFile_ThrowsNothing() { // Arrange using var httpClient = SetUpHttpClientThatReturns(HttpStatusCode.OK, JsonSerializer.Serialize(ValidUploadResponse)); var webPortalClient = new SkynetWebPortal(httpClient); var fileMock = new Mock <IFileInfo>().SetupValidFile(); // Act Task UploadRequest() => webPortalClient.UploadFile(fileMock.Object); // Assert Assert.That(UploadRequest, Throws.Nothing); }
public void UploadFile_FileInfoIsNotFoundFileInfo_ThrowsArgumentException() { // Arrange using var httpClient = SetUpHttpClientThatReturns(HttpStatusCode.OK, JsonSerializer.Serialize(ValidUploadResponse)); var webPortalClient = new SkynetWebPortal(httpClient); var fileProvider = SetUpFileProvider(); // Act Task UploadRequest() => webPortalClient.UploadFile(new NotFoundFileInfo("doesnotexist.txt")); // Assert Assert.That(UploadRequest, Throws.ArgumentException); }
public async Task UploadFile_FileExists_ReturnsSkylink() { // Arrange using var httpClient = SetUpHttpClientThatReturns(HttpStatusCode.OK, JsonSerializer.Serialize(ValidUploadResponse)); var webPortalClient = new SkynetWebPortal(httpClient); var fileProvider = SetUpFileProvider(); // Act var response = await webPortalClient.UploadFile(fileProvider, "exists.txt"); // Assert Assert.That(response, Is.EqualTo(Skylink.Parse(ValidUploadResponse.Skylink))); }
public void UploadFile_UploadItemIsNotNullInvalidUploadResponse_ThrowsHttpResponseException() { // Arrange using var httpClient = SetUpHttpClientThatReturns(HttpStatusCode.OK, JsonSerializer.Serialize(InvalidUploadResponse)); var webPortalClient = new SkynetWebPortal(httpClient); var fileMock = new Mock <IFileInfo>().SetupValidFile(); var uploadItem = new UploadItem(fileMock.Object); // Act Task UploadRequest() => webPortalClient.UploadFile(uploadItem); // Assert Assert.That(UploadRequest, Throws.TypeOf <HttpResponseException>()); }