Skip to content
Open
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
31 changes: 31 additions & 0 deletions src/EventStoreEventTools.Tests/EventStoreEventTools.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EventStore.Client.Grpc" Version="22.0.0" />
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="22.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0-preview-20221003-04" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Tools.EventStore\Tools.EventStore.csproj" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions src/EventStoreEventTools.Tests/EventStoreEventToolsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace EventStoreEventTools.Tests
{
using NUnit.Framework;
using EventStore.Client;
using CorshamScience.Tools.EventStore;
using Newtonsoft.Json;
using System.Text;

internal class EventStoreEventToolsTests
{
[Test]
public void ToEventData_Given_Valid_Event_Returns_EventData()
{
var standardEvent = new StandardEvent
{
Id = Uuid.NewUuid(),
Description = "Test",
};

var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(standardEvent));
var eventHeaders = new { ClrType = standardEvent.GetType().AssemblyQualifiedName };

var metadata = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(eventHeaders));
var typeName = standardEvent.GetType().Name;

var expectedObject = new EventData(standardEvent.Id, typeName, data, metadata);

var toEventData = EventStoreEventTools.ToEventData(standardEvent.Id, standardEvent);
Assert.That(JsonConvert.SerializeObject(toEventData), Is.EqualTo(JsonConvert.SerializeObject(expectedObject)));
}
private class StandardEvent
{
public Uuid Id { get; set; }
public string? Description { get; set; }
}
}
}
12 changes: 9 additions & 3 deletions src/Tools.EventStore.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2000
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tools.EventStore", "Tools.EventStore\Tools.EventStore.csproj", "{1FEA1406-472C-471E-96C6-3F075DD50FD3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.EventStore", "Tools.EventStore\Tools.EventStore.csproj", "{1FEA1406-472C-471E-96C6-3F075DD50FD3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStoreEventTools.Tests", "EventStoreEventTools.Tests\EventStoreEventTools.Tests.csproj", "{DCC4AC2A-9B1D-41FA-B450-818C62D2D158}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{1FEA1406-472C-471E-96C6-3F075DD50FD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FEA1406-472C-471E-96C6-3F075DD50FD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FEA1406-472C-471E-96C6-3F075DD50FD3}.Release|Any CPU.Build.0 = Release|Any CPU
{DCC4AC2A-9B1D-41FA-B450-818C62D2D158}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCC4AC2A-9B1D-41FA-B450-818C62D2D158}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCC4AC2A-9B1D-41FA-B450-818C62D2D158}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCC4AC2A-9B1D-41FA-B450-818C62D2D158}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
26 changes: 26 additions & 0 deletions src/Tools.EventStore/EventStoreClientBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// <copyright file="EventStoreClientBuilder.cs" company="Corsham Science">
// Copyright (c) Corsham Science. All rights reserved.
// </copyright>

namespace CorshamScience.Tools.EventStore
{
using System;
using global::EventStore.Client;

/// <summary>
/// A helper class for quickly building an <see cref="EventStoreClient"/>.
/// </summary>
public static class EventStoreClientBuilder
{
/// <summary>
/// Builds an <see cref="EventStoreClient"/> using the default settings.
/// </summary>
/// <param name="connectionString">Put valid connection string.</param>
/// <returns>EventStoreClient.</returns>
public static EventStoreClient GetEventStoreClient(string connectionString)
{
var settings = EventStoreClientSettings.Create(connectionString);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this definitely all we need to specify compared to the old version? Seems like previously we were setting a gossipTimeout, is that not something we still need to support or is there a different way of setting it now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @jbradford and @JamesMcCaig in Teams. Neither of us have been able to find references to this in the documentation, which suggests that the approach that we have taken here is sufficient

return new EventStoreClient(settings);
}
}
}
114 changes: 0 additions & 114 deletions src/Tools.EventStore/EventStoreConnectionBuilder.cs

This file was deleted.

10 changes: 5 additions & 5 deletions src/Tools.EventStore/EventStoreEventTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace CorshamScience.Tools.EventStore
{
using System;
using System.Text;
using global::EventStore.ClientAPI;
using global::EventStore.Client;
using Newtonsoft.Json;

/// <summary>
/// A helper class containing methods to handle reading and writing events to/from an <see cref="IEventStoreConnection"/>.
/// A helper class containing methods to handle reading and writing events to/from an <see cref="EventStoreClient"/>.
/// </summary>
public static class EventStoreEventTools
{
Expand All @@ -22,15 +22,15 @@ public static class EventStoreEventTools
/// <param name="serializerSettings">Optional <see cref="JsonSerializerSettings"/> to use when serializing the provided <see cref="object"/> and the event metadata.</param>
/// <returns>A new <see cref="EventData"/> object with the provided ID, and serialized &amp; encoded JSON data, as well as metadata containing the assembly qualified name for the event <see cref="object"/>.</returns>
// ReSharper disable once UnusedMember.Global
public static EventData ToEventData(Guid eventId, object @event, JsonSerializerSettings serializerSettings = null)
public static EventData ToEventData(Uuid eventId, object @event, JsonSerializerSettings serializerSettings = null)
{
var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(@event, serializerSettings));
var eventHeaders = new { ClrType = @event.GetType().AssemblyQualifiedName };

var metadata = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(eventHeaders, serializerSettings));
var typeName = @event.GetType().Name;

return new EventData(eventId, typeName, true, data, metadata);
return new EventData(eventId, typeName, data, metadata);
}

/// <summary>
Expand All @@ -52,7 +52,7 @@ public static EventData ToEventData(Guid eventId, object @event, JsonSerializerS
/// <returns>An <see cref="object"/> of the provided <see cref="Type"/> build from the JSON data contained in the provided <see cref="ResolvedEvent"/>.</returns>
public static object FromResolvedEvent(ResolvedEvent @event, Type typeToConvertTo, JsonSerializerSettings serializerSettings = null)
{
var eventString = Encoding.UTF8.GetString(@event.Event.Data);
var eventString = Encoding.UTF8.GetString(@event.Event.Data.Span);
return JsonConvert.DeserializeObject(eventString, typeToConvertTo, serializerSettings);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Tools.EventStore/Tools.EventStore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>CorshamScience.Tools.EventStore</AssemblyName>
<RootNamespace>CorshamScience.Tools.EventStore</RootNamespace>
<Product>CorshamScience.Tools</Product>
Expand Down Expand Up @@ -35,7 +35,9 @@
<PackageReference Include="CorshamScience.CodeStyle.CSharp.Full" Version="3.0.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="EventStore.Client" Version="5.0.5" />
<PackageReference Include="EventStore.Client.Grpc" Version="22.0.0" />
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="22.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down