Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to file-scoped namespaces, add global using #35

Merged
merged 1 commit into from
Jul 17, 2023
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 @@ -2,29 +2,28 @@
using IIIF.Auth.V1.AccessTokenService;
using Xunit;

namespace IIIF.Tests.Auth.V1.AccessTokenService
namespace IIIF.Tests.Auth.V1.AccessTokenService;

public class AccessTokenErrorTests
{
public class AccessTokenErrorTests
[Theory]
[InlineData(AccessTokenErrorConditions.InvalidRequest,
"The service could not process the information sent in the body of the request.")]
[InlineData(AccessTokenErrorConditions.MissingCredentials,
"The request did not have the credentials required.")]
[InlineData(AccessTokenErrorConditions.InvalidCredentials,
"The request had credentials that are not valid for the service.")]
[InlineData(AccessTokenErrorConditions.InvalidOrigin,
"The request came from a different origin than that specified in the access cookie service request, or an origin that the server rejects for other reasons.")]
[InlineData(AccessTokenErrorConditions.Unavailable,
"The request could not be fulfilled for reasons other than those listed above, such as scheduled maintenance.")]
public void Ctor_ErrorOnly_UsesDefaultDescription(AccessTokenErrorConditions error, string description)
{
[Theory]
[InlineData(AccessTokenErrorConditions.InvalidRequest,
"The service could not process the information sent in the body of the request.")]
[InlineData(AccessTokenErrorConditions.MissingCredentials,
"The request did not have the credentials required.")]
[InlineData(AccessTokenErrorConditions.InvalidCredentials,
"The request had credentials that are not valid for the service.")]
[InlineData(AccessTokenErrorConditions.InvalidOrigin,
"The request came from a different origin than that specified in the access cookie service request, or an origin that the server rejects for other reasons.")]
[InlineData(AccessTokenErrorConditions.Unavailable,
"The request could not be fulfilled for reasons other than those listed above, such as scheduled maintenance.")]
public void Ctor_ErrorOnly_UsesDefaultDescription(AccessTokenErrorConditions error, string description)
{
// Arrange
var accessTokenError = new AccessTokenError(error);
// Arrange
var accessTokenError = new AccessTokenError(error);

// Assert
accessTokenError.Error.Should().Be(error);
accessTokenError.Description.Should().Be(description);
}
// Assert
accessTokenError.Error.Should().Be(error);
accessTokenError.Description.Should().Be(description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,37 @@
using Newtonsoft.Json;
using Xunit;

namespace IIIF.Tests.Auth.V1.AccessTokenService
namespace IIIF.Tests.Auth.V1.AccessTokenService;

public class AccessTokenResponseTests
{
public class AccessTokenResponseTests
{
private readonly JsonSerializerSettings jsonSerializerSettings;
private readonly JsonSerializerSettings jsonSerializerSettings;

public AccessTokenResponseTests()
public AccessTokenResponseTests()
{
// NOTE: Using JsonSerializerSettings to facilitate testing as it makes it a LOT easier
jsonSerializerSettings = new JsonSerializerSettings
{
// NOTE: Using JsonSerializerSettings to facilitate testing as it makes it a LOT easier
jsonSerializerSettings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new PrettyIIIFContractResolver(),
};
}
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new PrettyIIIFContractResolver()
};
}

[Theory]
[InlineData(AccessTokenErrorConditions.InvalidRequest, "invalidRequest")]
[InlineData(AccessTokenErrorConditions.MissingCredentials, "missingCredentials")]
[InlineData(AccessTokenErrorConditions.InvalidCredentials, "invalidCredentials")]
[InlineData(AccessTokenErrorConditions.InvalidOrigin, "invalidOrigin")]
[InlineData(AccessTokenErrorConditions.Unavailable, "unavailable")]
public void AccessTokenError_ReturnsExpectedJson(AccessTokenErrorConditions error, string description)
{
// Arrange
var accessTokenError = new AccessTokenError(error, "test description");
var expected = $"{{\"error\":\"{description}\",\"description\":\"test description\"}}";
[Theory]
[InlineData(AccessTokenErrorConditions.InvalidRequest, "invalidRequest")]
[InlineData(AccessTokenErrorConditions.MissingCredentials, "missingCredentials")]
[InlineData(AccessTokenErrorConditions.InvalidCredentials, "invalidCredentials")]
[InlineData(AccessTokenErrorConditions.InvalidOrigin, "invalidOrigin")]
[InlineData(AccessTokenErrorConditions.Unavailable, "unavailable")]
public void AccessTokenError_ReturnsExpectedJson(AccessTokenErrorConditions error, string description)
{
// Arrange
var accessTokenError = new AccessTokenError(error, "test description");

var expected = $"{{\"error\":\"{description}\",\"description\":\"test description\"}}";

var actual = JsonConvert.SerializeObject(accessTokenError, jsonSerializerSettings);
var actual = JsonConvert.SerializeObject(accessTokenError, jsonSerializerSettings);

actual.Should().Be(expected);
}
actual.Should().Be(expected);
}
}
33 changes: 16 additions & 17 deletions src/IIIF/IIIF.Tests/Auth/V2/ContentResourceWithAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
using IIIF.Serialisation;
using Xunit;

namespace IIIF.Tests.Auth.V2
namespace IIIF.Tests.Auth.V2;

public class ContentResourceWithAuthTest
{
public class ContentResourceWithAuthTest
[Fact]
public void ContentResource_Can_Have_Auth_Services()
{
[Fact]
public void ContentResource_Can_Have_Auth_Services()
// Arrange
var res = new ExternalResource("Text")
{
// Arrange
var res = new ExternalResource("Text")
{
Id = "https://example.com/documents/my.pdf",
Service = ReusableParts.Auth2Services
};

// Act
var json = res.AsJson().Replace("\r\n", "\n");
const string expected = @"{
Id = "https://example.com/documents/my.pdf",
Service = ReusableParts.Auth2Services
};

// Act
var json = res.AsJson().Replace("\r\n", "\n");
const string expected = @"{
""id"": ""https://example.com/documents/my.pdf"",
""type"": ""Text""," + ReusableParts.ExpectedServiceAsArray + @"
}";
// Assert
json.Should().BeEquivalentTo(expected);
}
// Assert
json.Should().BeEquivalentTo(expected);
}
}
67 changes: 33 additions & 34 deletions src/IIIF/IIIF.Tests/Auth/V2/ImageServiceWithAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,47 @@
using IIIF.Serialisation;
using Xunit;

