Skip to content

Commit

Permalink
fix: deserializng nullable DateTime
Browse files Browse the repository at this point in the history
- Fix for issue in deserializing nullable DateTime (#5)
  • Loading branch information
adriantam committed Oct 7, 2022
1 parent e5e2d8e commit 3f69211
Show file tree
Hide file tree
Showing 51 changed files with 234 additions and 104 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.1.1

### [0.1.1](https://github.com/openfga/dotnet-sdk/compare/v0.1.0...v0.1.1) (2022-10-07)

- Fix for issue in deserializing nullable DateTime (https://github.com/openfga/dotnet-sdk/issues/5)

## v0.1.0

### [0.1.0](https://github.com/openfga/dotnet-sdk/compare/v0.0.3...v0.1.0) (2022-09-29)
Expand Down
124 changes: 124 additions & 0 deletions src/OpenFga.Sdk.Test/Api/OpenFgaApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,5 +1151,129 @@ public async Task ReadAssertionsTest() {
Assert.Equal(authorizationModelId, response.AuthorizationModelId);
Assert.Empty(response.Assertions);
}

/// <summary>
/// Test ListStores
/// </summary>
[Fact]
public async Task ListStoresTest() {
var mockHandler = new Mock<HttpMessageHandler>(MockBehavior.Strict);
var expectedResponse = new ListStoresResponse() {
Stores = new List<Store>() {
new() { Id = "45678", Name = "TestStore", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now}
}
};
mockHandler.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri ==
new Uri($"{_config.BasePath}/stores") &&
req.Method == HttpMethod.Get),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(expectedResponse),
});

var httpClient = new HttpClient(mockHandler.Object);
var openFgaApi = new OpenFgaApi(_config, httpClient);

var response = await openFgaApi.ListStores();
mockHandler.Protected().Verify(
"SendAsync",
Times.Exactly(1),
ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri == new Uri($"{_config.BasePath}/stores") &&
req.Method == HttpMethod.Get),
ItExpr.IsAny<CancellationToken>()
);
Assert.IsType<ListStoresResponse>(response);
Assert.Single(response.Stores);
Assert.Equal(response, expectedResponse);
}


/// <summary>
/// Test ListStores with Null DateTime
/// </summary>
[Fact]
public async Task ListStoresTestNullDeletedAt() {
var mockHandler = new Mock<HttpMessageHandler>(MockBehavior.Strict);
var content = "{ \"stores\": [{\"id\": \"xyz123\", \"name\": \"abcdefg\", \"created_at\": \"2022-10-07T14:00:40.205Z\", \"updated_at\": \"2022-10-07T14:00:40.205Z\", \"deleted_at\": null}], \"continuation_token\": \"eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==\"}";
mockHandler.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri ==
new Uri($"{_config.BasePath}/stores") &&
req.Method == HttpMethod.Get),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = new StringContent(content, Encoding.UTF8, "application/json")
});

var httpClient = new HttpClient(mockHandler.Object);
var openFgaApi = new OpenFgaApi(_config, httpClient);

var response = await openFgaApi.ListStores();
mockHandler.Protected().Verify(
"SendAsync",
Times.Exactly(1),
ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri == new Uri($"{_config.BasePath}/stores") &&
req.Method == HttpMethod.Get),
ItExpr.IsAny<CancellationToken>()
);
Assert.IsType<ListStoresResponse>(response);
Assert.Single(response.Stores);
Assert.Equal("xyz123", response.Stores[0].Id);
Assert.Equal("abcdefg", response.Stores[0].Name);
Assert.Null(response.Stores[0].DeletedAt);
}

/// <summary>
/// Test ListStores for empty array
/// </summary>
[Fact]
public async Task ListStoresEmptyTest() {
var mockHandler = new Mock<HttpMessageHandler>(MockBehavior.Strict);
var expectedResponse = new ListStoresResponse() {
Stores = new List<Store>() {
}
};
mockHandler.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri ==
new Uri($"{_config.BasePath}/stores") &&
req.Method == HttpMethod.Get),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(expectedResponse),
});

var httpClient = new HttpClient(mockHandler.Object);
var openFgaApi = new OpenFgaApi(_config, httpClient);

var response = await openFgaApi.ListStores();
mockHandler.Protected().Verify(
"SendAsync",
Times.Exactly(1),
ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri == new Uri($"{_config.BasePath}/stores") &&
req.Method == HttpMethod.Get),
ItExpr.IsAny<CancellationToken>()
);
Assert.IsType<ListStoresResponse>(response);
Assert.Empty(response.Stores);
Assert.Equal(response, expectedResponse);
}
}
}
2 changes: 1 addition & 1 deletion src/OpenFga.Sdk/Configuration/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void IsValid() {
/// Version of the package.
/// </summary>
/// <value>Version of the package.</value>
public const string Version = "0.1.0";
public const string Version = "0.1.1";

#endregion Constants

Expand Down
2 changes: 1 addition & 1 deletion src/OpenFga.Sdk/Model/Any.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Any() { }
/// </summary>
[DataMember(Name = "@type", EmitDefaultValue = false)]
[JsonPropertyName("@type")]
public string Type { get; set; }
public string? Type { get; set; }


/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenFga.Sdk/Model/Assertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Assertion() {
/// </summary>
[DataMember(Name = "tuple_key", EmitDefaultValue = false)]
[JsonPropertyName("tuple_key")]
public TupleKey TupleKey { get; set; }
public TupleKey? TupleKey { get; set; }

/// <summary>
/// Gets or Sets Expectation
Expand Down
6 changes: 3 additions & 3 deletions src/OpenFga.Sdk/Model/AuthorizationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ public AuthorizationModel() {
/// </summary>
[DataMember(Name = "id", EmitDefaultValue = false)]
[JsonPropertyName("id")]
public string Id { get; set; }
public string? Id { get; set; }

/// <summary>
/// Gets or Sets SchemaVersion
/// </summary>
[DataMember(Name = "schema_version", EmitDefaultValue = false)]
[JsonPropertyName("schema_version")]
public string SchemaVersion { get; set; }
public string? SchemaVersion { get; set; }

/// <summary>
/// Gets or Sets TypeDefinitions
/// </summary>
[DataMember(Name = "type_definitions", EmitDefaultValue = false)]
[JsonPropertyName("type_definitions")]
public List<TypeDefinition> TypeDefinitions { get; set; }
public List<TypeDefinition>? TypeDefinitions { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
8 changes: 4 additions & 4 deletions src/OpenFga.Sdk/Model/CheckRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ public CheckRequest() {
/// </summary>
[DataMember(Name = "tuple_key", EmitDefaultValue = false)]
[JsonPropertyName("tuple_key")]
public TupleKey TupleKey { get; set; }
public TupleKey? TupleKey { get; set; }

/// <summary>
/// Gets or Sets ContextualTuples
/// </summary>
[DataMember(Name = "contextual_tuples", EmitDefaultValue = false)]
[JsonPropertyName("contextual_tuples")]
public ContextualTupleKeys ContextualTuples { get; set; }
public ContextualTupleKeys? ContextualTuples { get; set; }

/// <summary>
/// Gets or Sets AuthorizationModelId
/// </summary>
[DataMember(Name = "authorization_model_id", EmitDefaultValue = false)]
[JsonPropertyName("authorization_model_id")]
public string AuthorizationModelId { get; set; }
public string? AuthorizationModelId { get; set; }

/// <summary>
/// Defaults to false. Making it true has performance implications.
/// </summary>
/// <value>Defaults to false. Making it true has performance implications.</value>
[DataMember(Name = "trace", EmitDefaultValue = true)]
[JsonPropertyName("trace")]
public bool Trace { get; private set; }
public bool? Trace { get; private set; }

/// <summary>
/// Returns false as Trace should not be serialized given that it's read-only.
Expand Down
4 changes: 2 additions & 2 deletions src/OpenFga.Sdk/Model/CheckResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public CheckResponse() {
/// </summary>
[DataMember(Name = "allowed", EmitDefaultValue = true)]
[JsonPropertyName("allowed")]
public bool Allowed { get; set; }
public bool? Allowed { get; set; }

/// <summary>
/// For internal use only.
/// </summary>
/// <value>For internal use only.</value>
[DataMember(Name = "resolution", EmitDefaultValue = false)]
[JsonPropertyName("resolution")]
public string Resolution { get; set; }
public string? Resolution { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
2 changes: 1 addition & 1 deletion src/OpenFga.Sdk/Model/Computed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Computed() {
/// </summary>
[DataMember(Name = "userset", EmitDefaultValue = false)]
[JsonPropertyName("userset")]
public string Userset { get; set; }
public string? Userset { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
2 changes: 1 addition & 1 deletion src/OpenFga.Sdk/Model/CreateStoreRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CreateStoreRequest() {
/// </summary>
[DataMember(Name = "name", EmitDefaultValue = false)]
[JsonPropertyName("name")]
public string Name { get; set; }
public string? Name { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
8 changes: 4 additions & 4 deletions src/OpenFga.Sdk/Model/CreateStoreResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ public CreateStoreResponse() {
/// </summary>
[DataMember(Name = "id", EmitDefaultValue = false)]
[JsonPropertyName("id")]
public string Id { get; set; }
public string? Id { get; set; }

/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name = "name", EmitDefaultValue = false)]
[JsonPropertyName("name")]
public string Name { get; set; }
public string? Name { get; set; }

/// <summary>
/// Gets or Sets CreatedAt
/// </summary>
[DataMember(Name = "created_at", EmitDefaultValue = false)]
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }
public DateTime? CreatedAt { get; set; }

/// <summary>
/// Gets or Sets UpdatedAt
/// </summary>
[DataMember(Name = "updated_at", EmitDefaultValue = false)]
[JsonPropertyName("updated_at")]
public DateTime UpdatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
4 changes: 2 additions & 2 deletions src/OpenFga.Sdk/Model/Difference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public Difference() {
/// </summary>
[DataMember(Name = "base", EmitDefaultValue = false)]
[JsonPropertyName("base")]
public Userset Base { get; set; }
public Userset? Base { get; set; }

/// <summary>
/// Gets or Sets Subtract
/// </summary>
[DataMember(Name = "subtract", EmitDefaultValue = false)]
[JsonPropertyName("subtract")]
public Userset Subtract { get; set; }
public Userset? Subtract { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
4 changes: 2 additions & 2 deletions src/OpenFga.Sdk/Model/ExpandRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public ExpandRequest() {
/// </summary>
[DataMember(Name = "tuple_key", EmitDefaultValue = false)]
[JsonPropertyName("tuple_key")]
public TupleKey TupleKey { get; set; }
public TupleKey? TupleKey { get; set; }

/// <summary>
/// Gets or Sets AuthorizationModelId
/// </summary>
[DataMember(Name = "authorization_model_id", EmitDefaultValue = false)]
[JsonPropertyName("authorization_model_id")]
public string AuthorizationModelId { get; set; }
public string? AuthorizationModelId { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
2 changes: 1 addition & 1 deletion src/OpenFga.Sdk/Model/ExpandResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ExpandResponse() {
/// </summary>
[DataMember(Name = "tree", EmitDefaultValue = false)]
[JsonPropertyName("tree")]
public UsersetTree Tree { get; set; }
public UsersetTree? Tree { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
8 changes: 4 additions & 4 deletions src/OpenFga.Sdk/Model/GetStoreResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ public GetStoreResponse() {
/// </summary>
[DataMember(Name = "id", EmitDefaultValue = false)]
[JsonPropertyName("id")]
public string Id { get; set; }
public string? Id { get; set; }

/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name = "name", EmitDefaultValue = false)]
[JsonPropertyName("name")]
public string Name { get; set; }
public string? Name { get; set; }

/// <summary>
/// Gets or Sets CreatedAt
/// </summary>
[DataMember(Name = "created_at", EmitDefaultValue = false)]
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }
public DateTime? CreatedAt { get; set; }

/// <summary>
/// Gets or Sets UpdatedAt
/// </summary>
[DataMember(Name = "updated_at", EmitDefaultValue = false)]
[JsonPropertyName("updated_at")]
public DateTime UpdatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
2 changes: 1 addition & 1 deletion src/OpenFga.Sdk/Model/InternalErrorMessageResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public InternalErrorMessageResponse() {
/// </summary>
[DataMember(Name = "message", EmitDefaultValue = false)]
[JsonPropertyName("message")]
public string Message { get; set; }
public string? Message { get; set; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
Loading

0 comments on commit 3f69211

Please sign in to comment.