-
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.
- Loading branch information
Showing
39 changed files
with
831 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ on: | |
branches: [ "main" ] | ||
|
||
env: | ||
PACKAGE_VERSION: 0.1.0 | ||
PACKAGE_VERSION: 0.1.4 | ||
|
||
jobs: | ||
|
||
|
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
6 changes: 6 additions & 0 deletions
6
CloudFabric.EventSourcing.EventStore/Enums/ItemsEventStoreNameSuffix.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,6 @@ | ||
namespace CloudFabric.EventSourcing.EventStore.Enums; | ||
|
||
public static class ItemsEventStoreNameSuffix | ||
{ | ||
public const string TableNameSuffix = "-item"; | ||
} |
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
15 changes: 15 additions & 0 deletions
15
CloudFabric.EventSourcing.EventStore/Persistence/ItemWrapper.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,15 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace CloudFabric.EventSourcing.EventStore.Persistence; | ||
|
||
public class ItemWrapper | ||
{ | ||
[JsonPropertyName("id")] | ||
public string? Id { get; set; } | ||
|
||
[JsonPropertyName("partition_key")] | ||
public string? PartitionKey { get; set; } | ||
|
||
[JsonPropertyName("data")] | ||
public string? ItemData { get; set; } | ||
} |
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,19 @@ | ||
namespace CloudFabric.EventSourcing.Tests.Domain; | ||
|
||
public class TestItem | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public Dictionary<string, TestNestedItemClass> Properties { get; set; } | ||
} | ||
|
||
public class TestNestedItemClass | ||
{ | ||
public Guid Id { get; set; } = Guid.NewGuid(); | ||
|
||
public string Name { get; set; } = nameof(Name).ToLowerInvariant(); | ||
|
||
public DateTime date { get; } = DateTime.MinValue; | ||
} |
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,102 @@ | ||
using CloudFabric.EventSourcing.EventStore; | ||
using CloudFabric.EventSourcing.Tests.Domain; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace CloudFabric.EventSourcing.Tests; | ||
public abstract class ItemTests | ||
{ | ||
protected abstract Task<IEventStore> GetEventStore(); | ||
private IEventStore _eventStore; | ||
|
||
[TestInitialize] | ||
public async Task Initialize() | ||
{ | ||
_eventStore = await GetEventStore(); | ||
} | ||
|
||
[TestCleanup] | ||
public async Task Cleanup() | ||
{ | ||
await _eventStore.DeleteAll(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task SaveItem() | ||
{ | ||
var item = new TestItem | ||
{ | ||
Id = Guid.NewGuid(), | ||
Name = "Item1", | ||
Properties = new Dictionary<string, TestNestedItemClass> | ||
{ | ||
{ Guid.NewGuid().ToString(), new TestNestedItemClass() }, | ||
{ Guid.NewGuid().ToString(), new TestNestedItemClass() } | ||
} | ||
}; | ||
|
||
Func<Task> action = async () => await _eventStore.UpsertItem($"{item.Id}{item.Name}", $"{item.Id}{item.Name}", item); | ||
await action.Should().NotThrowAsync(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task LoadItem() | ||
{ | ||
var item = new TestItem | ||
{ | ||
Id = Guid.NewGuid(), | ||
Name = "Item1", | ||
Properties = new Dictionary<string, TestNestedItemClass> | ||
{ | ||
{ Guid.NewGuid().ToString(), new TestNestedItemClass() } | ||
} | ||
}; | ||
|
||
await _eventStore.UpsertItem($"{item.Id}{item.Name}", $"{item.Id}{item.Name}", item); | ||
|
||
var loadedItem = await _eventStore.LoadItem<TestItem>($"{item.Id}{item.Name}", $"{item.Id}{item.Name}"); | ||
|
||
loadedItem.Id.Should().Be(item.Id); | ||
loadedItem.Name.Should().Be(item.Name); | ||
loadedItem.Properties.Keys.Should().BeEquivalentTo(item.Properties.Keys); | ||
loadedItem.Properties.Values.Should().BeEquivalentTo(item.Properties.Values); | ||
} | ||
|
||
[TestMethod] | ||
public async Task LoadItem_NullIfNotFound() | ||
{ | ||
var loadedItem = await _eventStore.LoadItem<TestItem>($"{Guid.NewGuid()}", $"{Guid.NewGuid()}"); | ||
|
||
loadedItem.Should().BeNull(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task UpdateItem() | ||
{ | ||
var item = new TestItem | ||
{ | ||
Id = Guid.NewGuid(), | ||
Name = "Item1", | ||
Properties = new Dictionary<string, TestNestedItemClass> | ||
{ | ||
{ Guid.NewGuid().ToString(), new TestNestedItemClass() }, | ||
{ Guid.NewGuid().ToString(), new TestNestedItemClass() } | ||
} | ||
}; | ||
|
||
await _eventStore.UpsertItem($"{item.Id}{item.Name}", $"{item.Id}{item.Name}", item); | ||
|
||
string propertyGuid = Guid.NewGuid().ToString(); | ||
|
||
item.Properties = new() | ||
{ | ||
{ propertyGuid, new TestNestedItemClass() } | ||
}; | ||
|
||
Func<Task> action = async () => await _eventStore.UpsertItem($"{item.Id}{item.Name}", $"{item.Id}{item.Name}", item); | ||
await action.Should().NotThrowAsync(); | ||
|
||
var updatedItem = await _eventStore.LoadItem<TestItem>($"{item.Id}{item.Name}", $"{item.Id}{item.Name}"); | ||
updatedItem.Properties.ContainsKey(propertyGuid).Should().BeTrue(); | ||
} | ||
} |
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
Oops, something went wrong.