namespace IIIF.Tests.Auth.V2
namespace IIIF.Tests.Auth.V2;

public class ImageServiceWithAuthTest
{
public class ImageServiceWithAuthTest
[Fact]
public void ImageService2_Can_Have_Auth_Services()
{
[Fact]
public void ImageService2_Can_Have_Auth_Services()
// Arrange
var imgService2 = new ImageService2
{
// Arrange
var imgService2 = new ImageService2
{
Id = "https://example.com/image/service",
Service = ReusableParts.Auth2Services
};

// Act
var json = imgService2.AsJson().Replace("\r\n", "\n");
string expected = @"{
Id = "https://example.com/image/service",
Service = ReusableParts.Auth2Services
};

// Act
var json = imgService2.AsJson().Replace("\r\n", "\n");
var expected = @"{
""@id"": ""https://example.com/image/service"",
""@type"": ""ImageService2""," + ReusableParts.GetExpectedServiceAsSingle() + "}";
// Assert
json.Should().BeEquivalentTo(expected);
}


[Fact]
public void ImageService3_Can_Have_Auth_Services()
// Assert
json.Should().BeEquivalentTo(expected);
}


[Fact]
public void ImageService3_Can_Have_Auth_Services()
{
// Arrange
var imgService3 = new ImageService3
{
// Arrange
var imgService3 = new ImageService3
{
Id = "https://example.com/image/service",
Service = ReusableParts.Auth2Services
};

// Act
var json = imgService3.AsJson().Replace("\r\n", "\n");
const string expected = @"{
Id = "https://example.com/image/service",
Service = ReusableParts.Auth2Services
};

// Act
var json = imgService3.AsJson().Replace("\r\n", "\n");
const string expected = @"{
""id"": ""https://example.com/image/service"",
""type"": ""ImageService3""," + ReusableParts.ExpectedServiceAsArray + @"
}";
// Assert
json.Should().BeEquivalentTo(expected);
}
// Assert
json.Should().BeEquivalentTo(expected);
}
}
Loading
Loading