-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Updated KeyDataPairsToDictionaryStringObjectJsonConverter to suppo…
…rt when data is null, and added some tests 2. Updated audit log to use a double when ValueKind is a number to support real numbers, and added some tests 3. Updated document to documents 4. Fixed an issue with concurrency within Linking due to the etag being empty
- Loading branch information
Thomas Anderson
committed
Dec 6, 2024
1 parent
d2babf4
commit 447cac1
Showing
18 changed files
with
150 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
namespace Btms.Backend.Data; | ||
|
||
public class ConcurrencyException(string message) : Exception(message); | ||
public class ConcurrencyException(string entityId, string entityEtag) : Exception($"Failed up update {entityId} with etag {entityEtag}") | ||
{ | ||
public string EntityId { get; } = entityId; | ||
|
||
public string EntityEtag { get; } = entityEtag; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Btms.Model.Auditing; | ||
using FluentAssertions; | ||
|
||
namespace Btms.Backend.Test.Auditing; | ||
|
||
public class AuditingTests | ||
{ | ||
public class TestClassOne | ||
{ | ||
public double NumberValue { get; set; } | ||
} | ||
|
||
[Fact] | ||
public void CreateAuditWhenDifferentIsDouble() | ||
{ | ||
var previous = new TestClassOne() { NumberValue = 1.2 }; | ||
var current = new TestClassOne() { NumberValue = 2.2 }; | ||
var auditEntry = AuditEntry.CreateUpdated(previous, current, "testid", 1, DateTime.UtcNow); | ||
|
||
auditEntry.Should().NotBeNull(); | ||
auditEntry.Diff.Count.Should().Be(1); | ||
auditEntry.Diff[0].Value.Should().Be(2.2); | ||
auditEntry.Diff[0].Op.Should().Be("Replace"); | ||
auditEntry.Diff[0].Path.Should().Be("/NumberValue"); | ||
|
||
} | ||
|
||
|
||
[Fact] | ||
public void CreateAuditWhenDifferentIsInt() | ||
{ | ||
var previous = new TestClassOne() { NumberValue = 1 }; | ||
var current = new TestClassOne() { NumberValue = 2 }; | ||
var auditEntry = AuditEntry.CreateUpdated(previous, current, "testid", 1, DateTime.UtcNow); | ||
|
||
auditEntry.Should().NotBeNull(); | ||
auditEntry.Diff.Count.Should().Be(1); | ||
auditEntry.Diff[0].Value.Should().Be(2); | ||
auditEntry.Diff[0].Op.Should().Be("Replace"); | ||
auditEntry.Diff[0].Path.Should().Be("/NumberValue"); | ||
|
||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
Btms.Backend.Test/JsonCoverters/KeyDataPairsToDictionaryStringObjectJsonConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Btms.Types.Ipaffs; | ||
using FluentAssertions; | ||
|
||
namespace Btms.Backend.Test.JsonCoverters; | ||
|
||
public class KeyDataPairsToDictionaryStringObjectJsonConverterTests | ||
{ | ||
public class TestClass | ||
{ | ||
[JsonPropertyName("keyDataPair")] | ||
[JsonConverter(typeof(KeyDataPairsToDictionaryStringObjectJsonConverter))] | ||
public IDictionary<string, object>? KeyDataPairs { get; set; } | ||
} | ||
|
||
[Fact] | ||
public void GivenDataIsNotPresentInJson_ThenItShouldBeDeserializedAsNull() | ||
{ | ||
var json = | ||
"{\"keyDataPair\": [\r\n {\r\n \"key\": \"netweight\"\r\n },\r\n {\r\n \"key\": \"number_package\",\r\n \"data\": \"0\"\r\n },\r\n {\r\n \"key\": \"type_package\",\r\n \"data\": \"Case\"\r\n }\r\n ]}"; | ||
|
||
var result = JsonSerializer.Deserialize<TestClass>(json); | ||
|
||
result.Should().NotBeNull(); | ||
result?.KeyDataPairs?.Count.Should().Be(3); | ||
result?.KeyDataPairs?["netweight"].Should().BeNull(); | ||
result?.KeyDataPairs?["number_package"].Should().Be(0); | ||
result?.KeyDataPairs?["type_package"].Should().Be("Case"); | ||
|
||
} | ||
|
||
[Fact] | ||
public void GivenValidJson_ThenEverythingShouldBeDeserialized() | ||
{ | ||
var json = | ||
"{\r\n\"keyDataPair\": [\r\n {\r\n \"key\": \"number_package\",\r\n \"data\": \"0\"\r\n },\r\n {\r\n \"key\": \"type_package\",\r\n \"data\": \"Case\"\r\n }\r\n ]\r\n}"; | ||
|
||
var result = JsonSerializer.Deserialize<TestClass>(json); | ||
|
||
result.Should().NotBeNull(); | ||
result?.KeyDataPairs?.Count.Should().Be(2); | ||
result?.KeyDataPairs?["number_package"].Should().Be(0); | ||
result?.KeyDataPairs?["type_package"].Should().Be("Case"); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters