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
5 changes: 4 additions & 1 deletion Src/Notion.Client/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Notion.Client
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Notion.UnitTests")]
namespace Notion.Client
{
internal class Constants
{
Expand Down
2 changes: 2 additions & 0 deletions Src/Notion.Client/Models/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public class Page : IObject
public bool IsArchived { get; set; }

public IDictionary<string, PropertyValue> Properties { get; set; }

public string Url { get; set; }
}
}
52 changes: 52 additions & 0 deletions Test/Notion.UnitTests/ApiTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Notion.Client;
using WireMock.Matchers;
using WireMock.RequestBuilders;
using WireMock.Server;

namespace Notion.UnitTests
{
public class ApiTestBase : IDisposable
{
protected readonly WireMockServer Server;

protected static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings()
{
Formatting = Newtonsoft.Json.Formatting.Indented,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy()
}
};

protected readonly ClientOptions ClientOptions;

protected ApiTestBase()
{
Server = WireMockServer.Start();
ClientOptions = new ClientOptions()
{
BaseUrl = Server.Urls.First(),
AuthToken = "<Token>"
};
}

public void Dispose()
{
Server.Stop();
Server.Dispose();
}

protected IRequestBuilder CreateGetRequestBuilder(string path)
{
return Request.Create()
.WithPath(path)
.UsingGet()
.WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch)
.WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch);
}
}
}
8 changes: 8 additions & 0 deletions Test/Notion.UnitTests/Notion.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Microsoft.VisualStudio.VsixColorCompiler" Version="16.0.0" />
<PackageReference Include="WireMock.Net" Version="1.4.19" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -23,4 +25,10 @@
<ProjectReference Include="..\..\Src\Notion.Client\Notion.Client.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="data\pages\PageObjectShouldHaveUrlPropertyResponse.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions Test/Notion.UnitTests/PagesClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.IO;
using System.Threading.Tasks;
using Notion.Client;
using WireMock.ResponseBuilders;
using Xunit;

namespace Notion.UnitTests
{
public class PagesClientTests : ApiTestBase
{
private readonly IPagesClient _client;

public PagesClientTests()
{
_client = new PagesClient(new RestClient(ClientOptions));
}

[Fact]
public async Task PageObjectShouldHaveUrlProperty()
{
var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c";
var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId);
var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json");

Server.Given(CreateGetRequestBuilder(path))
.RespondWith(
Response.Create()
.WithStatusCode(200)
.WithBody(jsonData)
);

var page = await _client.RetrieveAsync(pageId);

Assert.Equal("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c", page.Url);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"object": "page",
"id": "251d2b5f-268c-4de2-afe9-c71ff92ca95c",
"created_time": "2020-03-17T19:10:04.968Z",
"last_edited_time": "2020-03-17T21:49:37.913Z",
"parent": {
"type": "database_id",
"database_id": "48f8fee9-cd79-4180-bc2f-ec0398253067"
},
"archived": false,
"url": "https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c",
"properties": {
"Name": {
"id": "title",
"type": "title",
"title": [
{
"type": "text",
"text": {
"content": "Avocado",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Avocado",
"href": null
}
]
}
}
}