Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class CreateFileUploadRequest : ICreateFileUploadBodyParameters
{
public FileUploadMode Mode { get; set; }

public string Filename { get; set; }
public string FileName { get; set; }

public string ContentType { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface ICreateFileUploadBodyParameters
/// from the content_type parameter.
/// </summary>
[JsonProperty("filename")]
string Filename { get; }
string FileName { get; }

/// <summary>
/// MIME type of the file to be created. Recommended when sending the file in multiple parts.
Expand Down
2 changes: 1 addition & 1 deletion Test/Notion.IntegrationTests/FIleUploadsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public async Task CreateAsync()
{
Mode = FileUploadMode.ExternalUrl,
ExternalUrl = "https://unsplash.com/photos/hOhlYhAiizc/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzYwMTkxNzc3fA&force=true",
Filename = "sample-image.jpg",
FileName = "sample-image.jpg",
};

// Act
Expand Down
70 changes: 70 additions & 0 deletions Test/Notion.UnitTests/FileUploadClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using Moq.AutoMock;
using Newtonsoft.Json;
using Notion.Client;
using Xunit;

namespace Notion.UnitTests;

public class FileUploadClientTests
{
private readonly AutoMocker _mocker = new();
private readonly FileUploadsClient _fileUploadClient;
private readonly Mock<IRestClient> _restClientMock;

public FileUploadClientTests()
{
_restClientMock = _mocker.GetMock<IRestClient>();
_fileUploadClient = _mocker.CreateInstance<FileUploadsClient>();
}

[Fact]
public async Task CreateAsync_ThrowsArgumentNullException_WhenRequestIsNull()
{
// Act & Assert
var exception = await Assert.ThrowsAsync<ArgumentNullException>(() => _fileUploadClient.CreateAsync(null));
Assert.Equal("fileUploadObjectRequest", exception.ParamName);
Assert.Equal("Value cannot be null. (Parameter 'fileUploadObjectRequest')", exception.Message);
}

[Fact]
public async Task CreateAsync_CallsRestClientPostAsync_WithCorrectParameters()
{
// Arrange
var request = new CreateFileUploadRequest
{
FileName = "testfile.txt",
Mode = FileUploadMode.SinglePart,
};

var expectedResponse = new CreateFileUploadResponse
{
UploadUrl = "https://example.com/upload",
Id = Guid.NewGuid().ToString(),
};

_restClientMock
.Setup(client => client.PostAsync<CreateFileUploadResponse>(
It.Is<string>(url => url == ApiEndpoints.FileUploadsApiUrls.Create()),
It.IsAny<ICreateFileUploadBodyParameters>(),
It.IsAny<IEnumerable<KeyValuePair<string, string>>>(),
It.IsAny<IDictionary<string, string>>(),
It.IsAny<JsonSerializerSettings>(),
It.IsAny<IBasicAuthenticationParameters>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync(expectedResponse);

// Act
var response = await _fileUploadClient.CreateAsync(request);

// Assert
Assert.Equal(expectedResponse.UploadUrl, response.UploadUrl);
Assert.Equal(expectedResponse.Id, response.Id);

_restClientMock.VerifyAll();
}
}
Loading