Skip to content

Commit

Permalink
* more refactored tests.
Browse files Browse the repository at this point in the history
* optimized test fixtures.
* reverted spaces to tabs...
  • Loading branch information
RagingKore committed Oct 30, 2023
1 parent e39d52d commit 67e9132
Show file tree
Hide file tree
Showing 258 changed files with 14,635 additions and 13,369 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NullableContextOptions>enable</NullableContextOptions>
<ImplicitUsings>true</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>11</LangVersion>
<LangVersion>preview</LangVersion>

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<DebugType Condition=" '$(Configuration)' == 'Debug' ">full</DebugType>
Expand Down
9 changes: 0 additions & 9 deletions EventStore.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStore.Client.Persisten
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStore.Client.UserManagement.Tests", "test\EventStore.Client.UserManagement.Tests\EventStore.Client.UserManagement.Tests.csproj", "{22634CEE-4F7B-4679-A48D-38A2A8580ECA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "generators", "generators", "{57BAB29D-F8A8-47C7-B426-89A1929ADD70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStore.Tests.SourceGenerators", "generators\EventStore.Tests.SourceGenerators\EventStore.Tests.SourceGenerators.csproj", "{5912BD08-DA99-49B7-A2C0-C1BA42D209CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStore.Client.Tests.Common", "test\EventStore.Client.Tests.Common\EventStore.Client.Tests.Common.csproj", "{E326832D-DE52-4DE4-9E54-C800908B75F3}"
EndProject
Global
Expand Down Expand Up @@ -94,10 +90,6 @@ Global
{22634CEE-4F7B-4679-A48D-38A2A8580ECA}.Debug|x64.Build.0 = Debug|Any CPU
{22634CEE-4F7B-4679-A48D-38A2A8580ECA}.Release|x64.ActiveCfg = Release|Any CPU
{22634CEE-4F7B-4679-A48D-38A2A8580ECA}.Release|x64.Build.0 = Release|Any CPU
{5912BD08-DA99-49B7-A2C0-C1BA42D209CB}.Debug|x64.ActiveCfg = Debug|Any CPU
{5912BD08-DA99-49B7-A2C0-C1BA42D209CB}.Debug|x64.Build.0 = Debug|Any CPU
{5912BD08-DA99-49B7-A2C0-C1BA42D209CB}.Release|x64.ActiveCfg = Release|Any CPU
{5912BD08-DA99-49B7-A2C0-C1BA42D209CB}.Release|x64.Build.0 = Release|Any CPU
{E326832D-DE52-4DE4-9E54-C800908B75F3}.Debug|x64.ActiveCfg = Debug|Any CPU
{E326832D-DE52-4DE4-9E54-C800908B75F3}.Debug|x64.Build.0 = Debug|Any CPU
{E326832D-DE52-4DE4-9E54-C800908B75F3}.Release|x64.ActiveCfg = Release|Any CPU
Expand All @@ -116,7 +108,6 @@ Global
{FC829F1B-43AD-4C96-9002-23D04BBA3AF3} = {C51F2C69-45A9-4D0D-A708-4FC319D5D340}
{6CEB731F-72E1-461F-A6B3-54DBF3FD786C} = {C51F2C69-45A9-4D0D-A708-4FC319D5D340}
{22634CEE-4F7B-4679-A48D-38A2A8580ECA} = {C51F2C69-45A9-4D0D-A708-4FC319D5D340}
{5912BD08-DA99-49B7-A2C0-C1BA42D209CB} = {57BAB29D-F8A8-47C7-B426-89A1929ADD70}
{E326832D-DE52-4DE4-9E54-C800908B75F3} = {C51F2C69-45A9-4D0D-A708-4FC319D5D340}
EndGlobalSection
EndGlobal
14 changes: 10 additions & 4 deletions EventStore.Client.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AROUND_SINGLE_LINE_FIELD/@EntryValue">0</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_BEFORE_CASE/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_BETWEEN_USING_GROUPS/@EntryValue">0</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_STYLE/@EntryValue">Tab</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_ENUM_ARRANGEMENT/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_INITIALIZER_ARRANGEMENT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_INVOCATION_PARENS_ARRANGEMENT/@EntryValue">False</s:Boolean>
Expand Down Expand Up @@ -119,8 +120,11 @@
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_SWITCH_EXPRESSION_ARRANGEMENT/@EntryValue">False</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_INITIALIZER_ELEMENTS_ON_LINE/@EntryValue">10</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_INVOCATION_ARGUMENTS_ON_LINE/@EntryValue">3</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_ENUM_MEMBERS_ON_LINE/@EntryValue">6</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_FORMAL_PARAMETERS_ON_LINE/@EntryValue">10</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_INITIALIZER_ELEMENTS_ON_LINE/@EntryValue">6</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_INVOCATION_ARGUMENTS_ON_LINE/@EntryValue">6</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_PRIMARY_CONSTRUCTOR_PARAMETERS_ON_LINE/@EntryValue">10</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/NESTED_TERNARY_STYLE/@EntryValue">EXPANDED</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/OTHER_BRACES/@EntryValue">END_OF_LINE</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/OUTDENT_BINARY_OPS/@EntryValue">True</s:Boolean>
Expand All @@ -132,13 +136,14 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_DECLARATION_LPAR/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_INVOCATION_LPAR/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARGUMENTS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARRAY_INITIALIZER_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARRAY_INITIALIZER_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_BINARY_OPSIGN/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_PRIMARY_CONSTRUCTOR_DECLARATION_LPAR/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ENUM_DECLARATION/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_MULTIPLE_TYPE_PARAMEER_CONSTRAINTS_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE/@EntryValue">CHOP_ALWAYS</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpFileLayoutPatterns/Pattern/@EntryValue">&lt;Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"&gt;
&lt;TypePattern DisplayName="Non-reorderable types"&gt;
&lt;TypePattern.Match&gt;
Expand Down Expand Up @@ -376,6 +381,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=acked/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=appsettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cancellator/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Enrichers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=esdb/@EntryIndexedValue">True</s:Boolean>
Expand Down
20 changes: 11 additions & 9 deletions src/EventStore.Client.Common/AsyncStreamReaderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System.Runtime.CompilerServices;
using Grpc.Core;

namespace EventStore.Client {
internal static class AsyncStreamReaderExtensions {
public static async IAsyncEnumerable<T> ReadAllAsync<T>(this IAsyncStreamReader<T> reader,
[EnumeratorCancellation] CancellationToken cancellationToken = default) {
while (await reader.MoveNext(cancellationToken).ConfigureAwait(false)) {
yield return reader.Current;
}
}
namespace EventStore.Client;

static class AsyncStreamReaderExtensions {
public static async IAsyncEnumerable<T> ReadAllAsync<T>(
this IAsyncStreamReader<T> reader,
[EnumeratorCancellation]
CancellationToken cancellationToken = default
) {
while (await reader.MoveNext(cancellationToken).ConfigureAwait(false))
yield return reader.Current;
}
}
}
120 changes: 60 additions & 60 deletions src/EventStore.Client.Common/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
namespace EventStore.Client;

internal static class Constants {
public static class Exceptions {
public const string ExceptionKey = "exception";

public const string AccessDenied = "access-denied";
public const string InvalidTransaction = "invalid-transaction";
public const string StreamDeleted = "stream-deleted";
public const string WrongExpectedVersion = "wrong-expected-version";
public const string StreamNotFound = "stream-not-found";
public const string MaximumAppendSizeExceeded = "maximum-append-size-exceeded";
public const string MissingRequiredMetadataProperty = "missing-required-metadata-property";
public const string NotLeader = "not-leader";

public const string PersistentSubscriptionFailed = "persistent-subscription-failed";
public const string PersistentSubscriptionDoesNotExist = "persistent-subscription-does-not-exist";
public const string PersistentSubscriptionExists = "persistent-subscription-exists";
public const string MaximumSubscribersReached = "maximum-subscribers-reached";
public const string PersistentSubscriptionDropped = "persistent-subscription-dropped";

public const string UserNotFound = "user-not-found";
public const string UserConflict = "user-conflict";

public const string ScavengeNotFound = "scavenge-not-found";

public const string ExpectedVersion = "expected-version";
public const string ActualVersion = "actual-version";
public const string StreamName = "stream-name";
public const string GroupName = "group-name";
public const string Reason = "reason";
public const string MaximumAppendSize = "maximum-append-size";
public const string RequiredMetadataProperties = "required-metadata-properties";
public const string ScavengeId = "scavenge-id";
public const string LeaderEndpointHost = "leader-endpoint-host";
public const string LeaderEndpointPort = "leader-endpoint-port";

public const string LoginName = "login-name";
}

public static class Metadata {
public const string Type = "type";
public const string Created = "created";
public const string ContentType = "content-type";
public static readonly string[] RequiredMetadata = {Type, ContentType};

public static class ContentTypes {
public const string ApplicationJson = "application/json";
public const string ApplicationOctetStream = "application/octet-stream";
}
}

public static class Headers {
public const string Authorization = "authorization";
public const string BasicScheme = "Basic";
public const string BearerScheme = "Bearer";

public const string ConnectionName = "connection-name";
public const string RequiresLeader = "requires-leader";
}
namespace EventStore.Client;

static class Constants {
public static class Exceptions {
public const string ExceptionKey = "exception";

public const string AccessDenied = "access-denied";
public const string InvalidTransaction = "invalid-transaction";
public const string StreamDeleted = "stream-deleted";
public const string WrongExpectedVersion = "wrong-expected-version";
public const string StreamNotFound = "stream-not-found";
public const string MaximumAppendSizeExceeded = "maximum-append-size-exceeded";
public const string MissingRequiredMetadataProperty = "missing-required-metadata-property";
public const string NotLeader = "not-leader";

public const string PersistentSubscriptionFailed = "persistent-subscription-failed";
public const string PersistentSubscriptionDoesNotExist = "persistent-subscription-does-not-exist";
public const string PersistentSubscriptionExists = "persistent-subscription-exists";
public const string MaximumSubscribersReached = "maximum-subscribers-reached";
public const string PersistentSubscriptionDropped = "persistent-subscription-dropped";

public const string UserNotFound = "user-not-found";
public const string UserConflict = "user-conflict";

public const string ScavengeNotFound = "scavenge-not-found";

public const string ExpectedVersion = "expected-version";
public const string ActualVersion = "actual-version";
public const string StreamName = "stream-name";
public const string GroupName = "group-name";
public const string Reason = "reason";
public const string MaximumAppendSize = "maximum-append-size";
public const string RequiredMetadataProperties = "required-metadata-properties";
public const string ScavengeId = "scavenge-id";
public const string LeaderEndpointHost = "leader-endpoint-host";
public const string LeaderEndpointPort = "leader-endpoint-port";

public const string LoginName = "login-name";
}

public static class Metadata {
public const string Type = "type";
public const string Created = "created";
public const string ContentType = "content-type";
public static readonly string[] RequiredMetadata = { Type, ContentType };

public static class ContentTypes {
public const string ApplicationJson = "application/json";
public const string ApplicationOctetStream = "application/octet-stream";
}
}

public static class Headers {
public const string Authorization = "authorization";
public const string BasicScheme = "Basic";
public const string BearerScheme = "Bearer";

public const string ConnectionName = "connection-name";
public const string RequiresLeader = "requires-leader";
}
}
16 changes: 7 additions & 9 deletions src/EventStore.Client.Common/EpochExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
namespace EventStore.Client {
internal static class EpochExtensions {
private static readonly DateTime UnixEpoch = DateTime.UnixEpoch;
namespace EventStore.Client;

public static DateTime FromTicksSinceEpoch(this long value) =>
new DateTime(UnixEpoch.Ticks + value, DateTimeKind.Utc);
static class EpochExtensions {
static readonly DateTime UnixEpoch = DateTime.UnixEpoch;

public static long ToTicksSinceEpoch(this DateTime value) =>
(value - UnixEpoch).Ticks;
}
}
public static DateTime FromTicksSinceEpoch(this long value) => new(UnixEpoch.Ticks + value, DateTimeKind.Utc);

public static long ToTicksSinceEpoch(this DateTime value) => (value - UnixEpoch).Ticks;
}
91 changes: 57 additions & 34 deletions src/EventStore.Client.Common/EventStoreCallOptions.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
using Grpc.Core;
using Timeout_ = System.Threading.Timeout;

namespace EventStore.Client {
internal static class EventStoreCallOptions {
// deadline falls back to infinity
public static CallOptions CreateStreaming(EventStoreClientSettings settings,
TimeSpan? deadline = null, UserCredentials? userCredentials = null,
CancellationToken cancellationToken = default) =>
Create(settings, deadline, userCredentials, cancellationToken);

// deadline falls back to connection DefaultDeadline
public static CallOptions CreateNonStreaming(EventStoreClientSettings settings,
CancellationToken cancellationToken) => Create(settings, settings.DefaultDeadline,
settings.DefaultCredentials, cancellationToken);

public static CallOptions CreateNonStreaming(EventStoreClientSettings settings, TimeSpan? deadline,
UserCredentials? userCredentials, CancellationToken cancellationToken) => Create(settings,
deadline ?? settings.DefaultDeadline, userCredentials, cancellationToken);

private static CallOptions Create(EventStoreClientSettings settings, TimeSpan? deadline,
UserCredentials? userCredentials, CancellationToken cancellationToken) => new(
using static System.Threading.Timeout;

namespace EventStore.Client;

static class EventStoreCallOptions {
// deadline falls back to infinity
public static CallOptions CreateStreaming(
EventStoreClientSettings settings,
TimeSpan? deadline = null, UserCredentials? userCredentials = null,
CancellationToken cancellationToken = default
) =>
Create(settings, deadline, userCredentials, cancellationToken);

// deadline falls back to connection DefaultDeadline
public static CallOptions CreateNonStreaming(
EventStoreClientSettings settings,
CancellationToken cancellationToken
) =>
Create(
settings,
settings.DefaultDeadline,
settings.DefaultCredentials,
cancellationToken
);

public static CallOptions CreateNonStreaming(
EventStoreClientSettings settings, TimeSpan? deadline,
UserCredentials? userCredentials, CancellationToken cancellationToken
) =>
Create(
settings,
deadline ?? settings.DefaultDeadline,
userCredentials,
cancellationToken
);

static CallOptions Create(
EventStoreClientSettings settings, TimeSpan? deadline,
UserCredentials? userCredentials, CancellationToken cancellationToken
) =>
new(
cancellationToken: cancellationToken,
deadline: DeadlineAfter(deadline),
headers: new Metadata {
headers: new() {
{
Constants.Headers.RequiresLeader,
settings.ConnectivitySettings.NodePreference == NodePreference.Leader
Expand All @@ -32,20 +52,23 @@ private static CallOptions Create(EventStoreClientSettings settings, TimeSpan? d
},
credentials: (userCredentials ?? settings.DefaultCredentials) == null
? null
: CallCredentials.FromInterceptor(async (_, metadata) => {
var credentials = userCredentials ?? settings.DefaultCredentials;

var authorizationHeader = await settings.OperationOptions
.GetAuthenticationHeaderValue(credentials!, CancellationToken.None)
.ConfigureAwait(false);
metadata.Add(Constants.Headers.Authorization, authorizationHeader);
})
: CallCredentials.FromInterceptor(
async (_, metadata) => {
var credentials = userCredentials ?? settings.DefaultCredentials;

var authorizationHeader = await settings.OperationOptions
.GetAuthenticationHeaderValue(credentials!, CancellationToken.None)
.ConfigureAwait(false);

metadata.Add(Constants.Headers.Authorization, authorizationHeader);
}
)
);

private static DateTime? DeadlineAfter(TimeSpan? timeoutAfter) => !timeoutAfter.HasValue
static DateTime? DeadlineAfter(TimeSpan? timeoutAfter) =>
!timeoutAfter.HasValue
? new DateTime?()
: timeoutAfter.Value == TimeSpan.MaxValue || timeoutAfter.Value == Timeout_.InfiniteTimeSpan
: timeoutAfter.Value == TimeSpan.MaxValue || timeoutAfter.Value == InfiniteTimeSpan
? DateTime.MaxValue
: DateTime.UtcNow.Add(timeoutAfter.Value);
}
}
}
Loading

0 comments on commit 67e9132

Please sign in to comment.