├── .gitignore ├── EventStore.ClientAPI.NetCore.sln ├── LICENSE.md ├── README.md ├── appveyor.yml ├── build.sh ├── run_suppressed_tests.sh ├── scripts ├── appveyortest.ps1 ├── installandruneventstore.ps1 └── updateversion.ps1 ├── src └── EventStore.ClientAPI.NetCore │ ├── AllCheckpoint.cs │ ├── AllEventsSlice.cs │ ├── CatchUpSubscriptionSettings.cs │ ├── ClientApiConstants.cs │ ├── ClientAuthenticationFailedEventArgs.cs │ ├── ClientClosedEventArgs.cs │ ├── ClientConnectionEventArgs.cs │ ├── ClientErrorEventArgs.cs │ ├── ClientOperations │ ├── AppendToStreamOperation.cs │ ├── CommitTransactionOperation.cs │ ├── ConditionalAppendToStreamOperation.cs │ ├── ConnectToPersistentSubscriptionOperation.cs │ ├── CreatePersistentSubscriptionOperation.cs │ ├── DeletePersistentSubscriptionOperation.cs │ ├── DeleteStreamOperation.cs │ ├── IClientOperation.cs │ ├── ISubscriptionOperation.cs │ ├── OperationBase.cs │ ├── ReadAllEventsBackwardOperation.cs │ ├── ReadAllEventsForwardOperation.cs │ ├── ReadEventOperation.cs │ ├── ReadStreamEventsBackwardOperation.cs │ ├── ReadStreamEventsForwardOperation.cs │ ├── StartTransactionOperation.cs │ ├── SubscriptionOperation.cs │ ├── TransactionalWriteOperation.cs │ ├── UpdatePersistentSubscriptionOperation.cs │ └── VolatileSubscriptionOperation.cs │ ├── ClientReconnectingEventArgs.cs │ ├── ClusterSettings.cs │ ├── ClusterSettingsBuilder.cs │ ├── Common │ ├── Log │ │ ├── ConsoleLogger.cs │ │ ├── DebugLogger.cs │ │ ├── FileLogger.cs │ │ ├── LogManager.cs │ │ └── NoopLogger.cs │ ├── SystemNames.cs │ └── Utils │ │ ├── Ensure.cs │ │ ├── Helper.cs │ │ ├── Json.cs │ │ └── Threading │ │ ├── ManualResetEventSlimExtensions.cs │ │ └── TaskExtensions.cs │ ├── ConditionalWriteFailureReason.cs │ ├── ConditionalWriteResult.cs │ ├── ConnectionSettings.cs │ ├── ConnectionSettingsBuilder.cs │ ├── ConnectionString.cs │ ├── DeleteResult.cs │ ├── DnsClusterSettingsBuilder.cs │ ├── EventData.cs │ ├── EventReadResult.cs │ ├── EventReadStatus.cs │ ├── EventStore.ClientAPI.NetCore.csproj │ ├── EventStoreCatchUpSubscription.cs │ ├── EventStoreConnection.cs │ ├── EventStorePersistentSubscription.cs │ ├── EventStorePersistentSubscriptionBase.cs │ ├── EventStoreSubscription.cs │ ├── EventStoreTransaction.cs │ ├── Exceptions │ ├── AccessDeniedException.cs │ ├── CannotEstablishConnectionException.cs │ ├── ClusterException.cs │ ├── CommandNotExpectedException.cs │ ├── ConnectionClosedException.cs │ ├── EventStoreConnectionException.cs │ ├── InvalidTransactionException.cs │ ├── NoResultException.cs │ ├── NotAuthenticatedException.cs │ ├── OperationExpiredException.cs │ ├── OperationTimedOutException.cs │ ├── ProjectionCommandConflictException.cs │ ├── ProjectionCommandFailedException.cs │ ├── RetriesLimitReachedException.cs │ ├── ServerErrorException.cs │ ├── StreamDeletedException.cs │ ├── UserCommandConflictException.cs │ ├── UserCommandFailedException.cs │ └── WrongExpectedVersionException.cs │ ├── ExpectedVersion.cs │ ├── GossipSeed.cs │ ├── GossipSeedClusterSettingsBuilder.cs │ ├── IConnectToPersistentSubscriptions.cs │ ├── IEndPointDiscoverer.cs │ ├── IEventStoreConnection.cs │ ├── IEventStoreConnectionExtensions.cs │ ├── ILogger.cs │ ├── Internal │ ├── ClusterDnsEndPointDiscoverer.cs │ ├── Consts.cs │ ├── Empty.cs │ ├── EventStoreConnectionLogicHandler.cs │ ├── EventStoreNodeConnection.cs │ ├── IEventStoreConnectionLogicHandler.cs │ ├── IEventStoreTransactionConnection.cs │ ├── IPEndPointExtensions.cs │ ├── Messages.cs │ ├── OperationsManager.cs │ ├── PersistentSubscriptionCreateResult.cs │ ├── PersistentSubscriptionCreateStatus.cs │ ├── PersistentSubscriptionDeleteResult.cs │ ├── PersistentSubscriptionDeleteStatus.cs │ ├── PersistentSubscriptionUpdateResult.cs │ ├── PersistentSubscriptionUpdateStatus.cs │ ├── SimpleQueuedHandler.cs │ ├── SingleEndpointDiscoverer.cs │ ├── StaticEndPointDiscoverer.cs │ ├── SubscriptionsManager.cs │ └── VolatileEventStoreSubscription.cs │ ├── Messages │ ├── ClientMessage.cs │ ├── ClientMessagesExtensions.cs │ └── ClusterMessages.cs │ ├── NodeEndPoints.cs │ ├── NodePreference.cs │ ├── PersistentEventStoreSubscription.cs │ ├── PersistentSubscriptionNakEventAction.cs │ ├── PersistentSubscriptionSettings.cs │ ├── PersistentSubscriptionSettingsBuilder.cs │ ├── Position.cs │ ├── Projections │ ├── ProjectionDetails.cs │ ├── ProjectionsClient.cs │ ├── ProjectionsManager.cs │ └── QueryManager.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── RawStreamMetadataResult.cs │ ├── ReadDirection.cs │ ├── RecordedEvent.cs │ ├── ResolvedEvent.cs │ ├── SliceReadStatus.cs │ ├── StreamAcl.cs │ ├── StreamCheckpoint.cs │ ├── StreamEventsSlice.cs │ ├── StreamMetadata.cs │ ├── StreamMetadataBuilder.cs │ ├── StreamMetadataResult.cs │ ├── StreamPosition.cs │ ├── SubscriptionDropReason.cs │ ├── SystemData │ ├── InspectionDecision.cs │ ├── InspectionResult.cs │ ├── StatusCode.cs │ ├── TcpCommand.cs │ ├── TcpPackage.cs │ └── UserCredentials.cs │ ├── SystemSettings.cs │ ├── Transport.Http │ ├── ClientOperationState.cs │ ├── ContentType.cs │ ├── EndpointExtensions.cs │ ├── HttpAsyncClient.cs │ ├── HttpMethod.cs │ ├── HttpResponse.cs │ └── HttpStatusCode.cs │ ├── Transport.Tcp │ ├── IMonitoredTcpConnection.cs │ ├── ITcpConnection.cs │ ├── LengthPrefixFramer.cs │ ├── PackageFramingException.cs │ ├── ProtobufExtensions.cs │ ├── SocketArgsPool.cs │ ├── TcpClientConnector.cs │ ├── TcpConfiguratin.cs │ ├── TcpConnection.cs │ ├── TcpConnectionBase.cs │ ├── TcpConnectionLockless.cs │ ├── TcpConnectionMonitor.cs │ ├── TcpConnectionSsl.cs │ ├── TcpPackageConnection.cs │ └── TcpStats.cs │ ├── UserManagement │ ├── ChangePasswordDetails.cs │ ├── RelLink.cs │ ├── ResetPasswordDetails.cs │ ├── UserCreationInformation.cs │ ├── UserDetails.cs │ ├── UserUpdateInformation.cs │ ├── UsersClient.cs │ └── UsersManager.cs │ └── WriteResult.cs ├── test └── EventStore.ClientAPI.NetCore.Tests │ ├── DefaultData.cs │ ├── EventNumber.cs │ ├── EventStore.ClientAPI.NetCore.Tests.csproj │ ├── FakeEventStoreConnection.cs │ ├── Helpers │ ├── EventDataComparer.cs │ ├── EventsStream.cs │ ├── OngoingTransaction.cs │ ├── StreamWriter.cs │ ├── SystemStreams.cs │ ├── TailWriter.cs │ ├── TcpType.cs │ ├── TestConnection.cs │ ├── TestEvent.cs │ ├── TestNode.cs │ └── TransactionalWriter.cs │ ├── ProjectionSpecification.cs │ ├── Security │ ├── AuthenticationTestBase.cs │ ├── all_stream_with_no_acl_security.cs │ ├── authorized_default_credentials_security.cs │ ├── delete_stream_security.cs │ ├── multiple_role_security.cs │ ├── overriden_system_stream_security.cs │ ├── overriden_system_stream_security_for_all.cs │ ├── overriden_user_stream_security.cs │ ├── read_all_security.cs │ ├── read_stream_meta_security.cs │ ├── read_stream_security.cs │ ├── stream_security_inheritance.cs │ ├── subscribe_to_all_security.cs │ ├── subscribe_to_stream_security.cs │ ├── system_stream_security.cs │ ├── transactional_write_stream_security.cs │ ├── write_stream_meta_security.cs │ └── write_stream_security.cs │ ├── SpecificationWithConnection.cs │ ├── SpecificationWithLinkToToDeletedEvents.cs │ ├── SpecificationWithLinkToToMaxCountDeletedEvents.cs │ ├── SystemData │ └── clientapi_tcp_package.cs │ ├── SystemRoles.cs │ ├── SystemUsers.cs │ ├── UserManagement │ ├── TestWithNode.cs │ ├── TestWithUser.cs │ ├── change_password.cs │ ├── creating_a_user.cs │ ├── deleting_a_user.cs │ ├── enable_disable_user.cs │ ├── get_current_user.cs │ ├── list_users.cs │ ├── reset_password.cs │ └── updating_a_user.cs │ ├── a_nak_in_subscription_handler_in_autoack_mode_drops_the_subscription.cs │ ├── append_to_stream.cs │ ├── appending_to_implicitly_created_stream.cs │ ├── appending_to_implicitly_created_stream_using_transaction.cs │ ├── can_create_duplicate_persistent_subscription_group_name_on_different_streams.cs │ ├── catch_up_subscription_handles_errors.cs │ ├── catchup_subscription_handles_small_batch_sizes.cs │ ├── connect.cs │ ├── connect_to_existing_persistent_subscription_with_max_one_client.cs │ ├── connect_to_existing_persistent_subscription_with_max_one_client_async.cs │ ├── connect_to_existing_persistent_subscription_with_permissions.cs │ ├── connect_to_existing_persistent_subscription_with_permissions_async.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_beginning_and_events_in_it_async.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_beginning_and_no_stream_async.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_async.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_then_event_written.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_two_and_no_stream_async.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_x_set_and_events_in_it_then_event_written.cs │ ├── connect_to_existing_persistent_subscription_with_start_from_x_set_higher_than_x_and_events_in_it_then_event_written.cs │ ├── connect_to_existing_persistent_subscription_without_permissions.cs │ ├── connect_to_existing_persistent_subscription_without_permissions_async.cs │ ├── connect_to_non_existing_persistent_subscription_with_permissions.cs │ ├── connect_to_non_existing_persistent_subscription_with_permissions_async.cs │ ├── connect_to_persistent_subscription_with_retries.cs │ ├── connection_string.cs │ ├── create_duplicate_persistent_subscription_group.cs │ ├── create_persistent_subscription_after_deleting_the_same.cs │ ├── create_persistent_subscription_group_without_permissions.cs │ ├── create_persistent_subscription_on_all_stream.cs │ ├── create_persistent_subscription_on_existing_stream.cs │ ├── create_persistent_subscription_on_non_existing_stream.cs │ ├── create_persistent_subscription_with_dont_timeout.cs │ ├── create_persistent_subscription_with_too_big_checkpoint_after.cs │ ├── create_persistent_subscription_with_too_big_message_timeout.cs │ ├── create_persistent_subscription_with_too_big_retry_after.cs │ ├── deleting_existing_persistent_subscription_group_with_permissions.cs │ ├── deleting_existing_persistent_subscription_with_subscriber.cs │ ├── deleting_persistent_subscription_group_that_doesnt_exist.cs │ ├── deleting_persistent_subscription_group_without_permissions.cs │ ├── deleting_stream.cs │ ├── event_store_connection_should.cs │ ├── happy_case_catching_up_to_link_to_events_auto_ack.cs │ ├── happy_case_catching_up_to_link_to_events_manual_ack.cs │ ├── happy_case_catching_up_to_normal_events_auto_ack.cs │ ├── happy_case_catching_up_to_normal_events_manual_ack.cs │ ├── happy_case_writing_and_subscribing_to_normal_events_auto_ack.cs │ ├── happy_case_writing_and_subscribing_to_normal_events_manual_ack.cs │ ├── not_connected_tests.cs │ ├── read_all_events_backward_should.cs │ ├── read_all_events_forward_should.cs │ ├── read_all_events_forward_with_hard_deleted_stream_should.cs │ ├── read_all_events_forward_with_linkto_passed_max_count.cs │ ├── read_all_events_forward_with_linkto_to_deleted_event.cs │ ├── read_all_events_forward_with_soft_deleted_stream_should.cs │ ├── read_allevents_backward_with_linkto_deleted_event.cs │ ├── read_event_of_linkto_to_deleted_event.cs │ ├── read_event_should.cs │ ├── read_event_stream_backward_should.cs │ ├── read_event_stream_forward_should.cs │ ├── read_stream_events_with_unresolved_linkto.cs │ ├── soft_delete.cs │ ├── ssl_append_to_stream.cs │ ├── subscribe_should.cs │ ├── subscribe_to_all_catching_up_should.cs │ ├── subscribe_to_all_should.cs │ ├── subscribe_to_stream_catching_up_should.cs │ ├── transaction.cs │ ├── update_existing_persistent_subscription.cs │ ├── update_existing_persistent_subscription_with_subscribers.cs │ ├── update_existing_persistent_subscription_without_permissions.cs │ ├── update_non_existing_persistent_subscription.cs │ ├── when_a_projection_is_running.cs │ ├── when_committing_empty_transaction.cs │ ├── when_connecting_with_connection_string.cs │ ├── when_creating_continuous_projection.cs │ ├── when_creating_continuous_projection_with_track_emitted_streams.cs │ ├── when_creating_one_time_projection.cs │ ├── when_creating_transient_projection.cs │ ├── when_disabling_projections.cs │ ├── when_enabling_projections.cs │ ├── when_having_max_count_set_for_stream.cs │ ├── when_having_truncatebefore_set_for_stream.cs │ ├── when_listing_all_projections.cs │ ├── when_listing_continuous_projections.cs │ ├── when_listing_one_time_projections.cs │ ├── when_updating_a_projection_query.cs │ ├── when_working_with_metadata.cs │ ├── when_working_with_stream_metadata_as_byte_array.cs │ ├── when_working_with_stream_metadata_as_structured_info.cs │ └── when_writing_and_subscribing_to_normal_events_manual_nack.cs └── wercker.yml /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | .vscode 4 | .vs 5 | backup 6 | .idea 7 | project.lock.json 8 | *.xproj.user 9 | TestResult.xml 10 | *.nuget.props 11 | *.out 12 | *.ncrunchsolution.user 13 | artifacts/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | # EventStore .NET Core Client 4 | 5 | This repository contained an Event Store .NET client for .NET Core, targetting netstandard-2.0. 6 | 7 | As of version 5.0.0, the official client maintained as part of [github.com/EventStore/EventStore](github.com/EventStore/EventStore) now targets all supported .NET platforms: 8 | 9 | - netstandard2.0 10 | - net452 11 | - net46 12 | 13 | This code and repository is not maintained. 14 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 4.1.0.{build} 2 | 3 | image: Visual Studio 2017 4 | 5 | install: 6 | - ps: .\scripts\updateversion.ps1 7 | - ps: .\scripts\installandruneventstore.ps1 8 | 9 | dotnet_csproj: 10 | patch: true 11 | file: '**\*.csproj' 12 | version: '{version}' 13 | package_version: '{version}' 14 | 15 | configuration: Release 16 | 17 | before_build: 18 | - msbuild /t:restore EventStore.ClientAPI.NetCore.sln 19 | 20 | build: 21 | project: EventStore.ClientAPI.NetCore.sln 22 | publish_nuget: true 23 | verbosity: minimal 24 | 25 | deploy: 26 | provider: NuGet 27 | on: 28 | appveyor_repo_tag: true 29 | api_key: 30 | secure: zd6D5E28IF7m/HSA9k1GUDSzOiWhnrvQUBATrbEqA2MJVh1rDDl+4LDuv+dvioWp 31 | artifact: /.*\.nupkg/ 32 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | dotnet restore src/EventStore.ClientAPI.NetCore/EventStore.ClientAPI.NetCore.csproj 4 | dotnet restore test/EventStore.ClientAPI.NetCore.Tests/EventStore.ClientAPI.NetCore.Tests.csproj 5 | dotnet build src/EventStore.ClientAPI.NetCore/EventStore.ClientAPI.NetCore.csproj 6 | dotnet build test/EventStore.ClientAPI.NetCore.Tests/EventStore.ClientAPI.NetCore.Tests.csproj 7 | dotnet pack src/EventStore.ClientAPI.NetCore/EventStore.ClientAPI.NetCore.csproj -------------------------------------------------------------------------------- /run_suppressed_tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Abort on Error 3 | set -e 4 | 5 | export PING_SLEEP=30s 6 | export WORKDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 7 | export BUILD_OUTPUT=$WORKDIR/build.out 8 | 9 | touch $BUILD_OUTPUT 10 | 11 | dump_output() { 12 | echo Tailing the last 500 lines of output: 13 | tail -500 $BUILD_OUTPUT 14 | } 15 | error_handler() { 16 | echo ERROR: An error was encountered with the build. 17 | dump_output 18 | exit 1 19 | } 20 | # If an error occurs, run our error handler to output a tail of the build 21 | trap 'error_handler' ERR 22 | 23 | # Set up a repeating loop to send some output to Travis. 24 | 25 | bash -c "while true; do echo \$(date) - building ...; sleep $PING_SLEEP; done" & 26 | PING_LOOP_PID=$! 27 | 28 | dotnet test test/EventStore.ClientAPI.NetCore.Tests/EventStore.ClientAPI.NetCore.Tests.csproj >> $BUILD_OUTPUT 2>&1 29 | 30 | # The build finished without returning an error so dump a tail of the output 31 | dump_output 32 | 33 | # nicely terminate the ping output loop 34 | kill $PING_LOOP_PID 35 | -------------------------------------------------------------------------------- /scripts/appveyortest.ps1: -------------------------------------------------------------------------------- 1 | $testResults = Join-Path $env:APPVEYOR_BUILD_FOLDER testResults.xml 2 | dotnet test test\EventStore.ClientAPI.NetCore.Tests\EventStore.ClientAPI.NetCore.Tests.csproj --no-build --logger="trx;LogFileName=$testResults" 3 | $wc = New-Object System.Net.WebClient 4 | $wc.UploadFile("https://ci.appveyor.com/api/testresults/mstest/$env:APPVEYOR_JOB_ID", $testResults) -------------------------------------------------------------------------------- /scripts/installandruneventstore.ps1: -------------------------------------------------------------------------------- 1 | (New-Object Net.WebClient).DownloadFile('https://eventstore.org/downloads/EventStore-OSS-Win-v4.1.0.zip','c:\tools\eventstore.zip') 2 | 7z e C:\tools\eventstore.zip -oC:\tools\EventStore 3 | start-process -NoNewWindow "C:\tools\EventStore\EventStore.ClusterNode.exe" "--memdb --run-projections ALL" -------------------------------------------------------------------------------- /scripts/updateversion.ps1: -------------------------------------------------------------------------------- 1 | 2 | if($env:APPVEYOR_REPO_TAG -eq 'True'){ 3 | Update-AppveyorBuild -version $env:APPVEYOR_REPO_BRANCH 4 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/AllCheckpoint.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// This class contains constants to be used when setting up subscriptions 5 | /// using the IEventStoreConnection.SubscribeToAllFrom method on 6 | /// . 7 | /// 8 | public static class AllCheckpoint 9 | { 10 | /// 11 | /// Indicates that a catch-up subscription should receive all events 12 | /// in the database. 13 | /// 14 | public static Position? AllStart = null; 15 | } 16 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/AllEventsSlice.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Internal; 2 | using EventStore.ClientAPI.Messages; 3 | 4 | namespace EventStore.ClientAPI 5 | { 6 | /// 7 | /// The result of a read operation from the $all stream. 8 | /// 9 | public class AllEventsSlice 10 | { 11 | /// 12 | /// The direction of read request. 13 | /// 14 | public readonly ReadDirection ReadDirection; 15 | 16 | /// 17 | /// A representing the position where this slice was read from. 18 | /// 19 | public readonly Position FromPosition; 20 | 21 | /// 22 | /// A representing the position where the next slice should be read from. 23 | /// 24 | public readonly Position NextPosition; 25 | 26 | /// 27 | /// The events read. 28 | /// 29 | public readonly ResolvedEvent[] Events; 30 | 31 | /// 32 | /// A boolean representing whether or not this is the end of the $all stream. 33 | /// 34 | public bool IsEndOfStream { get { return Events.Length == 0; } } 35 | 36 | internal AllEventsSlice(ReadDirection readDirection, Position fromPosition, Position nextPosition, ClientMessage.ResolvedEvent[] events) 37 | { 38 | ReadDirection = readDirection; 39 | FromPosition = fromPosition; 40 | NextPosition = nextPosition; 41 | if (events == null) 42 | Events = Empty.ResolvedEvents; 43 | else 44 | { 45 | Events = new ResolvedEvent[events.Length]; 46 | for (int i = 0; i < Events.Length; ++i) 47 | { 48 | Events[i] = new ResolvedEvent(events[i]); 49 | } 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ClientApiConstants.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Various constant values that may be useful when working with the ClientAPI. 5 | /// 6 | public static class ClientApiConstants 7 | { 8 | /// 9 | /// The maximum number of events that can be read in a single operation. 10 | /// 11 | public static readonly int MaxReadSize = Consts.MaxReadSize; 12 | } 13 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ClientAuthenticationFailedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | /// 6 | /// Event Arguments for the event raised when an fails 7 | /// to authenticate against an Event Store server. 8 | /// 9 | public class ClientAuthenticationFailedEventArgs : EventArgs 10 | { 11 | /// 12 | /// A reason for authentication failure, if known. 13 | /// 14 | public string Reason { get; private set; } 15 | 16 | /// 17 | /// The responsible for raising the event. 18 | /// 19 | public IEventStoreConnection Connection { get; private set; } 20 | 21 | /// 22 | /// Constructs a new instance of . 23 | /// 24 | /// The responsible for raising the event. 25 | /// A reason for authentication failure, if known. 26 | public ClientAuthenticationFailedEventArgs(IEventStoreConnection connection, string reason) 27 | { 28 | Connection = connection; 29 | Reason = reason; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ClientClosedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | /// 6 | /// Event Arguments for the event raised when an is 7 | /// disconnected from an Event Store server. 8 | /// 9 | public class ClientClosedEventArgs : EventArgs 10 | { 11 | /// 12 | /// A description of the reason the connection was closed if closing was initiated by the server or client API directly 13 | /// rather than by calling . 14 | /// 15 | public string Reason { get; private set; } 16 | 17 | /// 18 | /// The responsible for raising the event. 19 | /// 20 | public IEventStoreConnection Connection { get; private set; } 21 | 22 | /// 23 | /// Constructs a new instance of . 24 | /// 25 | /// The responsible for raising the event. 26 | /// A description of the reason the connection was closed. 27 | public ClientClosedEventArgs(IEventStoreConnection connection, string reason) 28 | { 29 | Connection = connection; 30 | Reason = reason; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ClientConnectionEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace EventStore.ClientAPI 5 | { 6 | /// 7 | /// Event Arguments for the event raised when an is 8 | /// connected to or disconnected from an Event Store server. 9 | /// 10 | public class ClientConnectionEventArgs : EventArgs 11 | { 12 | /// 13 | /// The endpoint of the Event Store server to or from which the connection was connected or disconnected. 14 | /// 15 | public IPEndPoint RemoteEndPoint { get; private set; } 16 | 17 | /// 18 | /// The responsible for raising the event. 19 | /// 20 | public IEventStoreConnection Connection { get; private set; } 21 | 22 | /// 23 | /// Constructs a new instance of . 24 | /// 25 | /// The responsible for raising the event. 26 | /// The endpoint of the Event Store server to or from which the connection was connected or disconnected. 27 | public ClientConnectionEventArgs(IEventStoreConnection connection, IPEndPoint remoteEndPoint) 28 | { 29 | Connection = connection; 30 | RemoteEndPoint = remoteEndPoint; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ClientErrorEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | /// 6 | /// Event Arguments for the event raised when an error occurs on an . 7 | /// 8 | public class ClientErrorEventArgs : EventArgs 9 | { 10 | /// 11 | /// The thrown exception, if one was raised. 12 | /// 13 | public Exception Exception { get; private set; } 14 | 15 | /// 16 | /// The responsible for raising the event. 17 | /// 18 | public IEventStoreConnection Connection { get; private set; } 19 | 20 | /// 21 | /// Constructs a new instance of . 22 | /// 23 | /// The responsible for raising the event. 24 | /// The thrown exception, if one was raised. 25 | public ClientErrorEventArgs(IEventStoreConnection connection, Exception exception) 26 | { 27 | Connection = connection; 28 | Exception = exception; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ClientOperations/IClientOperation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI.SystemData; 3 | 4 | namespace EventStore.ClientAPI.ClientOperations 5 | { 6 | internal interface IClientOperation 7 | { 8 | TcpPackage CreateNetworkPackage(Guid correlationId); 9 | InspectionResult InspectPackage(TcpPackage package); 10 | void Fail(Exception exception); 11 | } 12 | 13 | internal interface ISubscription: IClientOperation 14 | { 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ClientOperations/ISubscriptionOperation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI.SystemData; 3 | using EventStore.ClientAPI.Transport.Tcp; 4 | 5 | namespace EventStore.ClientAPI.ClientOperations 6 | { 7 | internal interface ISubscriptionOperation 8 | { 9 | void DropSubscription(SubscriptionDropReason reason, Exception exc, TcpPackageConnection connection = null); 10 | void ConnectionClosed(); 11 | InspectionResult InspectPackage(TcpPackage package); 12 | bool Subscribe(Guid correlationId, TcpPackageConnection connection); 13 | } 14 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ClientReconnectingEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | /// 6 | /// Event Arguments for the event raised when an is 7 | /// about to reconnect to an Event Store server. 8 | /// 9 | public class ClientReconnectingEventArgs : EventArgs 10 | { 11 | /// 12 | /// The responsible for raising the event. 13 | /// 14 | public IEventStoreConnection Connection { get; private set; } 15 | 16 | /// 17 | /// Constructs a new instance of . 18 | /// 19 | /// The responsible for raising the event. 20 | public ClientReconnectingEventArgs(IEventStoreConnection connection) 21 | { 22 | Connection = connection; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ClusterSettingsBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Builder used for creating instances of ClusterSettings. 5 | /// 6 | public class ClusterSettingsBuilder 7 | { 8 | /// 9 | /// Sets the client to discover nodes using a DNS name and a well-known port. 10 | /// 11 | /// A for further configuration. 12 | public DnsClusterSettingsBuilder DiscoverClusterViaDns() 13 | { 14 | return new DnsClusterSettingsBuilder(); 15 | } 16 | 17 | /// 18 | /// Sets the client to discover cluster nodes by specifying the IP endpoints of 19 | /// one or more of the nodes. 20 | /// 21 | /// 22 | public GossipSeedClusterSettingsBuilder DiscoverClusterViaGossipSeeds() 23 | { 24 | return new GossipSeedClusterSettingsBuilder(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Common/Log/DebugLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI.Common.Log 4 | { 5 | class DebugLogger : ILogger 6 | { 7 | public void Error(string format, params object[] args) 8 | { 9 | System.Diagnostics.Trace.WriteLine(Log("ERROR", format, args)); 10 | } 11 | 12 | public void Error(Exception ex, string format, params object[] args) 13 | { 14 | System.Diagnostics.Trace.WriteLine(Log("ERROR", ex, format, args)); 15 | } 16 | 17 | public void Debug(string format, params object[] args) 18 | { 19 | System.Diagnostics.Trace.WriteLine(Log("DEBUG", format, args)); 20 | } 21 | 22 | public void Debug(Exception ex, string format, params object[] args) 23 | { 24 | System.Diagnostics.Trace.WriteLine(Log("DEBUG", ex, format, args)); 25 | } 26 | 27 | public void Info(string format, params object[] args) 28 | { 29 | System.Diagnostics.Trace.WriteLine(Log("INFO", format, args)); 30 | } 31 | 32 | public void Info(Exception ex, string format, params object[] args) 33 | { 34 | System.Diagnostics.Trace.WriteLine(Log("INFO", ex, format, args)); 35 | } 36 | 37 | 38 | private string Log(string level, string format, params object[] args) 39 | { 40 | return string.Format("{0}: {1}", level, args.Length == 0 ? format : string.Format(format, args)); 41 | } 42 | 43 | private string Log(string level, Exception exc, string format, params object[] args) 44 | { 45 | return string.Format("{0} EXCEPTION: {1}\nException: {2}", level, args.Length == 0 ? format : string.Format(format, args), exc); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Common/Log/FileLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace EventStore.ClientAPI.Common.Log 5 | { 6 | /// 7 | /// Logger that writes to a file 8 | /// 9 | class FileLogger : ILogger, IDisposable 10 | { 11 | private readonly StreamWriter _streamWriter; 12 | 13 | public FileLogger(string filename) 14 | { 15 | _streamWriter = new StreamWriter(new FileStream(filename, FileMode.OpenOrCreate)) {AutoFlush = true}; 16 | } 17 | 18 | public void Error(string format, params object[] args) 19 | { 20 | _streamWriter.WriteLine("Error: " + format, args); 21 | } 22 | 23 | public void Error(Exception ex, string format, params object[] args) 24 | { 25 | _streamWriter.WriteLine("Error: " + format, args); 26 | _streamWriter.WriteLine(ex); 27 | } 28 | 29 | public void Info(string format, params object[] args) 30 | { 31 | _streamWriter.WriteLine("Info : " + format, args); 32 | } 33 | 34 | public void Info(Exception ex, string format, params object[] args) 35 | { 36 | _streamWriter.WriteLine("Info : " + format, args); 37 | _streamWriter.WriteLine(ex); 38 | } 39 | 40 | public void Debug(string format, params object[] args) 41 | { 42 | _streamWriter.WriteLine("Debug: " + format, args); 43 | } 44 | 45 | public void Debug(Exception ex, string format, params object[] args) 46 | { 47 | _streamWriter.WriteLine("Debug: " + format, args); 48 | _streamWriter.WriteLine(ex); 49 | 50 | } 51 | 52 | void IDisposable.Dispose() 53 | { 54 | _streamWriter.Dispose(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Common/Log/LogManager.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Common.Log 2 | { 3 | /* public static class LogManager 4 | { 5 | private static readonly ILogger Default = new DebugLogger(); 6 | 7 | private static ILogger _defaultLogger; 8 | private static ILogger _userLogger; 9 | 10 | public static ILogger GetLogger() 11 | { 12 | return _userLogger ?? _defaultLogger ?? Default; 13 | } 14 | 15 | public static void SetDefaultLogger(ILogger logger) 16 | { 17 | _defaultLogger = logger; 18 | } 19 | 20 | public static void RegisterLogger(ILogger logger) 21 | { 22 | _userLogger = logger; 23 | } 24 | }*/ 25 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Common/Log/NoopLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI.Common.Log 4 | { 5 | class NoopLogger : ILogger 6 | { 7 | public void Error(string format, params object[] args) 8 | { 9 | } 10 | 11 | public void Error(Exception ex, string format, params object[] args) 12 | { 13 | } 14 | 15 | public void Debug(string format, params object[] args) 16 | { 17 | } 18 | 19 | public void Debug(Exception ex, string format, params object[] args) 20 | { 21 | } 22 | 23 | public void Info(string format, params object[] args) 24 | { 25 | } 26 | 27 | public void Info(Exception ex, string format, params object[] args) 28 | { 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Common/Utils/Ensure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI.Common.Utils 4 | { 5 | static class Ensure 6 | { 7 | public static void NotNull(T argument, string argumentName) where T : class 8 | { 9 | if (argument == null) 10 | throw new ArgumentNullException(argumentName); 11 | } 12 | 13 | public static void NotNullOrEmpty(string argument, string argumentName) 14 | { 15 | if (string.IsNullOrEmpty(argument)) 16 | throw new ArgumentNullException(argument, argumentName); 17 | } 18 | 19 | public static void Positive(int number, string argumentName) 20 | { 21 | if (number <= 0) 22 | throw new ArgumentOutOfRangeException(argumentName, argumentName + " should be positive."); 23 | } 24 | 25 | public static void Positive(long number, string argumentName) 26 | { 27 | if (number <= 0) 28 | throw new ArgumentOutOfRangeException(argumentName, argumentName + " should be positive."); 29 | } 30 | 31 | public static void Nonnegative(long number, string argumentName) 32 | { 33 | if (number < 0) 34 | throw new ArgumentOutOfRangeException(argumentName, argumentName + " should be non-negative."); 35 | } 36 | 37 | public static void Nonnegative(int number, string argumentName) 38 | { 39 | if (number < 0) 40 | throw new ArgumentOutOfRangeException(argumentName, argumentName + " should be non-negative."); 41 | } 42 | 43 | public static void NotEmptyGuid(Guid guid, string argumentName) 44 | { 45 | if (Guid.Empty == guid) 46 | throw new ArgumentException(argumentName, argumentName + " should be non-empty GUID."); 47 | } 48 | 49 | public static void Equal(int expected, int actual) 50 | { 51 | if (expected != actual) 52 | throw new Exception(string.Format("expected {0} actual {1}", expected, actual)); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Common/Utils/Threading/ManualResetEventSlimExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace EventStore.ClientAPI.Common.Utils.Threading 5 | { 6 | internal static class ManualResetEventSlimExtensions 7 | { 8 | public static Task AsTask(this ManualResetEventSlim resetEvent) 9 | { 10 | return AsTask(resetEvent, Timeout.Infinite); 11 | } 12 | 13 | public static Task AsTask(this ManualResetEventSlim resetEvent, int timeoutMs) 14 | { 15 | TaskCompletionSource tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); 16 | 17 | RegisteredWaitHandle registration = ThreadPool.RegisterWaitForSingleObject(resetEvent.WaitHandle, (state, timedOut) => 18 | { 19 | if (timedOut) 20 | { 21 | tcs.SetCanceled(); 22 | } 23 | else 24 | { 25 | tcs.SetResult(null); 26 | } 27 | }, null, timeoutMs, true); 28 | 29 | tcs.Task.ContinueWith(_ => registration.Unregister(null)); 30 | 31 | return tcs.Task; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Common/Utils/Threading/TaskExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using EventStore.ClientAPI.Exceptions; 4 | 5 | namespace EventStore.ClientAPI.Common.Utils.Threading 6 | { 7 | internal static class TaskExtensions 8 | { 9 | public static async Task WithTimeout(this Task task, TimeSpan timeout) 10 | { 11 | if (await Task.WhenAny(task, Task.Delay(timeout)) != task) 12 | { 13 | throw new OperationTimedOutException(string.Format("The operation did not complete within the specified time of {0}", timeout)); 14 | } 15 | 16 | return await task; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ConditionalWriteFailureReason.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// The reason why a conditional write fails 5 | /// 6 | public enum ConditionalWriteStatus 7 | { 8 | /// 9 | /// The write operation succeeded 10 | /// 11 | Succeeded = 0, 12 | /// 13 | /// The expected version does not match actual stream version 14 | /// 15 | VersionMismatch = 1, 16 | /// 17 | /// The stream has been deleted 18 | /// 19 | StreamDeleted = 2 20 | } 21 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ConditionalWriteResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | /// 6 | /// Result type returned after conditionally writing to a stream. 7 | /// 8 | public struct ConditionalWriteResult 9 | { 10 | /// 11 | /// Returns if the write was successful. 12 | /// 13 | public readonly ConditionalWriteStatus Status; 14 | 15 | /// 16 | /// The next expected version for the stream. 17 | /// 18 | public readonly long? NextExpectedVersion; 19 | 20 | /// 21 | /// The of the write. 22 | /// 23 | public readonly Position? LogPosition; 24 | 25 | /// 26 | /// Constructs a new . 27 | /// 28 | /// The next expected version for the stream. 29 | /// The position of the write in the log 30 | public ConditionalWriteResult(long nextExpectedVersion, Position logPosition) 31 | { 32 | LogPosition = logPosition; 33 | NextExpectedVersion = nextExpectedVersion; 34 | Status = ConditionalWriteStatus.Succeeded; 35 | } 36 | 37 | /// 38 | /// Constructs a new . 39 | /// 40 | /// The status of the write operation. 41 | public ConditionalWriteResult(ConditionalWriteStatus status) 42 | { 43 | if (status == ConditionalWriteStatus.Succeeded) 44 | { 45 | throw new Exception("For successful write pass next expected version and log position."); 46 | } 47 | LogPosition = null; 48 | NextExpectedVersion = null; 49 | Status = status; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/DeleteResult.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Result type returned after deleting a stream. 5 | /// 6 | public struct DeleteResult 7 | { 8 | /// 9 | /// The of the write. 10 | /// 11 | public readonly Position LogPosition; 12 | 13 | /// 14 | /// Constructs a new . 15 | /// 16 | /// The position of the write in the log 17 | public DeleteResult(Position logPosition) 18 | { 19 | LogPosition = logPosition; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/EventData.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Internal; 2 | using System; 3 | 4 | namespace EventStore.ClientAPI 5 | { 6 | /// 7 | /// Represents an event to be written. 8 | /// 9 | public sealed class EventData 10 | { 11 | /// 12 | /// The ID of the event, used as part of the idempotent write check. 13 | /// 14 | public readonly Guid EventId; 15 | 16 | /// 17 | /// The name of the event type. It is strongly recommended that these 18 | /// use lowerCamelCase if projections are to be used. 19 | /// 20 | public readonly string Type; 21 | 22 | /// 23 | /// Flag indicating whether the data and metadata are JSON. 24 | /// 25 | public readonly bool IsJson; 26 | 27 | /// 28 | /// The raw bytes of the event data. 29 | /// 30 | public readonly byte[] Data; 31 | 32 | /// 33 | /// The raw bytes of the event metadata. 34 | /// 35 | public readonly byte[] Metadata; 36 | 37 | /// 38 | /// Constructs a new . 39 | /// 40 | /// The ID of the event, used as part of the idempotent write check. 41 | /// The name of the event type. It is strongly recommended that these 42 | /// use lowerCamelCase if projections are to be used. 43 | /// Flag indicating whether the data and metadata are JSON. 44 | /// The raw bytes of the event data. 45 | /// The raw bytes of the event metadata. 46 | public EventData(Guid eventId, string type, bool isJson, byte[] data, byte[] metadata) 47 | { 48 | EventId = eventId; 49 | Type = type; 50 | IsJson = isJson; 51 | Data = data ?? Empty.ByteArray; 52 | Metadata = metadata ?? Empty.ByteArray; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/EventReadResult.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Common.Utils; 2 | using EventStore.ClientAPI.Messages; 3 | 4 | namespace EventStore.ClientAPI 5 | { 6 | /// 7 | /// A event read result is the result of a single event read operation to Event Store. 8 | /// 9 | public class EventReadResult 10 | { 11 | /// 12 | /// The representing the status of this read attempt. 13 | /// 14 | public readonly EventReadStatus Status; 15 | 16 | /// 17 | /// The name of the stream read. 18 | /// 19 | public readonly string Stream; 20 | 21 | /// 22 | /// The event number of the requested event. 23 | /// 24 | public readonly long EventNumber; 25 | 26 | /// 27 | /// The event read represented as . 28 | /// 29 | public readonly ResolvedEvent? Event; 30 | 31 | internal EventReadResult(EventReadStatus status, 32 | string stream, 33 | long eventNumber, 34 | ClientMessage.ResolvedIndexedEvent @event) 35 | { 36 | Ensure.NotNullOrEmpty(stream, "stream"); 37 | 38 | Status = status; 39 | Stream = stream; 40 | EventNumber = eventNumber; 41 | Event = status == EventReadStatus.Success ? new ResolvedEvent(@event) : (ResolvedEvent?)null; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/EventReadStatus.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Enumeration representing the status of a single event read operation. 5 | /// 6 | public enum EventReadStatus 7 | { 8 | /// 9 | /// The read operation was successful. 10 | /// 11 | Success = 0, 12 | /// 13 | /// The event was not found. 14 | /// 15 | NotFound = 1, 16 | /// 17 | /// The stream was not found. 18 | /// 19 | NoStream = 2, 20 | /// 21 | /// The stream previously existed but was deleted. 22 | /// 23 | StreamDeleted = 3, 24 | } 25 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/EventStore.ClientAPI.NetCore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netstandard2.0 4 | EventStore.ClientAPI 5 | 6 | 7 | EventStore.ClientAPI 8 | EventStore NetStandard ClientApi 9 | Event Store LLP 10 | Copyright © Event Store LLP. All rights reserved. 11 | EventStore.ClientAPI 12 | 4.1.1-rc 13 | 14 | 15 | The client API for the Event Store. Get the open source or commercial versions of the Event Store server from http://geteventstore.com 16 | Event Store LLP 17 | portable 18 | EventStore.ClientAPI.NetCore 19 | EventStore.ClientAPI.NetCore 20 | eventstore;client;netstandard2.0 21 | http://geteventstore.com/assets/ouro-200.png 22 | https://github.com/EventStore/netcore-client/blob/master/LICENSE.md 23 | git 24 | https://github.com/EventStore/ClientAPI.NetCore 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/EventStoreSubscription.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | /// 6 | /// Represents a subscription to a single stream or to the stream 7 | /// of all events in the Event Store. 8 | /// 9 | public abstract class EventStoreSubscription : IDisposable 10 | { 11 | /// 12 | /// True if this subscription is to all streams. 13 | /// 14 | public bool IsSubscribedToAll { get { return StreamId == string.Empty; } } 15 | /// 16 | /// The name of the stream to which the subscription is subscribed. 17 | /// 18 | public string StreamId { get; } 19 | /// 20 | /// The last commit position seen on the subscription (if this is 21 | /// a subscription to all events). 22 | /// 23 | public readonly long LastCommitPosition; 24 | /// 25 | /// The last event number seen on the subscription (if this is a 26 | /// subscription to a single stream). 27 | /// 28 | public readonly long? LastEventNumber; 29 | 30 | internal EventStoreSubscription(string streamId, long lastCommitPosition, long? lastEventNumber) 31 | { 32 | StreamId = streamId; 33 | LastCommitPosition = lastCommitPosition; 34 | LastEventNumber = lastEventNumber; 35 | } 36 | 37 | /// 38 | /// Unsubscribes from the stream. 39 | /// 40 | public void Dispose() 41 | { 42 | Unsubscribe(); 43 | } 44 | 45 | /// 46 | /// Unsubscribes from the stream. 47 | /// 48 | public void Close() 49 | { 50 | Unsubscribe(); 51 | } 52 | 53 | /// 54 | ///Unsubscribes from the stream 55 | /// 56 | public abstract void Unsubscribe(); 57 | } 58 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/AccessDeniedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown when a user is not authorised to carry out 8 | /// an operation. 9 | /// 10 | public class AccessDeniedException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new . 14 | /// 15 | public AccessDeniedException(): base("Access denied") 16 | { 17 | } 18 | 19 | /// 20 | /// Constructs a new . 21 | /// 22 | public AccessDeniedException(string message) : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// Constructs a new . 28 | /// 29 | public AccessDeniedException(string message, Exception innerException) : base(message, innerException) 30 | { 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/CannotEstablishConnectionException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if an is 8 | /// unable to establish a connection to an Event Store server. 9 | /// 10 | public class CannotEstablishConnectionException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new . 14 | /// 15 | public CannotEstablishConnectionException() 16 | { 17 | } 18 | 19 | /// 20 | /// Constructs a new . 21 | /// 22 | public CannotEstablishConnectionException(string message) : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// Constructs a new . 28 | /// 29 | public CannotEstablishConnectionException(string message, 30 | Exception innerException) : base(message, innerException) 31 | { 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/ClusterException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if cluster discovery fails. 8 | /// 9 | public class ClusterException : EventStoreConnectionException 10 | { 11 | /// 12 | /// Constructs a new . 13 | /// 14 | public ClusterException() 15 | { 16 | } 17 | 18 | /// 19 | /// Constructs a new . 20 | /// 21 | public ClusterException(string message) 22 | : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// Constructs a new . 28 | /// 29 | public ClusterException(string message, Exception innerException) 30 | : base(message, innerException) 31 | { 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/CommandNotExpectedException.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Exceptions 2 | { 3 | /// 4 | /// Exception thrown if an unexpected command is received. 5 | /// 6 | public class CommandNotExpectedException : EventStoreConnectionException 7 | { 8 | /// 9 | /// Constructs a new . 10 | /// 11 | public CommandNotExpectedException(string expected, string actual) 12 | : base(string.Format("Expected : {0}. Actual : {1}.", expected, actual)) 13 | { 14 | } 15 | 16 | /// 17 | /// Constructs a new . 18 | /// 19 | public CommandNotExpectedException(string unexpectedCommand) 20 | : base(string.Format("Unexpected command: {0}.", unexpectedCommand)) 21 | { 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/ConnectionClosedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown by ongoing operations which are terminated 8 | /// by an closing. 9 | /// 10 | public class ConnectionClosedException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new . 14 | /// 15 | public ConnectionClosedException() 16 | { 17 | } 18 | 19 | /// 20 | /// Constructs a new . 21 | /// 22 | public ConnectionClosedException(string message) : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// Constructs a new . 28 | /// 29 | public ConnectionClosedException(string message, Exception innerException) : base(message, innerException) 30 | { 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/EventStoreConnectionException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI.Exceptions 4 | { 5 | /// 6 | /// Base type for exceptions thrown by an , 7 | /// thrown in circumstances which do not have a specific derived exception. 8 | /// 9 | public class EventStoreConnectionException : Exception 10 | { 11 | /// 12 | /// Constructs a new . 13 | /// 14 | public EventStoreConnectionException() 15 | { 16 | } 17 | 18 | /// 19 | /// Constructs a new . 20 | /// 21 | public EventStoreConnectionException(string message): base(message) 22 | { 23 | } 24 | 25 | /// 26 | /// Constructs a new . 27 | /// 28 | public EventStoreConnectionException(string message, Exception innerException): base(message, innerException) 29 | { 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/InvalidTransactionException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if there is an attempt to operate inside a 8 | /// transaction which does not exist. 9 | /// 10 | public class InvalidTransactionException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new . 14 | /// 15 | public InvalidTransactionException() 16 | { 17 | } 18 | 19 | /// 20 | /// Constructs a new . 21 | /// 22 | public InvalidTransactionException(string message) : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// Constructs a new . 28 | /// 29 | public InvalidTransactionException(string message, Exception innerException) : base(message, innerException) 30 | { 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/NoResultException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if there is no result for an operation for 8 | /// which one is expected. 9 | /// 10 | public class NoResultException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new . 14 | /// 15 | public NoResultException() 16 | { 17 | } 18 | 19 | /// 20 | /// Constructs a new . 21 | /// 22 | public NoResultException(string message) : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// Constructs a new . 28 | /// 29 | public NoResultException(string message, Exception innerException) : base(message, innerException) 30 | { 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/NotAuthenticatedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if an operation requires authentication but 8 | /// the client is not authenticated. 9 | /// 10 | public class NotAuthenticatedException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new . 14 | /// 15 | public NotAuthenticatedException(): base("Authentication error") 16 | { 17 | } 18 | 19 | /// 20 | /// Constructs a new . 21 | /// 22 | public NotAuthenticatedException(string message) : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// Constructs a new . 28 | /// 29 | public NotAuthenticatedException(string message, Exception innerException) : base(message, innerException) 30 | { 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/OperationExpiredException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace EventStore.ClientAPI.Exceptions 6 | { 7 | /// 8 | /// Exception thrown if an operation expires before it can be scheduled. 9 | /// 10 | public class OperationExpiredException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new . 14 | /// 15 | public OperationExpiredException() 16 | { 17 | } 18 | 19 | /// 20 | /// Constructs a new . 21 | /// 22 | /// 23 | public OperationExpiredException(string message) : base(message) 24 | { 25 | } 26 | 27 | /// 28 | /// Constructs a new . 29 | /// 30 | public OperationExpiredException(string message, Exception innerException):base(message, innerException) 31 | { 32 | 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/OperationTimedOutException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if an operation times out. 8 | /// 9 | public class OperationTimedOutException : EventStoreConnectionException 10 | { 11 | /// 12 | /// Constructs a new . 13 | /// 14 | public OperationTimedOutException() 15 | { 16 | } 17 | 18 | /// 19 | /// Constructs a new . 20 | /// 21 | public OperationTimedOutException(string message) : base(message) 22 | { 23 | } 24 | 25 | /// 26 | /// Constructs a new . 27 | /// 28 | public OperationTimedOutException(string message, Exception innerException) : base(message, innerException) 29 | { 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/ProjectionCommandConflictException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if a projection command fails. 8 | /// 9 | public class ProjectionCommandConflictException : ProjectionCommandFailedException 10 | { 11 | /// 12 | /// Constructs a new . 13 | /// 14 | public ProjectionCommandConflictException() 15 | { 16 | } 17 | 18 | /// 19 | /// Constructs a new . 20 | /// 21 | public ProjectionCommandConflictException(int httpStatusCode, string message) 22 | : base(httpStatusCode, message) 23 | { 24 | } 25 | 26 | /// 27 | /// Constructs a new . 28 | /// 29 | public ProjectionCommandConflictException(string message, 30 | Exception innerException) 31 | : base(message, innerException) 32 | { 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/ProjectionCommandFailedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if a projection command fails. 8 | /// 9 | public class ProjectionCommandFailedException : EventStoreConnectionException 10 | { 11 | /// 12 | /// The Http status code returned by the server 13 | /// 14 | public int HttpStatusCode { get; private set; } 15 | 16 | /// 17 | /// Constructs a new . 18 | /// 19 | public ProjectionCommandFailedException() 20 | { 21 | } 22 | 23 | /// 24 | /// Constructs a new . 25 | /// 26 | public ProjectionCommandFailedException(int httpStatusCode, string message) 27 | : base(message) 28 | { 29 | HttpStatusCode = httpStatusCode; 30 | } 31 | 32 | /// 33 | /// Constructs a new . 34 | /// 35 | public ProjectionCommandFailedException(string message, 36 | Exception innerException) 37 | : base(message, innerException) 38 | { 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/RetriesLimitReachedException.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Exceptions 2 | { 3 | /// 4 | /// Exception thrown if the number of retries for an operation is reached. 5 | /// To change the number of retries attempted for an operation, use the methods 6 | /// or 7 | /// and pass the resulting 8 | /// into the constructor of the connection. 9 | /// 10 | public class RetriesLimitReachedException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new instance of . 14 | /// 15 | /// The number of retries attempted. 16 | public RetriesLimitReachedException(int retries) 17 | : base(string.Format("Reached retries limit : {0}", retries)) 18 | { 19 | } 20 | 21 | /// 22 | /// Constructs a new instance of . 23 | /// 24 | /// The name of the item for which retries were attempted. 25 | /// The number of retries attempted. 26 | public RetriesLimitReachedException(string item, int retries) 27 | : base(string.Format("Item {0} reached retries limit : {1}", item, retries)) 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/ServerErrorException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if a server-side error occurs during an 8 | /// operation. 9 | /// 10 | public class ServerErrorException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new instance of . 14 | /// 15 | public ServerErrorException() 16 | { 17 | } 18 | 19 | /// 20 | /// Constructs a new instance of . 21 | /// 22 | public ServerErrorException(string message) 23 | : base(string.Format("Unexpected error on server: {0}", message)) 24 | { 25 | } 26 | 27 | /// 28 | /// Constructs a new instance of . 29 | /// 30 | public ServerErrorException(string message, Exception innerException) 31 | : base(string.Format("Unexpected error on server: {0}", message), innerException) 32 | { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/StreamDeletedException.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Common.Utils; 2 | 3 | namespace EventStore.ClientAPI.Exceptions 4 | { 5 | /// 6 | /// Exception thrown if an operation is attempted on a stream which 7 | /// has been deleted. 8 | /// 9 | public class StreamDeletedException : EventStoreConnectionException 10 | { 11 | /// 12 | /// The name of the deleted stream. 13 | /// 14 | public readonly string Stream; 15 | 16 | /// 17 | /// Constructs a new instance of . 18 | /// 19 | /// The name of the deleted stream. 20 | public StreamDeletedException(string stream) 21 | : base(string.Format("Event stream '{0}' is deleted.", stream)) 22 | { 23 | Ensure.NotNullOrEmpty(stream, "stream"); 24 | Stream = stream; 25 | } 26 | 27 | /// 28 | /// Constructs a new instance of . 29 | /// 30 | public StreamDeletedException() 31 | : base("Transaction failed due to underlying stream being deleted.") 32 | { 33 | Stream = null; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/UserCommandConflictException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if a user command fails. 8 | /// 9 | public class UserCommandConflictException : ProjectionCommandFailedException 10 | { 11 | /// 12 | /// Constructs a new . 13 | /// 14 | public UserCommandConflictException() 15 | { 16 | } 17 | 18 | /// 19 | /// Constructs a new . 20 | /// 21 | public UserCommandConflictException(int httpStatusCode, string message) 22 | : base(httpStatusCode, message) 23 | { 24 | } 25 | 26 | /// 27 | /// Constructs a new . 28 | /// 29 | public UserCommandConflictException(string message, 30 | Exception innerException) 31 | : base(message, innerException) 32 | { 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/UserCommandFailedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if a projection command fails. 8 | /// 9 | public class UserCommandFailedException : EventStoreConnectionException 10 | { 11 | /// 12 | /// The Http status code returned for the operation 13 | /// 14 | public int HttpStatusCode { get; private set; } 15 | 16 | /// 17 | /// Constructs a new . 18 | /// 19 | public UserCommandFailedException() 20 | { 21 | } 22 | 23 | /// 24 | /// Constructs a new . 25 | /// 26 | public UserCommandFailedException(int httpStatusCode, string message) : base(message) 27 | { 28 | HttpStatusCode = httpStatusCode; 29 | } 30 | 31 | /// 32 | /// Constructs a new . 33 | /// 34 | public UserCommandFailedException(string message, 35 | Exception innerException) : base(message, innerException) 36 | { 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Exceptions/WrongExpectedVersionException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Exceptions 5 | { 6 | /// 7 | /// Exception thrown if the expected version specified on an operation 8 | /// does not match the version of the stream when the operation was attempted. 9 | /// 10 | public class WrongExpectedVersionException : EventStoreConnectionException 11 | { 12 | /// 13 | /// Constructs a new instance of . 14 | /// 15 | public WrongExpectedVersionException(string message) : base(message) 16 | { 17 | } 18 | 19 | /// 20 | /// Constructs a new instance of . 21 | /// 22 | public WrongExpectedVersionException(string message, Exception innerException) : base(message, innerException) 23 | { 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ExpectedVersion.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Constants used for expected version control 5 | /// 6 | /// 7 | /// The use of expected version can be a bit tricky especially when discussing idempotency assurances given by the event store. 8 | /// 9 | /// There are five possible values that can be used for the passing of an expected version. 10 | /// 11 | /// ExpectedVersion.Any (-2) says that you should not conflict with anything. 12 | /// ExpectedVersion.NoStream (-1) says that the stream should not exist when doing your write. 13 | /// ExpectedVersion.EmptyStream (0) says the stream should exist but be empty when doing the write. 14 | /// ExpectedVersion.StreamExists(-4) says the stream or a metadata stream should exist when doing your write. 15 | /// 16 | /// Any other value states that the last event written to the stream should have a sequence number matching your 17 | /// expected value. 18 | /// 19 | /// The Event Store will assure idempotency for all operations using any value in ExpectedVersion except for 20 | /// ExpectedVersion.Any and ExpectedVersion.StreamExists. When using ExpectedVersion.Any or ExpectedVersion.StreamExists 21 | /// the Event Store will do its best to assure idempotency but will not guarantee idempotency. 22 | /// 23 | public static class ExpectedVersion 24 | { 25 | /// 26 | /// This write should not conflict with anything and should always succeed. 27 | /// 28 | public const long Any = -2; 29 | /// 30 | /// The stream being written to should not yet exist. If it does exist treat that as a concurrency problem. 31 | /// 32 | public const long NoStream = -1; 33 | /// 34 | /// The stream should exist and should be empty. If it does not exist or is not empty treat that as a concurrency problem. 35 | /// 36 | public const long EmptyStream = -1; 37 | 38 | /// 39 | /// The stream should exist. If it or a metadata stream does not exist treat that as a concurrency problem. 40 | /// 41 | public const long StreamExists = -4; 42 | } 43 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/GossipSeed.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | /// 6 | /// Represents a source of cluster gossip. 7 | /// 8 | public class GossipSeed 9 | { 10 | /// 11 | /// The for the External HTTP endpoint of the gossip seed. 12 | /// 13 | /// The HTTP endpoint is used rather than the TCP endpoint because it is required 14 | /// for the client to exchange gossip with the server. The standard port which should be 15 | /// used here is 2113. 16 | /// 17 | public readonly IPEndPoint EndPoint; 18 | /// 19 | /// The host header to be sent when requesting gossip. 20 | /// 21 | public readonly string HostHeader; 22 | 23 | /// 24 | /// Creates a new . 25 | /// 26 | /// The for the External HTTP endpoint of the gossip seed. The standard port is 2113. 27 | /// The host header to be sent when requesting gossip. Defaults to String.Empty 28 | public GossipSeed(IPEndPoint endPoint, string hostHeader = "") 29 | { 30 | EndPoint = endPoint; 31 | HostHeader = hostHeader; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/IConnectToPersistentSubscriptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | internal interface IConnectToPersistentSubscriptions 6 | { 7 | void NotifyEventsProcessed(Guid[] processedEvents); 8 | void NotifyEventsFailed(Guid[] processedEvents, PersistentSubscriptionNakEventAction action, string reason); 9 | void Unsubscribe(); 10 | } 11 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/IEndPointDiscoverer.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Threading.Tasks; 3 | 4 | namespace EventStore.ClientAPI 5 | { 6 | /// 7 | /// Represents a way of discovering cluster endpoints. This could be through gossip, consul, text files, etc 8 | /// 9 | public interface IEndPointDiscoverer 10 | { 11 | /// 12 | /// Called to discover a new 13 | /// 14 | /// The The recently failed endpoint 15 | /// 16 | Task DiscoverAsync(IPEndPoint failedTcpEndPoint); 17 | } 18 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/Consts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | internal static class Consts 6 | { 7 | public const int DefaultMaxQueueSize = 5000; 8 | public const int DefaultMaxConcurrentItems = 5000; 9 | public const int DefaultMaxOperationRetries = 10; 10 | public const int DefaultMaxReconnections = 10; 11 | 12 | public const bool DefaultRequireMaster = true; 13 | 14 | public static readonly TimeSpan DefaultReconnectionDelay = TimeSpan.FromMilliseconds(100); 15 | public static readonly TimeSpan DefaultQueueTimeout = TimeSpan.Zero; //unlimited 16 | public static readonly TimeSpan DefaultOperationTimeout = TimeSpan.FromSeconds(7); 17 | public static readonly TimeSpan DefaultOperationTimeoutCheckPeriod = TimeSpan.FromSeconds(1); 18 | 19 | public static readonly TimeSpan TimerPeriod = TimeSpan.FromMilliseconds(200); 20 | public static readonly int MaxReadSize = 4096; 21 | public const int DefaultMaxClusterDiscoverAttempts = 10; 22 | public const int DefaultClusterManagerExternalHttpPort = 30778; 23 | 24 | public const int CatchUpDefaultReadBatchSize = 500; 25 | public const int CatchUpDefaultMaxPushQueueSize = 10000; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/Empty.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json.Linq; 4 | 5 | namespace EventStore.ClientAPI.Internal 6 | { 7 | internal static class Empty 8 | { 9 | public static readonly byte[] ByteArray = new byte[0]; 10 | public static readonly string[] StringArray = new string[0]; 11 | public static readonly ResolvedEvent[] ResolvedEvents = new ResolvedEvent[0]; 12 | 13 | public static readonly Action Action = () => { }; 14 | 15 | public static readonly IDictionary CustomStreamMetadata = new Dictionary(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/IEventStoreConnectionLogicHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI.Internal 4 | { 5 | internal interface IEventStoreConnectionLogicHandler 6 | { 7 | int TotalOperationCount { get; } 8 | void EnqueueMessage(Message message); 9 | event EventHandler Connected; 10 | event EventHandler Disconnected; 11 | event EventHandler Reconnecting; 12 | event EventHandler Closed; 13 | event EventHandler ErrorOccurred; 14 | event EventHandler AuthenticationFailed; 15 | } 16 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/IEventStoreTransactionConnection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using EventStore.ClientAPI.SystemData; 4 | 5 | namespace EventStore.ClientAPI.Internal 6 | { 7 | internal interface IEventStoreTransactionConnection 8 | { 9 | /// 10 | /// Writes to a transaction in the event store asynchronously 11 | /// 12 | /// 13 | /// A allows the calling of multiple writes with multiple 14 | /// round trips over long periods of time between the caller and the event store. This method 15 | /// is only available through the TCP interface and no equivalent exists for the RESTful interface. 16 | /// 17 | /// The to write to. 18 | /// The events to write 19 | /// The optional user credentials to perform operation with. 20 | /// A allowing the caller to control the async operation 21 | Task TransactionalWriteAsync(EventStoreTransaction transaction, IEnumerable events, UserCredentials userCredentials = null); 22 | 23 | /// 24 | /// Commits a multi-write transaction in the Event Store 25 | /// 26 | /// The to commit 27 | /// The optional user credentials to perform operation with. 28 | Task CommitTransactionAsync(EventStoreTransaction transaction, UserCredentials userCredentials = null); 29 | } 30 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/IPEndPointExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace EventStore.ClientAPI.Internal 5 | { 6 | static class IPEndPointExtensions 7 | { 8 | public static Uri ToESTcpUri(this IPEndPoint ipEndPoint) 9 | { 10 | return new Uri(string.Format("tcp://{0}:{1}", ipEndPoint.Address, ipEndPoint.Port)); 11 | } 12 | 13 | public static Uri ToESTcpUri(this IPEndPoint ipEndPoint, string username, string password) 14 | { 15 | return new Uri(string.Format("tcp://{0}:{1}@{2}:{3}", username, password, ipEndPoint.Address, ipEndPoint.Port)); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/PersistentSubscriptionCreateResult.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Internal 2 | { 3 | /// 4 | /// A Persistent Subscription Create Result is the result of a single operation creating a 5 | /// persistent subscription in the event store 6 | /// 7 | class PersistentSubscriptionCreateResult 8 | { 9 | /// 10 | /// The representing the status of this create attempt 11 | /// 12 | public readonly PersistentSubscriptionCreateStatus Status; 13 | 14 | internal PersistentSubscriptionCreateResult(PersistentSubscriptionCreateStatus status) 15 | { 16 | Status = status; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/PersistentSubscriptionCreateStatus.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Internal 2 | { 3 | /// 4 | /// Enumeration representing the status of a single subscription create message. 5 | /// 6 | enum PersistentSubscriptionCreateStatus 7 | { 8 | /// 9 | /// The subscription was created successfully 10 | /// 11 | Success = 0, 12 | /// 13 | /// The subscription already exists 14 | /// 15 | NotFound = 1, 16 | /// 17 | /// Some failure happened creating the subscription 18 | /// 19 | Failure = 2, 20 | } 21 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/PersistentSubscriptionDeleteResult.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Internal 2 | { 3 | /// 4 | /// A Persistent Subscription Delete Result is the result of a single operation deleting a 5 | /// persistent subscription in the event store 6 | /// 7 | class PersistentSubscriptionDeleteResult 8 | { 9 | /// 10 | /// The representing the status of this create attempt 11 | /// 12 | public readonly PersistentSubscriptionDeleteStatus Status; 13 | 14 | internal PersistentSubscriptionDeleteResult(PersistentSubscriptionDeleteStatus status) 15 | { 16 | Status = status; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/PersistentSubscriptionDeleteStatus.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Internal 2 | { 3 | /// 4 | /// Enumeration representing the status of a single subscription delete message. 5 | /// 6 | enum PersistentSubscriptionDeleteStatus 7 | { 8 | /// 9 | /// The subscription was created successfully 10 | /// 11 | Success = 0, 12 | /// 13 | /// Some failure happened creating the subscription 14 | /// 15 | Failure = 1, 16 | } 17 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/PersistentSubscriptionUpdateResult.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Internal 2 | { 3 | /// 4 | /// A Persistent Subscription Create Result is the result of a single operation updating a 5 | /// persistent subscription in the event store 6 | /// 7 | public class PersistentSubscriptionUpdateResult 8 | { 9 | /// 10 | /// The representing the status of this create attempt 11 | /// 12 | public readonly PersistentSubscriptionUpdateStatus Status; 13 | 14 | internal PersistentSubscriptionUpdateResult(PersistentSubscriptionUpdateStatus status) 15 | { 16 | Status = status; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/PersistentSubscriptionUpdateStatus.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Internal 2 | { 3 | /// 4 | /// Enumeration representing the status of a single subscription create message. 5 | /// 6 | public enum PersistentSubscriptionUpdateStatus 7 | { 8 | /// 9 | /// The subscription was created successfully 10 | /// 11 | Success = 0, 12 | /// 13 | /// The subscription already exists 14 | /// 15 | NotFound = 1, 16 | /// 17 | /// Some failure happened creating the subscription 18 | /// 19 | Failure = 2, 20 | /// 21 | /// You do not have permissions to update this subscription 22 | /// 23 | AccessDenied = 3, 24 | } 25 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/SimpleQueuedHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using EventStore.ClientAPI.Common.Utils; 5 | using System.Collections.Concurrent; 6 | 7 | namespace EventStore.ClientAPI.Internal 8 | { 9 | internal class SimpleQueuedHandler 10 | { 11 | private readonly ConcurrentQueue _messageQueue = new ConcurrentQueue(); 12 | private readonly Dictionary> _handlers = new Dictionary>(); 13 | private int _isProcessing; 14 | 15 | public void RegisterHandler(Action handler) where T : Message 16 | { 17 | Ensure.NotNull(handler, "handler"); 18 | _handlers.Add(typeof(T), msg => handler((T)msg)); 19 | } 20 | 21 | public void EnqueueMessage(Message message) 22 | { 23 | Ensure.NotNull(message, "message"); 24 | 25 | _messageQueue.Enqueue(message); 26 | if (Interlocked.CompareExchange(ref _isProcessing, 1, 0) == 0) 27 | ThreadPool.QueueUserWorkItem(ProcessQueue); 28 | } 29 | 30 | private void ProcessQueue(object state) 31 | { 32 | do 33 | { 34 | Message message; 35 | 36 | while (_messageQueue.TryDequeue(out message)) 37 | { 38 | Action handler; 39 | if (!_handlers.TryGetValue(message.GetType(), out handler)) 40 | throw new Exception(string.Format("No handler registered for message {0}", message.GetType().Name)); 41 | handler(message); 42 | } 43 | 44 | Interlocked.Exchange(ref _isProcessing, 0); 45 | } while (_messageQueue.Count > 0 && Interlocked.CompareExchange(ref _isProcessing, 1, 0) == 0); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/SingleEndpointDiscoverer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using System.Threading.Tasks; 6 | 7 | namespace EventStore.ClientAPI.Internal 8 | { 9 | internal class SingleEndpointDiscoverer : IEndPointDiscoverer 10 | { 11 | private readonly Uri _uri; 12 | private readonly bool _useSslConnection; 13 | 14 | public SingleEndpointDiscoverer(Uri uri, bool useSslConnection) 15 | { 16 | _uri = uri; 17 | _useSslConnection = useSslConnection; 18 | } 19 | 20 | public async Task DiscoverAsync(IPEndPoint failedTcpEndPoint) 21 | { 22 | var endpoint = await GetSingleNodeIPEndPointFrom(_uri).ConfigureAwait(false); 23 | return new NodeEndPoints(_useSslConnection ? null : endpoint, _useSslConnection ? endpoint : null); 24 | } 25 | 26 | private static async Task GetSingleNodeIPEndPointFrom(Uri uri) 27 | { 28 | var ipaddress = IPAddress.Any; 29 | if (!IPAddress.TryParse(uri.Host, out ipaddress)) 30 | { 31 | var entries = await Dns.GetHostAddressesAsync(uri.Host); 32 | if (entries.Length == 0) throw new Exception(string.Format("Unable to parse IP address or lookup DNS host for '{0}'", uri.Host)); 33 | //pick an IPv4 address, if one exists 34 | ipaddress = entries.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork); 35 | if (ipaddress == null) throw new Exception(string.Format("Could not get an IPv4 address for host '{0}'", uri.Host)); 36 | } 37 | var port = uri.IsDefaultPort ? 2113 : uri.Port; 38 | return new IPEndPoint(ipaddress, port); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/StaticEndPointDiscoverer.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Threading.Tasks; 3 | using EventStore.ClientAPI.Common.Utils; 4 | 5 | namespace EventStore.ClientAPI.Internal 6 | { 7 | internal class StaticEndPointDiscoverer : IEndPointDiscoverer 8 | { 9 | private readonly Task _task; 10 | 11 | public StaticEndPointDiscoverer(IPEndPoint endPoint, bool isSsl) 12 | { 13 | Ensure.NotNull(endPoint, "endPoint"); 14 | _task = Task.FromResult(new NodeEndPoints(isSsl ? null : endPoint, isSsl ? endPoint : null)); 15 | } 16 | 17 | public Task DiscoverAsync(IPEndPoint failedTcpEndPoint) 18 | { 19 | return _task; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Internal/VolatileEventStoreSubscription.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.ClientOperations; 2 | 3 | namespace EventStore.ClientAPI.Internal 4 | { 5 | internal class VolatileEventStoreSubscription : EventStoreSubscription 6 | { 7 | private readonly VolatileSubscriptionOperation _subscriptionOperation; 8 | 9 | internal VolatileEventStoreSubscription(VolatileSubscriptionOperation subscriptionOperation, string streamId, long lastCommitPosition, long? lastEventNumber) 10 | : base(streamId, lastCommitPosition, lastEventNumber) 11 | { 12 | _subscriptionOperation = subscriptionOperation; 13 | } 14 | 15 | public override void Unsubscribe() 16 | { 17 | _subscriptionOperation.Unsubscribe(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Messages/ClientMessagesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace EventStore.ClientAPI.Messages 4 | { 5 | internal static partial class ClientMessage 6 | { 7 | public partial class NotHandled 8 | { 9 | public partial class MasterInfo 10 | { 11 | public IPEndPoint ExternalTcpEndPoint { get { return new IPEndPoint(IPAddress.Parse(ExternalTcpAddress), ExternalTcpPort); } } 12 | 13 | public IPEndPoint ExternalSecureTcpEndPoint 14 | { 15 | get 16 | { 17 | return ExternalSecureTcpAddress == null || ExternalSecureTcpPort == null 18 | ? null 19 | : new IPEndPoint(IPAddress.Parse(ExternalSecureTcpAddress), ExternalSecureTcpPort.Value); 20 | } 21 | } 22 | 23 | public IPEndPoint ExternalHttpEndPoint { get { return new IPEndPoint(IPAddress.Parse(ExternalHttpAddress), ExternalHttpPort); } } 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/NodeEndPoints.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace EventStore.ClientAPI 5 | { 6 | /// 7 | /// Represents a node and its possible endpoints 8 | /// 9 | public struct NodeEndPoints 10 | { 11 | /// 12 | /// The tcp endpoint of the node. 13 | /// 14 | public readonly IPEndPoint TcpEndPoint; 15 | 16 | /// 17 | /// The ssl endpoint of the node. 18 | /// 19 | public readonly IPEndPoint SecureTcpEndPoint; 20 | 21 | /// 22 | /// Called to create a new NodeEndPoints 23 | /// 24 | /// The tcp endpoint of the node 25 | /// he ssl endpoint of the node 26 | public NodeEndPoints(IPEndPoint tcpEndPoint, IPEndPoint secureTcpEndPoint) 27 | { 28 | if ((tcpEndPoint ?? secureTcpEndPoint) == null) throw new ArgumentException("Both endpoints are null."); 29 | TcpEndPoint = tcpEndPoint; 30 | SecureTcpEndPoint = secureTcpEndPoint; 31 | } 32 | 33 | /// 34 | /// Formats the endpoints as a string 35 | /// 36 | public override string ToString() 37 | { 38 | return string.Format("[{0}, {1}]", 39 | TcpEndPoint == null ? "n/a" : TcpEndPoint.ToString(), 40 | SecureTcpEndPoint == null ? "n/a" : SecureTcpEndPoint.ToString()); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/NodePreference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace EventStore.ClientAPI 6 | { 7 | /// 8 | /// Indicates which order of preferred nodes for connecting to. 9 | /// 10 | public enum NodePreference 11 | { 12 | /// 13 | /// When attempting connnection, prefers master node. 14 | /// 15 | Master, 16 | /// 17 | /// When attempting connnection, prefers slave node. 18 | /// 19 | Slave, 20 | /// 21 | /// When attempting connnection, has no node preference. 22 | /// 23 | Random 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/PersistentEventStoreSubscription.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | internal class PersistentEventStoreSubscription : EventStoreSubscription 6 | { 7 | private readonly IConnectToPersistentSubscriptions _subscriptionOperation; 8 | 9 | internal PersistentEventStoreSubscription(IConnectToPersistentSubscriptions subscriptionOperation, string streamId, long lastCommitPosition, long? lastEventNumber) 10 | : base(streamId, lastCommitPosition, lastEventNumber) 11 | { 12 | _subscriptionOperation = subscriptionOperation; 13 | } 14 | 15 | public override void Unsubscribe() 16 | { 17 | _subscriptionOperation.Unsubscribe(); 18 | } 19 | 20 | public void NotifyEventsProcessed(Guid[] processedEvents) 21 | { 22 | _subscriptionOperation.NotifyEventsProcessed(processedEvents); 23 | } 24 | 25 | public void NotifyEventsFailed(Guid[] processedEvents, PersistentSubscriptionNakEventAction action, string reason) 26 | { 27 | _subscriptionOperation.NotifyEventsFailed(processedEvents, action, reason); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/PersistentSubscriptionNakEventAction.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Actions to be taken by server in the case of a client NAK 5 | /// 6 | public enum PersistentSubscriptionNakEventAction 7 | { 8 | /// 9 | /// Client unknown on action. Let server decide 10 | /// 11 | Unknown = 0, 12 | /// 13 | /// Park message do not resend. Put on poison queue 14 | /// 15 | Park = 1, 16 | /// 17 | /// Explicitly retry the message. 18 | /// 19 | Retry = 2, 20 | /// 21 | /// Skip this message do not resend do not put in poison queue 22 | /// 23 | Skip = 3, 24 | /// 25 | /// Stop the subscription. 26 | /// 27 | Stop = 4 28 | } 29 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: ComVisible(false)] 6 | [assembly: Guid("0bffd734-18c5-4575-9321-324ed1a3bbfb")] 7 | [assembly: InternalsVisibleTo("EventStore.Core.Tests.ClientAPI")] -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/RawStreamMetadataResult.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Common.Utils; 2 | using EventStore.ClientAPI.Internal; 3 | 4 | namespace EventStore.ClientAPI 5 | { 6 | /// 7 | /// Represents stream metadata as a series of properties for system 8 | /// data and a byte array for user metadata. 9 | /// 10 | public struct RawStreamMetadataResult 11 | { 12 | /// 13 | /// The name of the stream. 14 | /// 15 | public readonly string Stream; 16 | /// 17 | /// True if the stream is soft-deleted. 18 | /// 19 | public readonly bool IsStreamDeleted; 20 | /// 21 | /// The version of the metadata format. 22 | /// 23 | public readonly long MetastreamVersion; 24 | /// 25 | /// A byte array containing user-specified metadata. 26 | /// 27 | public readonly byte[] StreamMetadata; 28 | 29 | /// 30 | /// Constructs a new instance of . 31 | /// 32 | /// The name of the stream. 33 | /// True if the stream is soft-deleted. 34 | /// The version of the metadata format. 35 | /// A byte array containing user-specified metadata. 36 | public RawStreamMetadataResult(string stream, bool isStreamDeleted, long metastreamVersion, byte[] streamMetadata) 37 | { 38 | Ensure.NotNullOrEmpty(stream, "stream"); 39 | 40 | Stream = stream; 41 | IsStreamDeleted = isStreamDeleted; 42 | MetastreamVersion = metastreamVersion; 43 | StreamMetadata = streamMetadata ?? Empty.ByteArray; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/ReadDirection.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Represents the direction of read operation (both from $all and usual streams) 5 | /// 6 | public enum ReadDirection 7 | { 8 | /// 9 | /// From beginning to end. 10 | /// 11 | Forward, 12 | /// 13 | /// From end to beginning. 14 | /// 15 | Backward 16 | } 17 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/SliceReadStatus.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Enumeration detailing the possible outcomes of reading a 5 | /// slice of a stream. 6 | /// 7 | public enum SliceReadStatus 8 | { 9 | /// 10 | /// The read was successful. 11 | /// 12 | Success, 13 | /// 14 | /// The stream was not found. 15 | /// 16 | StreamNotFound, 17 | /// 18 | /// The stream has previously existed but is deleted. 19 | /// 20 | StreamDeleted 21 | } 22 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/StreamCheckpoint.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// This class contains constants to be used when setting up subscriptions 5 | /// using the IEventStoreConnection.SubscribeToStreamFrom method 6 | /// on . 7 | /// 8 | public static class StreamCheckpoint 9 | { 10 | /// 11 | /// Indicates that a catch-up subscription should receive all events 12 | /// in the stream. 13 | /// 14 | public static int? StreamStart = null; 15 | } 16 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/StreamMetadataResult.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Common.Utils; 2 | 3 | namespace EventStore.ClientAPI 4 | { 5 | /// 6 | /// Represents stream metadata as a series of properties for system 7 | /// data and a object for user metadata. 8 | /// 9 | public struct StreamMetadataResult 10 | { 11 | /// 12 | /// The name of the stream. 13 | /// 14 | public readonly string Stream; 15 | /// 16 | /// True if the stream is soft-deleted. 17 | /// 18 | public readonly bool IsStreamDeleted; 19 | /// 20 | /// The version of the metadata format. 21 | /// 22 | public readonly long MetastreamVersion; 23 | /// 24 | /// A containing user-specified metadata. 25 | /// 26 | public readonly StreamMetadata StreamMetadata; 27 | 28 | /// 29 | /// Constructs a new instance of . 30 | /// 31 | /// The name of the stream. 32 | /// True if the stream is soft-deleted. 33 | /// The version of the metadata format. 34 | /// A containing user-specified metadata. 35 | public StreamMetadataResult(string stream, bool isStreamDeleted, long metastreamVersion, StreamMetadata streamMetadata) 36 | { 37 | Ensure.NotNullOrEmpty(stream, "stream"); 38 | 39 | Stream = stream; 40 | IsStreamDeleted = isStreamDeleted; 41 | MetastreamVersion = metastreamVersion; 42 | StreamMetadata = streamMetadata; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/StreamPosition.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Constants for stream positions 5 | /// 6 | public static class StreamPosition 7 | { 8 | /// 9 | /// The first event in a stream 10 | /// 11 | public const int Start = 0; 12 | 13 | /// 14 | /// The last event in the stream. 15 | /// 16 | public const int End = -1; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/SubscriptionDropReason.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Represents the reason subscription drop happened 5 | /// 6 | public enum SubscriptionDropReason 7 | { 8 | /// 9 | /// Subscription dropped because the client called Close. 10 | /// 11 | UserInitiated, 12 | /// 13 | /// Subscription dropped because the client is not authenticated. 14 | /// 15 | NotAuthenticated, 16 | /// 17 | /// Subscription dropped because access to the stream was denied. 18 | /// 19 | AccessDenied, 20 | /// 21 | /// Subscription dropped because of an error in the subscription phase. 22 | /// 23 | SubscribingError, 24 | /// 25 | /// Subscription dropped because of a server error. 26 | /// 27 | ServerError, 28 | /// 29 | /// Subscription dropped because the connection was closed. 30 | /// 31 | ConnectionClosed, 32 | 33 | /// 34 | /// Subscription dropped because of an error during the catch-up phase. 35 | /// 36 | CatchUpError, 37 | /// 38 | /// Subscription dropped because it's queue overflowed. 39 | /// 40 | ProcessingQueueOverflow, 41 | /// 42 | /// Subscription dropped because an exception was thrown by a handler. 43 | /// 44 | EventHandlerException, 45 | 46 | /// 47 | /// The maximum number of subscribers for the persistent subscription has been reached 48 | /// 49 | MaxSubscribersReached, 50 | 51 | /// 52 | /// The persistent subscription has been deleted 53 | /// 54 | PersistentSubscriptionDeleted, 55 | /// 56 | /// Subscription was dropped for an unknown reason. 57 | /// 58 | Unknown = 100, 59 | 60 | /// 61 | /// Target of persistent subscription was not found. Needs to be created first 62 | /// 63 | NotFound 64 | } 65 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/SystemData/InspectionDecision.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.SystemData 2 | { 3 | internal enum InspectionDecision 4 | { 5 | DoNothing, 6 | EndOperation, 7 | Retry, 8 | Reconnect, 9 | Subscribed 10 | } 11 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/SystemData/InspectionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using EventStore.ClientAPI.Common.Utils; 4 | 5 | namespace EventStore.ClientAPI.SystemData 6 | { 7 | internal class InspectionResult 8 | { 9 | public readonly InspectionDecision Decision; 10 | public readonly string Description; 11 | public readonly IPEndPoint TcpEndPoint; 12 | public readonly IPEndPoint SecureTcpEndPoint; 13 | 14 | public InspectionResult(InspectionDecision decision, string description, IPEndPoint tcpEndPoint = null, IPEndPoint secureTcpEndPoint = null) 15 | { 16 | if (decision == InspectionDecision.Reconnect) 17 | Ensure.NotNull(tcpEndPoint, "tcpEndPoint"); 18 | else 19 | { 20 | if (tcpEndPoint != null) 21 | throw new ArgumentException(string.Format("tcpEndPoint is not null for decision {0}.", decision)); 22 | } 23 | 24 | Decision = decision; 25 | Description = description; 26 | TcpEndPoint = tcpEndPoint; 27 | SecureTcpEndPoint = secureTcpEndPoint; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/SystemData/StatusCode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI.Messages; 3 | 4 | namespace EventStore.ClientAPI.SystemData 5 | { 6 | internal class StatusCode 7 | { 8 | public static SliceReadStatus Convert(ClientMessage.ReadStreamEventsCompleted.ReadStreamResult code) 9 | { 10 | switch (code) 11 | { 12 | case ClientMessage.ReadStreamEventsCompleted.ReadStreamResult.Success: 13 | return SliceReadStatus.Success; 14 | case ClientMessage.ReadStreamEventsCompleted.ReadStreamResult.NoStream: 15 | return SliceReadStatus.StreamNotFound; 16 | case ClientMessage.ReadStreamEventsCompleted.ReadStreamResult.StreamDeleted: 17 | return SliceReadStatus.StreamDeleted; 18 | default: 19 | throw new ArgumentOutOfRangeException("code"); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/SystemData/UserCredentials.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Common.Utils; 2 | 3 | namespace EventStore.ClientAPI.SystemData 4 | { 5 | /// 6 | /// A username/password pair used for authentication and 7 | /// authorization to perform operations over an . 8 | /// 9 | public class UserCredentials 10 | { 11 | /// 12 | /// The username 13 | /// 14 | public readonly string Username; 15 | /// 16 | /// The password 17 | /// 18 | public readonly string Password; 19 | 20 | /// 21 | /// Constructs a new . 22 | /// 23 | /// 24 | /// 25 | public UserCredentials(string username, string password) 26 | { 27 | Ensure.NotNull(username, "username"); 28 | Ensure.NotNull(password, "password"); 29 | 30 | Username = username; 31 | Password = password; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Http/ClientOperationState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using EventStore.ClientAPI.Common.Utils; 4 | 5 | namespace EventStore.ClientAPI.Transport.Http 6 | { 7 | internal class ClientOperationState: IDisposable 8 | { 9 | public readonly HttpRequestMessage Request; 10 | public readonly Action OnSuccess; 11 | public readonly Action OnError; 12 | 13 | public HttpResponse Response { get; set; } 14 | 15 | public ClientOperationState(HttpRequestMessage request, Action onSuccess, Action onError) 16 | { 17 | Ensure.NotNull(request, "request"); 18 | Ensure.NotNull(onSuccess, "onSuccess"); 19 | Ensure.NotNull(onError, "onError"); 20 | 21 | Request = request; 22 | OnSuccess = onSuccess; 23 | OnError = onError; 24 | } 25 | 26 | public void Dispose() 27 | { 28 | Request.Dispose(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Http/ContentType.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Transport.Http 2 | { 3 | internal static class ContentType 4 | { 5 | public const string Any = "*/*"; 6 | 7 | public const string Xml = "text/xml"; 8 | public const string PlainText = "text/plain"; 9 | public const string Html = "text/html"; 10 | 11 | public const string Atom = "application/atom+xml"; 12 | public const string AtomJson = "application/atom+x.json"; 13 | 14 | public const string AtomServiceDoc = "application/atomsvc+xml"; 15 | public const string AtomServiceDocJson = "application/atomsvc+x.json"; 16 | } 17 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Http/EndpointExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace EventStore.ClientAPI.Transport.Http 4 | { 5 | internal static class EndpointExtensions 6 | { 7 | public const string HTTP_SCHEMA = "http"; 8 | public const string HTTPS_SCHEMA = "https"; 9 | public static string ToHttpUrl(this EndPoint endPoint, string schema, string rawUrl) 10 | { 11 | if (endPoint is IPEndPoint) 12 | { 13 | var ipEndPoint = endPoint as IPEndPoint; 14 | return CreateHttpUrl(schema, ipEndPoint.ToString(), rawUrl != null ? rawUrl.TrimStart('/') : string.Empty); 15 | } 16 | if (endPoint is DnsEndPoint) 17 | { 18 | var dnsEndpoint = endPoint as DnsEndPoint; 19 | return CreateHttpUrl(schema, dnsEndpoint.Host, dnsEndpoint.Port, rawUrl != null ? rawUrl.TrimStart('/') : string.Empty); 20 | } 21 | return null; 22 | } 23 | 24 | public static string ToHttpUrl(this EndPoint endPoint, string schema, string formatString, params object[] args) 25 | { 26 | if (endPoint is IPEndPoint) 27 | { 28 | var ipEndPoint = endPoint as IPEndPoint; 29 | return CreateHttpUrl(schema, ipEndPoint.ToString(), string.Format(formatString.TrimStart('/'), args)); 30 | } 31 | if (endPoint is DnsEndPoint) 32 | { 33 | var dnsEndpoint = endPoint as DnsEndPoint; 34 | return CreateHttpUrl(schema, dnsEndpoint.Host, dnsEndpoint.Port, string.Format(formatString.TrimStart('/'), args)); 35 | } 36 | return null; 37 | } 38 | 39 | private static string CreateHttpUrl(string schema, string host, int port, string path) 40 | { 41 | return $"{schema}://{host}:{port}/{path}"; 42 | } 43 | 44 | private static string CreateHttpUrl(string schema, string address, string path) 45 | { 46 | return $"{schema}://{address}/{path}"; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Http/HttpMethod.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Transport.Http 2 | { 3 | internal static class HttpMethod 4 | { 5 | public const string Get = "GET"; 6 | public const string Post = "POST"; 7 | public const string Put = "PUT"; 8 | public const string Delete = "DELETE"; 9 | public const string Options = "OPTIONS"; 10 | public const string Head = "HEAD"; 11 | public const string Patch = "PATCH"; 12 | } 13 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Http/HttpResponse.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Net.Http; 3 | using System.Net.Http.Headers; 4 | 5 | namespace EventStore.ClientAPI.Transport.Http 6 | { 7 | internal class HttpResponse 8 | { 9 | public readonly string CharacterSet; 10 | 11 | public readonly string ContentEncoding; 12 | public readonly long ContentLength; 13 | public readonly string ContentType; 14 | 15 | //public readonly CookieCollection Cookies; 16 | public readonly HttpResponseHeaders Headers; 17 | 18 | //public readonly bool IsFromCache; 19 | //public readonly bool IsMutuallyAuthenticated;//TODO TR: not implemented in mono 20 | //public readonly DateTime LastModified; 21 | 22 | public readonly string Method; 23 | //public readonly Version ProtocolVersion; 24 | 25 | //public readonly Uri ResponseUri; 26 | //public readonly string Server; 27 | 28 | public readonly int HttpStatusCode; 29 | public readonly string StatusDescription; 30 | 31 | public string Body { get; internal set; } 32 | 33 | public HttpResponse(HttpResponseMessage responseMessage) 34 | { 35 | ContentEncoding = responseMessage.Content.Headers.ContentEncoding.FirstOrDefault(); 36 | ContentLength = responseMessage.Content.Headers.ContentLength.Value; 37 | 38 | if(responseMessage.Content.Headers.ContentType != null) 39 | { 40 | CharacterSet = responseMessage.Content.Headers.ContentType.CharSet; 41 | ContentType = responseMessage.Content.Headers.ContentType.MediaType; 42 | } 43 | 44 | 45 | //Cookies = httpWebResponse.Cookies; 46 | Headers = responseMessage.Headers; 47 | 48 | //IsFromCache = httpWebResponse.IsFromCache; 49 | //IsMutuallyAuthenticated = httpWebResponse.IsMutuallyAuthenticated; 50 | 51 | //LastModified = httpWebResponse.LastModified; 52 | 53 | Method = responseMessage.RequestMessage.Method.ToString(); 54 | //ProtocolVersion = httpWebResponse.ProtocolVersion; 55 | 56 | //ResponseUri = httpWebResponse.ResponseUri; 57 | //Server = httpWebResponse.Server; 58 | 59 | HttpStatusCode = (int)responseMessage.StatusCode; 60 | StatusDescription = responseMessage.ReasonPhrase; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Tcp/IMonitoredTcpConnection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI.Transport.Tcp 4 | { 5 | internal interface IMonitoredTcpConnection 6 | { 7 | bool IsReadyForSend { get; } 8 | bool IsReadyForReceive { get; } 9 | bool IsInitialized { get; } 10 | bool IsFaulted { get; } 11 | bool IsClosed { get; } 12 | 13 | bool InSend { get; } 14 | bool InReceive { get; } 15 | 16 | DateTime? LastSendStarted { get; } 17 | DateTime? LastReceiveStarted { get; } 18 | 19 | int PendingSendBytes { get; } 20 | int InSendBytes { get; } 21 | int PendingReceivedBytes { get; } 22 | 23 | long TotalBytesSent { get; } 24 | long TotalBytesReceived { get; } 25 | } 26 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Tcp/ITcpConnection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | 5 | namespace EventStore.ClientAPI.Transport.Tcp 6 | { 7 | internal interface ITcpConnection 8 | { 9 | Guid ConnectionId { get; } 10 | IPEndPoint RemoteEndPoint { get; } 11 | IPEndPoint LocalEndPoint { get; } 12 | int SendQueueSize { get; } 13 | bool IsClosed { get; } 14 | 15 | void ReceiveAsync(Action>> callback); 16 | void EnqueueSend(IEnumerable> data); 17 | void Close(string reason); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Tcp/PackageFramingException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace EventStore.ClientAPI.Transport.Tcp 5 | { 6 | internal class PackageFramingException : Exception 7 | { 8 | public PackageFramingException() 9 | { 10 | } 11 | 12 | public PackageFramingException(string message) 13 | : base(message) 14 | { 15 | } 16 | 17 | public PackageFramingException(string message, Exception innerException) 18 | : base(message, innerException) 19 | { 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Tcp/ProtobufExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using EventStore.ClientAPI.Common.Log; 4 | using ProtoBuf; 5 | 6 | namespace EventStore.ClientAPI.Transport.Tcp 7 | { 8 | internal static class ProtobufExtensions 9 | { 10 | private static readonly ILogger Log = new ConsoleLogger(); 11 | 12 | public static T Deserialize(this byte[] data) 13 | { 14 | return Deserialize(new ArraySegment(data)); 15 | } 16 | 17 | public static T Deserialize(this ArraySegment data) 18 | { 19 | try 20 | { 21 | using (var memory = new MemoryStream(data.Array, data.Offset, data.Count)) 22 | { 23 | var res = Serializer.Deserialize(memory); 24 | return res; 25 | } 26 | } 27 | catch (Exception e) 28 | { 29 | Log.Debug("Deserialization to {0} failed : {1}", typeof(T).FullName, e); 30 | return default(T); 31 | } 32 | } 33 | 34 | public static ArraySegment Serialize(this T protoContract) 35 | { 36 | using (var memory = new MemoryStream()) 37 | { 38 | Serializer.Serialize(memory, protoContract); 39 | ArraySegment res ; 40 | memory.TryGetBuffer(out res); 41 | return res; 42 | } 43 | } 44 | 45 | public static byte[] SerializeToArray(this T protoContract) 46 | { 47 | using (var memory = new MemoryStream()) 48 | { 49 | Serializer.Serialize(memory, protoContract); 50 | return memory.ToArray(); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Tcp/SocketArgsPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Net.Sockets; 4 | 5 | namespace EventStore.ClientAPI.Transport.Tcp 6 | { 7 | internal class SocketArgsPool 8 | { 9 | public readonly string Name; 10 | private readonly Func _socketArgsCreator; 11 | 12 | private readonly ConcurrentStack _socketArgsPool = new ConcurrentStack(); 13 | 14 | public SocketArgsPool(string name, int initialCount, Func socketArgsCreator) 15 | { 16 | if (socketArgsCreator == null) 17 | throw new ArgumentNullException("socketArgsCreator"); 18 | if (initialCount < 0) 19 | throw new ArgumentOutOfRangeException("initialCount"); 20 | 21 | Name = name; 22 | _socketArgsCreator = socketArgsCreator; 23 | 24 | for (int i = 0; i < initialCount; ++i) 25 | { 26 | _socketArgsPool.Push(socketArgsCreator()); 27 | } 28 | } 29 | 30 | public SocketAsyncEventArgs Get() 31 | { 32 | SocketAsyncEventArgs result; 33 | if (_socketArgsPool.TryPop(out result)) 34 | return result; 35 | return _socketArgsCreator(); 36 | } 37 | 38 | public void Return(SocketAsyncEventArgs socketArgs) 39 | { 40 | _socketArgsPool.Push(socketArgs); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Tcp/TcpConfiguratin.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI.Transport.Tcp 2 | { 3 | internal static class TcpConfiguration 4 | { 5 | public const int SocketCloseTimeoutMs = 500; 6 | 7 | public const int AcceptBacklogCount = 1000; 8 | public const int ConcurrentAccepts = 1; 9 | public const int AcceptPoolSize = ConcurrentAccepts * 2; 10 | 11 | public const int ConnectPoolSize = 32; 12 | public const int SendReceivePoolSize = 512; 13 | 14 | public const int BufferChunksCount = 512; 15 | public const int SocketBufferSize = 8 * 1024; 16 | } 17 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/Transport.Tcp/TcpStats.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventStore.ClientAPI.Transport.Tcp 4 | { 5 | internal class TcpStats 6 | { 7 | public readonly int Connections; 8 | public readonly long SentBytesTotal; 9 | public readonly long ReceivedBytesTotal; 10 | public readonly long SentBytesSinceLastRun; 11 | public readonly long ReceivedBytesSinceLastRun; 12 | public readonly double SendingSpeed; 13 | public readonly double ReceivingSpeed; 14 | public readonly long PendingSend; 15 | public readonly long InSend; 16 | public readonly long PendingReceived; 17 | public readonly TimeSpan MeasureTime; 18 | 19 | public TcpStats(int connections, 20 | long sentBytesTotal, 21 | long receivedBytesTotal, 22 | long sentBytesSinceLastRunSinceLastRun, 23 | long receivedBytesSinceLastRun, 24 | long pendingSend, 25 | long inSend, 26 | long pendingReceived, 27 | TimeSpan measureTime) 28 | { 29 | Connections = connections; 30 | SentBytesTotal = sentBytesTotal; 31 | ReceivedBytesTotal = receivedBytesTotal; 32 | SentBytesSinceLastRun = sentBytesSinceLastRunSinceLastRun; 33 | ReceivedBytesSinceLastRun = receivedBytesSinceLastRun; 34 | PendingSend = pendingSend; 35 | InSend = inSend; 36 | PendingReceived = pendingReceived; 37 | MeasureTime = measureTime; 38 | SendingSpeed = MeasureTime.TotalSeconds < 0.00001 ? 0 : SentBytesSinceLastRun / MeasureTime.TotalSeconds; 39 | ReceivingSpeed = MeasureTime.TotalSeconds < 0.00001 ? 0 : ReceivedBytesSinceLastRun / MeasureTime.TotalSeconds; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/UserManagement/ChangePasswordDetails.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Common.Utils; 2 | 3 | namespace EventStore.ClientAPI.UserManagement 4 | { 5 | internal class ChangePasswordDetails 6 | { 7 | public readonly string CurrentPassword; 8 | 9 | public readonly string NewPassword; 10 | 11 | public ChangePasswordDetails(string currentPassword, string newPassword) 12 | { 13 | Ensure.NotNullOrEmpty(currentPassword, "currentPassword"); 14 | Ensure.NotNullOrEmpty(newPassword, "newPassword"); 15 | CurrentPassword = currentPassword; 16 | NewPassword = newPassword; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/UserManagement/RelLink.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace EventStore.ClientAPI.UserManagement 3 | { 4 | /// 5 | /// 6 | /// 7 | public class RelLink 8 | { 9 | /// 10 | /// 11 | /// 12 | public readonly string Href; 13 | 14 | /// 15 | /// 16 | /// 17 | public readonly string Rel; 18 | 19 | /// 20 | /// 21 | /// 22 | /// 23 | /// 24 | public RelLink(string href, string rel) 25 | { 26 | Href = href; 27 | Rel = rel; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/UserManagement/ResetPasswordDetails.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Common.Utils; 2 | 3 | namespace EventStore.ClientAPI.UserManagement 4 | { 5 | internal class ResetPasswordDetails 6 | { 7 | public readonly string NewPassword; 8 | 9 | public ResetPasswordDetails(string newPassword) 10 | { 11 | Ensure.NotNullOrEmpty(newPassword, "newPassword"); 12 | NewPassword= newPassword; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/UserManagement/UserCreationInformation.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Common.Utils; 2 | 3 | namespace EventStore.ClientAPI.UserManagement 4 | { 5 | /// 6 | /// Class holding the information needed to create a user. 7 | /// 8 | internal sealed class UserCreationInformation 9 | { 10 | /// 11 | /// The new users login name. 12 | /// 13 | public readonly string LoginName; 14 | 15 | /// 16 | /// The full name of the new user. 17 | /// 18 | public readonly string FullName; 19 | 20 | /// 21 | /// The groups the new user should become a member of. 22 | /// 23 | public readonly string[] Groups; 24 | 25 | /// 26 | /// The password of the new user. 27 | /// 28 | public readonly string Password; 29 | 30 | /// 31 | /// Enstantiates a new class. 32 | /// 33 | /// 34 | /// 35 | /// 36 | /// 37 | public UserCreationInformation(string login, string fullName, string[] groups, string password) 38 | { 39 | Ensure.NotNullOrEmpty(login, "login"); 40 | Ensure.NotNullOrEmpty(fullName, "fullName"); 41 | Ensure.NotNull(groups, "groups"); 42 | Ensure.NotNullOrEmpty(password, "password"); 43 | LoginName = login; 44 | FullName = fullName; 45 | Groups = groups; 46 | Password = password; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/UserManagement/UserUpdateInformation.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Common.Utils; 2 | 3 | namespace EventStore.ClientAPI.UserManagement 4 | { 5 | internal class UserUpdateInformation 6 | { 7 | public readonly string FullName; 8 | 9 | public readonly string[] Groups; 10 | 11 | public UserUpdateInformation(string fullName, string[] groups) 12 | { 13 | Ensure.NotNullOrEmpty(fullName, "fullName"); 14 | Ensure.NotNull(groups, "fullName"); 15 | FullName = fullName; 16 | Groups = groups; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/EventStore.ClientAPI.NetCore/WriteResult.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.ClientAPI 2 | { 3 | /// 4 | /// Result type returned after writing to a stream. 5 | /// 6 | public struct WriteResult 7 | { 8 | /// 9 | /// The next expected version for the stream. 10 | /// 11 | public readonly long NextExpectedVersion; 12 | 13 | /// 14 | /// The of the write. 15 | /// 16 | public readonly Position LogPosition; 17 | 18 | /// 19 | /// Constructs a new . 20 | /// 21 | /// The next expected version for the stream. 22 | /// The position of the write in the log 23 | public WriteResult(long nextExpectedVersion, Position logPosition) 24 | { 25 | LogPosition = logPosition; 26 | NextExpectedVersion = nextExpectedVersion; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/DefaultData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Threading.Tasks; 6 | using EventStore.ClientAPI.SystemData; 7 | 8 | namespace EventStore.Core.Tests.ClientAPI 9 | { 10 | public class DefaultData 11 | { 12 | public static string AdminUsername = SystemUsers.Admin; 13 | public static string AdminPassword = SystemUsers.DefaultAdminPassword; 14 | public static UserCredentials AdminCredentials = new UserCredentials(AdminUsername, AdminPassword); 15 | public static NetworkCredential AdminNetworkCredentials = new NetworkCredential(AdminUsername, AdminPassword); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/EventNumber.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.Core.Tests.ClientAPI 2 | { 3 | public static class EventNumber 4 | { 5 | public const long DeletedStream = long.MaxValue; 6 | public const long Invalid = long.MinValue; 7 | } 8 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/EventStore.ClientAPI.NetCore.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Library 5 | 6 | 7 | 8 | netcoreapp2.0 9 | EventStore.Core.Tests.ClientAPI 10 | EventStore.ClientAPI.NetCore.Tests 11 | true 12 | 13 | library 14 | 15 | EventStore.Core.Tests.ClientAPI 16 | False 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Helpers/EventDataComparer.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | using EventStore.ClientAPI.Common.Utils; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI.Helpers 5 | { 6 | internal static class EventDataComparer 7 | { 8 | public static bool Equal(EventData expected, RecordedEvent actual) 9 | { 10 | if (expected.EventId != actual.EventId) 11 | return false; 12 | 13 | if (expected.Type != actual.EventType) 14 | return false; 15 | 16 | var expectedDataString = Helper.UTF8NoBom.GetString(expected.Data ?? new byte[0]); 17 | var expectedMetadataString = Helper.UTF8NoBom.GetString(expected.Metadata ?? new byte[0]); 18 | 19 | var actualDataString = Helper.UTF8NoBom.GetString(actual.Data ?? new byte[0]); 20 | var actualMetadataDataString = Helper.UTF8NoBom.GetString(actual.Metadata ?? new byte[0]); 21 | 22 | return expectedDataString == actualDataString && expectedMetadataString == actualMetadataDataString; 23 | } 24 | 25 | public static bool Equal(EventData[] expected, RecordedEvent[] actual) 26 | { 27 | if (expected.Length != actual.Length) 28 | return false; 29 | 30 | for (var i = 0; i < expected.Length; i++) 31 | { 32 | if (!Equal(expected[i], actual[i])) 33 | return false; 34 | } 35 | 36 | return true; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Helpers/EventsStream.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | 3 | namespace EventStore.Core.Tests.ClientAPI.Helpers 4 | { 5 | internal class EventsStream 6 | { 7 | private const int SliceSize = 10; 8 | 9 | public static int Count(IEventStoreConnection store, string stream) 10 | { 11 | var result = 0; 12 | while (true) 13 | { 14 | var slice = store.ReadStreamEventsForwardAsync(stream, result, SliceSize, false).Result; 15 | result += slice.Events.Length; 16 | if (slice.IsEndOfStream) 17 | break; 18 | } 19 | return result; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Helpers/OngoingTransaction.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | 3 | namespace EventStore.Core.Tests.ClientAPI.Helpers 4 | { 5 | internal class OngoingTransaction 6 | { 7 | private readonly EventStoreTransaction _transaction; 8 | 9 | public OngoingTransaction(EventStoreTransaction transaction) 10 | { 11 | _transaction = transaction; 12 | } 13 | 14 | public OngoingTransaction Write(params EventData[] events) 15 | { 16 | _transaction.WriteAsync(events).Wait(); 17 | return this; 18 | } 19 | 20 | public WriteResult Commit() 21 | { 22 | return _transaction.CommitAsync().Result; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Helpers/StreamWriter.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI.Helpers 5 | { 6 | internal class StreamWriter 7 | { 8 | private readonly IEventStoreConnection _store; 9 | private readonly string _stream; 10 | private readonly long _version; 11 | 12 | public StreamWriter(IEventStoreConnection store, string stream, long version) 13 | { 14 | _store = store; 15 | _stream = stream; 16 | _version = version; 17 | } 18 | 19 | public TailWriter Append(params EventData[] events) 20 | { 21 | for (var i = 0; i < events.Length; i++) 22 | { 23 | var expVer = _version == ExpectedVersion.Any ? ExpectedVersion.Any : _version + i; 24 | var nextExpVer = _store.AppendToStreamAsync(_stream, expVer, new[] { events[i] }).Result.NextExpectedVersion; 25 | if (_version != ExpectedVersion.Any) 26 | Assert.AreEqual(expVer + 1, nextExpVer); 27 | } 28 | return new TailWriter(_store, _stream); 29 | } 30 | } 31 | 32 | //TODO GFY this should be removed and merged with the public idea of a transaction. 33 | } 34 | -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Helpers/SystemStreams.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.Core.Tests.ClientAPI.Helpers 2 | { 3 | public static class SystemStreams 4 | { 5 | public static bool IsSystemStream(string streamId) 6 | { 7 | return streamId.Length != 0 && streamId[0] == '$'; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Helpers/TailWriter.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | 3 | namespace EventStore.Core.Tests.ClientAPI.Helpers 4 | { 5 | internal class TailWriter 6 | { 7 | private readonly IEventStoreConnection _store; 8 | private readonly string _stream; 9 | 10 | public TailWriter(IEventStoreConnection store, string stream) 11 | { 12 | _store = store; 13 | _stream = stream; 14 | } 15 | 16 | public TailWriter Then(EventData @event, long expectedVersion) 17 | { 18 | _store.AppendToStreamAsync(_stream, expectedVersion, new[] {@event}).Wait(); 19 | return this; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Helpers/TcpType.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.Core.Tests.ClientAPI.Helpers 2 | { 3 | public enum TcpType 4 | { 5 | Normal, 6 | Ssl 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Helpers/TestEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using EventStore.ClientAPI.Common.Utils; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI.Helpers 6 | { 7 | public class TestEvent 8 | { 9 | public static EventData NewTestEvent(string data = null, string metadata = null) 10 | { 11 | return NewTestEvent(Guid.NewGuid(), data, metadata); 12 | } 13 | 14 | public static EventData NewTestEvent(Guid eventId, string data = null, string metadata = null) 15 | { 16 | var encodedData = Helper.UTF8NoBom.GetBytes(data ?? eventId.ToString()); 17 | var encodedMetadata = Helper.UTF8NoBom.GetBytes(metadata ?? "metadata"); 18 | 19 | return new EventData(eventId, "TestEvent", false, encodedData, encodedMetadata); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Helpers/TransactionalWriter.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | 3 | namespace EventStore.Core.Tests.ClientAPI.Helpers 4 | { 5 | internal class TransactionalWriter 6 | { 7 | private readonly IEventStoreConnection _store; 8 | private readonly string _stream; 9 | 10 | public TransactionalWriter(IEventStoreConnection store, string stream) 11 | { 12 | _store = store; 13 | _stream = stream; 14 | } 15 | 16 | public OngoingTransaction StartTransaction(long expectedVersion) 17 | { 18 | return new OngoingTransaction(_store.StartTransactionAsync(_stream, expectedVersion).Result); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Security/multiple_role_security.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | using EventStore.ClientAPI.Exceptions; 3 | using EventStore.ClientAPI.SystemData; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI.Security 7 | { 8 | [TestFixture, Category("LongRunning"), Category("Network")] 9 | public class multiple_role_security : AuthenticationTestBase 10 | { 11 | [OneTimeSetUp] 12 | public override void OneTimeSetUp() 13 | { 14 | base.OneTimeSetUp(); 15 | 16 | var settings = new SystemSettings( 17 | new StreamAcl(new[]{"user1", "user2"}, new[]{"$admins", "user1"}, new[] {"user1", SystemRoles.All}, null, null), 18 | null); 19 | Connection.SetSystemSettingsAsync(settings, new UserCredentials("adm", "admpa$$")).Wait(); 20 | } 21 | 22 | [Test, Category("LongRunning"), Category("Network")] 23 | public void multiple_roles_are_handled_correctly() 24 | { 25 | Expect(() => ReadEvent("usr-stream", null, null)); 26 | ExpectNoException(() => ReadEvent("usr-stream", "user1", "pa$$1")); 27 | ExpectNoException(() => ReadEvent("usr-stream", "user2", "pa$$2")); 28 | ExpectNoException(() => ReadEvent("usr-stream", "adm", "admpa$$")); 29 | 30 | Expect(() => WriteStream("usr-stream", null, null)); 31 | ExpectNoException(() => WriteStream("usr-stream", "user1", "pa$$1")); 32 | Expect(() => WriteStream("usr-stream", "user2", "pa$$2")); 33 | ExpectNoException(() => WriteStream("usr-stream", "adm", "admpa$$")); 34 | 35 | ExpectNoException(() => DeleteStream("usr-stream1", null, null)); 36 | ExpectNoException(() => DeleteStream("usr-stream2", "user1", "pa$$1")); 37 | ExpectNoException(() => DeleteStream("usr-stream3", "user2", "pa$$2")); 38 | ExpectNoException(() => DeleteStream("usr-stream4", "adm", "admpa$$")); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Security/read_all_security.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Exceptions; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI.Security 5 | { 6 | [TestFixture, Category("LongRunning"), Category("Network")] 7 | public class read_all_security : AuthenticationTestBase 8 | { 9 | [Test, Category("LongRunning"), Category("Network")] 10 | public void reading_all_with_not_existing_credentials_is_not_authenticated() 11 | { 12 | Expect(() => ReadAllForward("badlogin", "badpass")); 13 | Expect(() => ReadAllBackward("badlogin", "badpass")); 14 | } 15 | 16 | [Test, Category("LongRunning"), Category("Network")] 17 | public void reading_all_with_no_credentials_is_denied() 18 | { 19 | Expect(() => ReadAllForward(null, null)); 20 | Expect(() => ReadAllBackward(null, null)); 21 | } 22 | 23 | [Test, Category("LongRunning"), Category("Network")] 24 | public void reading_all_with_not_authorized_user_credentials_is_denied() 25 | { 26 | Expect(() => ReadAllForward("user2", "pa$$2")); 27 | Expect(() => ReadAllBackward("user2", "pa$$2")); 28 | } 29 | 30 | [Test, Category("LongRunning"), Category("Network")] 31 | public void reading_all_with_authorized_user_credentials_succeeds() 32 | { 33 | ExpectNoException(() => ReadAllForward("user1", "pa$$1")); 34 | ExpectNoException(() => ReadAllBackward("user1", "pa$$1")); 35 | } 36 | 37 | [Test, Category("LongRunning"), Category("Network")] 38 | public void reading_all_with_admin_credentials_succeeds() 39 | { 40 | ExpectNoException(() => ReadAllForward("adm", "admpa$$")); 41 | ExpectNoException(() => ReadAllBackward("adm", "admpa$$")); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/Security/subscribe_to_all_security.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.Exceptions; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI.Security 5 | { 6 | [TestFixture, Category("LongRunning"), Category("Network")] 7 | public class subscribe_to_all_security : AuthenticationTestBase 8 | { 9 | [Test, Category("LongRunning"), Category("Network")] 10 | public void subscribing_to_all_with_not_existing_credentials_is_not_authenticated() 11 | { 12 | Expect(() => SubscribeToAll("badlogin", "badpass")); 13 | } 14 | 15 | [Test, Category("LongRunning"), Category("Network")] 16 | public void subscribing_to_all_with_no_credentials_is_denied() 17 | { 18 | Expect(() => SubscribeToAll(null, null)); 19 | } 20 | 21 | [Test, Category("LongRunning"), Category("Network")] 22 | public void subscribing_to_all_with_not_authorized_user_credentials_is_denied() 23 | { 24 | Expect(() => SubscribeToAll("user2", "pa$$2")); 25 | } 26 | 27 | [Test, Category("LongRunning"), Category("Network")] 28 | public void subscribing_to_all_with_authorized_user_credentials_succeeds() 29 | { 30 | ExpectNoException(() => SubscribeToAll("user1", "pa$$1")); 31 | } 32 | 33 | [Test, Category("LongRunning"), Category("Network")] 34 | public void subscribing_to_all_with_admin_user_credentials_succeeds() 35 | { 36 | ExpectNoException(() => SubscribeToAll("adm", "admpa$$")); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/SpecificationWithConnection.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using EventStore.ClientAPI; 3 | using EventStore.Core.Tests.ClientAPI.Helpers; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | public abstract class SpecificationWithConnection 9 | { 10 | protected IEventStoreConnection _conn; 11 | 12 | protected virtual void Given() 13 | { 14 | } 15 | 16 | protected abstract void When(); 17 | 18 | protected IEventStoreConnection BuildConnection() 19 | { 20 | return TestConnection.Create(TcpType.Normal); 21 | } 22 | 23 | [OneTimeSetUp] 24 | public void OneTimeSetUp() 25 | { 26 | _conn = BuildConnection(); 27 | _conn.ConnectAsync().Wait(); 28 | Given(); 29 | When(); 30 | } 31 | 32 | [OneTimeTearDown] 33 | public virtual void OneTimeTearDown() 34 | { 35 | _conn.Close(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/SpecificationWithLinkToToDeletedEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using EventStore.ClientAPI; 4 | using EventStore.ClientAPI.Common; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | public abstract class SpecificationWithLinkToToDeletedEvents : SpecificationWithConnection 9 | { 10 | protected string LinkedStreamName; 11 | protected string DeletedStreamName; 12 | protected override void Given() 13 | { 14 | var creds = DefaultData.AdminCredentials; 15 | LinkedStreamName = Guid.NewGuid().ToString(); 16 | DeletedStreamName = Guid.NewGuid().ToString(); 17 | _conn.AppendToStreamAsync(DeletedStreamName, ExpectedVersion.Any, creds, 18 | new EventData(Guid.NewGuid(), "testing", true, Encoding.UTF8.GetBytes("{'foo' : 4}"), new byte[0])).Wait(); 19 | _conn.AppendToStreamAsync(LinkedStreamName, ExpectedVersion.Any, creds, 20 | new EventData(Guid.NewGuid(), SystemEventTypes.LinkTo, false, Encoding.UTF8.GetBytes("0@" + DeletedStreamName), new byte[0])).Wait(); 21 | _conn.DeleteStreamAsync(DeletedStreamName, ExpectedVersion.Any).Wait(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/SpecificationWithLinkToToMaxCountDeletedEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using EventStore.ClientAPI; 4 | using EventStore.ClientAPI.Common; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | public abstract class SpecificationWithLinkToToMaxCountDeletedEvents : SpecificationWithConnection 9 | { 10 | protected string LinkedStreamName; 11 | protected string DeletedStreamName; 12 | protected override void Given() 13 | { 14 | var creds = DefaultData.AdminCredentials; 15 | DeletedStreamName = Guid.NewGuid().ToString(); 16 | LinkedStreamName = Guid.NewGuid().ToString(); 17 | _conn.AppendToStreamAsync(DeletedStreamName, ExpectedVersion.Any, creds, 18 | new EventData(Guid.NewGuid(), "testing1", true, Encoding.UTF8.GetBytes("{'foo' : 4}"), new byte[0])).Wait(); 19 | _conn.SetStreamMetadataAsync(DeletedStreamName, ExpectedVersion.Any, 20 | new StreamMetadata(2, null, null, null, null)).Wait(); 21 | _conn.AppendToStreamAsync(DeletedStreamName, ExpectedVersion.Any, creds, 22 | new EventData(Guid.NewGuid(), "testing2", true, Encoding.UTF8.GetBytes("{'foo' : 4}"), new byte[0])).Wait(); 23 | _conn.AppendToStreamAsync(DeletedStreamName, ExpectedVersion.Any, creds, 24 | new EventData(Guid.NewGuid(), "testing3", true, Encoding.UTF8.GetBytes("{'foo' : 4}"), new byte[0])).Wait(); 25 | _conn.AppendToStreamAsync(LinkedStreamName, ExpectedVersion.Any, creds, 26 | new EventData(Guid.NewGuid(), SystemEventTypes.LinkTo, false, Encoding.UTF8.GetBytes("0@" + DeletedStreamName), new byte[0])).Wait(); 27 | 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/SystemRoles.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.Core.Tests.ClientAPI 2 | { 3 | public static class SystemRoles 4 | { 5 | public const string Admins = "$admins"; 6 | public const string Operations = "$ops"; 7 | public const string All = "$all"; 8 | } 9 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/SystemUsers.cs: -------------------------------------------------------------------------------- 1 | namespace EventStore.Core.Tests.ClientAPI 2 | { 3 | public static class SystemUsers 4 | { 5 | public const string Admin = "admin"; 6 | public const string Operations = "ops"; 7 | public const string DefaultAdminPassword = "changeit"; 8 | } 9 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/UserManagement/TestWithNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using EventStore.ClientAPI.Common.Log; 4 | using EventStore.ClientAPI.UserManagement; 5 | using EventStore.Core.Tests.ClientAPI.Helpers; 6 | using NUnit.Framework; 7 | 8 | namespace EventStore.Core.Tests.ClientAPI.UserManagement 9 | { 10 | [Category("LongRunning")] 11 | public class TestWithNode 12 | { 13 | protected UsersManager _manager; 14 | 15 | [OneTimeSetUp] 16 | public virtual void OneTimeSetUp() 17 | { 18 | _manager = new UsersManager(new NoopLogger(), TestNode.HttpEndPoint, TimeSpan.FromSeconds(5)); 19 | } 20 | 21 | protected virtual IEventStoreConnection BuildConnection() 22 | { 23 | return TestConnection.Create(TcpType.Normal); 24 | } 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/UserManagement/TestWithUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI.SystemData; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI.UserManagement 5 | { 6 | public class TestWithUser : TestWithNode 7 | { 8 | protected string _username = Guid.NewGuid().ToString(); 9 | public override void OneTimeSetUp() 10 | { 11 | base.OneTimeSetUp(); 12 | _manager.CreateUserAsync(_username, "name", new[] {"foo", "admins"}, "password", new UserCredentials("admin", "changeit")).Wait(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/UserManagement/enable_disable_user.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI.SystemData; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI.UserManagement 6 | { 7 | public class enable_disable_user : TestWithUser 8 | { 9 | [Test] 10 | public void disable_empty_username_throws() 11 | { 12 | Assert.Throws(() => _manager.DisableAsync("", new UserCredentials("admin", "changeit")).Wait()); 13 | } 14 | 15 | [Test] 16 | public void disable_null_username_throws() 17 | { 18 | Assert.Throws(() => _manager.DisableAsync(null, new UserCredentials("admin", "changeit")).Wait()); 19 | } 20 | 21 | [Test] 22 | public void enable_empty_username_throws() 23 | { 24 | Assert.Throws(() => _manager.EnableAsync("", new UserCredentials("admin", "changeit")).Wait()); 25 | } 26 | 27 | [Test] 28 | public void enable_null_username_throws() 29 | { 30 | Assert.Throws(() => _manager.EnableAsync(null, new UserCredentials("admin", "changeit")).Wait()); 31 | } 32 | 33 | [Test] 34 | public void can_enable_disable_user() 35 | { 36 | _manager.DisableAsync(_username, new UserCredentials("admin", "changeit")).Wait(); 37 | 38 | Assert.Throws(() => _manager.DisableAsync("foo", new UserCredentials(_username, "password")).Wait()); 39 | 40 | _manager.EnableAsync(_username, new UserCredentials("admin", "changeit")).Wait(); 41 | 42 | var c = _manager.GetCurrentUserAsync(new UserCredentials(_username, "password")).Result; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/UserManagement/get_current_user.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.SystemData; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI.UserManagement 5 | { 6 | public class get_current_user : TestWithNode 7 | { 8 | [Test] 9 | public void returns_the_current_user() 10 | { 11 | var x = _manager.GetCurrentUserAsync(new UserCredentials("admin", "changeit")).Result; 12 | Assert.AreEqual("admin", x.LoginName); 13 | Assert.AreEqual("Event Store Administrator", x.FullName); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/UserManagement/list_users.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI.SystemData; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI.UserManagement 5 | { 6 | public class list_users: TestWithNode 7 | { 8 | [Test, Ignore("Users are set up and deleted before this test runs so db is in unknown state")] 9 | public void list_all_users_works() 10 | { 11 | _manager.CreateUserAsync("ouro", "ourofull", new[] { "foo", "bar" }, "ouro", new UserCredentials("admin", "changeit")).Wait(); 12 | var x = _manager.ListAllAsync(new UserCredentials("admin", "changeit")).Result; 13 | Assert.AreEqual(3, x.Count); 14 | Assert.AreEqual("admin", x[0].LoginName); 15 | Assert.AreEqual("Event Store Administrator", x[0].FullName); 16 | Assert.AreEqual("ops", x[1].LoginName); 17 | Assert.AreEqual("Event Store Operations", x[1].FullName); 18 | Assert.AreEqual("ouro", x[2].LoginName); 19 | Assert.AreEqual("ourofull", x[2].FullName); 20 | 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/UserManagement/reset_password.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI.Exceptions; 3 | using EventStore.ClientAPI.SystemData; 4 | using EventStore.ClientAPI.Transport.Http; 5 | using NUnit.Framework; 6 | 7 | namespace EventStore.Core.Tests.ClientAPI.UserManagement 8 | { 9 | public class reset_password : TestWithUser 10 | { 11 | [Test] 12 | public void null_user_name_throws() 13 | { 14 | Assert.Throws(() =>_manager.ResetPasswordAsync(null, "foo", new UserCredentials("admin", "changeit")).Wait()); 15 | } 16 | 17 | [Test] 18 | public void empty_user_name_throws() 19 | { 20 | Assert.Throws(() =>_manager.ResetPasswordAsync("", "foo", new UserCredentials("admin", "changeit")).Wait()); 21 | } 22 | 23 | [Test] 24 | public void empty_password_throws() 25 | { 26 | Assert.Throws(() =>_manager.ResetPasswordAsync(_username, "", new UserCredentials("admin", "changeit")).Wait()); 27 | } 28 | 29 | [Test] 30 | public void null_password_throws() 31 | { 32 | Assert.Throws(() =>_manager.ResetPasswordAsync(_username, null, new UserCredentials("admin", "changeit")).Wait()); 33 | } 34 | 35 | [Test] 36 | public void can_reset_password() 37 | { 38 | _manager.ResetPasswordAsync(_username, "foo", new UserCredentials("admin", "changeit")).Wait(); 39 | var ex = Assert.Throws( 40 | () => _manager.ChangePasswordAsync(_username, "password", "foobar", new UserCredentials(_username, "password")).Wait() 41 | ); 42 | Assert.AreEqual(HttpStatusCode.Unauthorized, ((UserCommandFailedException)ex.InnerException).HttpStatusCode); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/can_create_duplicate_persistent_subscription_group_name_on_different_streams.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class can_create_duplicate_persistent_subscription_group_name_on_different_streams : SpecificationWithConnection 9 | { 10 | private readonly string _stream = Guid.NewGuid().ToString(); 11 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 12 | .DoNotResolveLinkTos() 13 | .StartFromCurrent(); 14 | protected override void When() 15 | { 16 | _conn.CreatePersistentSubscriptionAsync(_stream, "group3211", _settings, DefaultData.AdminCredentials).Wait(); 17 | 18 | } 19 | 20 | [Test] 21 | public void the_completion_succeeds() 22 | { 23 | Assert.DoesNotThrow(() => _conn.CreatePersistentSubscriptionAsync("someother" + _stream, "group3211", _settings, DefaultData.AdminCredentials).Wait()); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/connect_to_existing_persistent_subscription_with_max_one_client.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using EventStore.ClientAPI.ClientOperations; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture, Category("LongRunning")] 9 | public class connect_to_existing_persistent_subscription_with_max_one_client : SpecificationWithConnection 10 | { 11 | private readonly string _stream = "$" + Guid.NewGuid(); 12 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 13 | .DoNotResolveLinkTos() 14 | .StartFromCurrent() 15 | .WithMaxSubscriberCountOf(1); 16 | 17 | private Exception _exception; 18 | 19 | private const string _group = "startinbeginning1"; 20 | 21 | protected override void Given() 22 | { 23 | base.Given(); 24 | _conn.CreatePersistentSubscriptionAsync(_stream, _group, _settings, 25 | DefaultData.AdminCredentials).Wait(); 26 | _conn.ConnectToPersistentSubscription( 27 | _stream, 28 | _group, 29 | (s, e) => s.Acknowledge(e), 30 | (sub, reason, ex) => { }, 31 | DefaultData.AdminCredentials); 32 | } 33 | 34 | protected override void When() 35 | { 36 | _exception = Assert.Throws(() => { 37 | _conn.ConnectToPersistentSubscription( 38 | _stream, 39 | _group, 40 | (s, e) => s.Acknowledge(e), 41 | (sub, reason, ex) => { }, 42 | DefaultData.AdminCredentials); 43 | throw new Exception("should have thrown."); 44 | }).InnerException; 45 | } 46 | 47 | [Test] 48 | public void the_second_subscription_fails_to_connect() 49 | { 50 | Assert.IsInstanceOf(_exception); 51 | Assert.IsInstanceOf(_exception.InnerException); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/connect_to_existing_persistent_subscription_with_permissions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class connect_to_existing_persistent_subscription_with_permissions : SpecificationWithConnection 9 | { 10 | private EventStorePersistentSubscriptionBase _sub; 11 | private readonly string _stream = Guid.NewGuid().ToString(); 12 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 13 | .DoNotResolveLinkTos() 14 | .StartFromCurrent(); 15 | 16 | protected override void When() 17 | { 18 | _conn.CreatePersistentSubscriptionAsync(_stream, "agroupname17", _settings, DefaultData.AdminCredentials).Wait(); 19 | _sub = _conn.ConnectToPersistentSubscription(_stream, 20 | "agroupname17", 21 | (sub, e) => Console.Write("appeared"), 22 | (sub, reason, ex) => {}); 23 | } 24 | 25 | [Test] 26 | public void the_subscription_suceeds() 27 | { 28 | Assert.IsNotNull(_sub); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/connect_to_existing_persistent_subscription_with_permissions_async.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class connect_to_existing_persistent_subscription_with_permissions_async : SpecificationWithConnection 9 | { 10 | private EventStorePersistentSubscriptionBase _sub; 11 | private readonly string _stream = Guid.NewGuid().ToString(); 12 | 13 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 14 | .DoNotResolveLinkTos() 15 | .StartFromCurrent(); 16 | 17 | protected override void When() 18 | { 19 | _conn.CreatePersistentSubscriptionAsync(_stream, "agroupname17", _settings, DefaultData.AdminCredentials).Wait(); 20 | _sub = _conn.ConnectToPersistentSubscriptionAsync(_stream, 21 | "agroupname17", 22 | (sub, e) => Console.Write("appeared"), 23 | (sub, reason, ex) => { }).Result; 24 | } 25 | 26 | [Test] 27 | public void the_subscription_suceeds() 28 | { 29 | Assert.IsNotNull(_sub); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using EventStore.ClientAPI; 6 | using NUnit.Framework; 7 | 8 | namespace EventStore.Core.Tests.ClientAPI 9 | { 10 | [TestFixture, Category("LongRunning")] 11 | public class connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it : SpecificationWithConnection 12 | { 13 | private readonly string _stream = "$" + Guid.NewGuid(); 14 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 15 | .DoNotResolveLinkTos() 16 | .StartFromCurrent(); 17 | 18 | private readonly AutoResetEvent _resetEvent = new AutoResetEvent(false); 19 | 20 | private const string _group = "startinbeginning1"; 21 | 22 | protected override void Given() 23 | { 24 | WriteEvents(_conn); 25 | _conn.CreatePersistentSubscriptionAsync(_stream, _group, _settings, 26 | DefaultData.AdminCredentials).Wait(); 27 | } 28 | 29 | private void WriteEvents(IEventStoreConnection connection) 30 | { 31 | for (int i = 0; i < 10; i++) 32 | { 33 | connection.AppendToStreamAsync(_stream, ExpectedVersion.Any, DefaultData.AdminCredentials, 34 | new EventData(Guid.NewGuid(), "test", true, Encoding.UTF8.GetBytes("{'foo' : 'bar'}"), new byte[0])).Wait(); 35 | } 36 | } 37 | 38 | protected override void When() 39 | { 40 | _conn.ConnectToPersistentSubscription( 41 | _stream, 42 | _group, 43 | HandleEvent, 44 | (sub, reason, ex) => { }, 45 | DefaultData.AdminCredentials); 46 | } 47 | 48 | private Task HandleEvent(EventStorePersistentSubscriptionBase sub, ResolvedEvent resolvedEvent) 49 | { 50 | _resetEvent.Set(); 51 | return Task.CompletedTask; 52 | } 53 | 54 | [Test] 55 | public void the_subscription_gets_no_events() 56 | { 57 | Assert.IsFalse(_resetEvent.WaitOne(TimeSpan.FromSeconds(1))); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_async.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using EventStore.ClientAPI; 6 | using NUnit.Framework; 7 | 8 | namespace EventStore.Core.Tests.ClientAPI 9 | { 10 | [TestFixture, Category("LongRunning")] 11 | public class connect_to_existing_persistent_subscription_with_start_from_beginning_not_set_and_events_in_it_async : SpecificationWithConnection 12 | { 13 | private readonly string _stream = "$" + Guid.NewGuid(); 14 | 15 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 16 | .DoNotResolveLinkTos() 17 | .StartFromCurrent(); 18 | 19 | private readonly AutoResetEvent _resetEvent = new AutoResetEvent(false); 20 | 21 | private const string _group = "startinbeginning1"; 22 | 23 | protected override void Given() 24 | { 25 | WriteEvents(_conn); 26 | _conn.CreatePersistentSubscriptionAsync(_stream, _group, _settings, 27 | DefaultData.AdminCredentials).Wait(); 28 | } 29 | 30 | private void WriteEvents(IEventStoreConnection connection) 31 | { 32 | for (int i = 0; i < 10; i++) 33 | { 34 | connection.AppendToStreamAsync(_stream, ExpectedVersion.Any, DefaultData.AdminCredentials, 35 | new EventData(Guid.NewGuid(), "test", true, Encoding.UTF8.GetBytes("{'foo' : 'bar'}"), new byte[0])).Wait(); 36 | } 37 | } 38 | 39 | protected override void When() 40 | { 41 | _conn.ConnectToPersistentSubscriptionAsync( 42 | _stream, 43 | _group, 44 | HandleEvent, 45 | (sub, reason, ex) => { }, 46 | DefaultData.AdminCredentials).Wait(); 47 | } 48 | 49 | private Task HandleEvent(EventStorePersistentSubscriptionBase sub, ResolvedEvent resolvedEvent) 50 | { 51 | _resetEvent.Set(); 52 | return Task.CompletedTask; 53 | } 54 | 55 | [Test] 56 | public void the_subscription_gets_no_events() 57 | { 58 | Assert.IsFalse(_resetEvent.WaitOne(TimeSpan.FromSeconds(1))); 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/connect_to_existing_persistent_subscription_without_permissions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using EventStore.ClientAPI.Exceptions; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture, Category("LongRunning")] 9 | public class connect_to_existing_persistent_subscription_without_permissions : SpecificationWithConnection 10 | { 11 | private readonly string _stream = "$" + Guid.NewGuid(); 12 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 13 | .DoNotResolveLinkTos() 14 | .StartFromCurrent(); 15 | protected override void When() 16 | { 17 | _conn.CreatePersistentSubscriptionAsync(_stream, "agroupname55", _settings, 18 | DefaultData.AdminCredentials).Wait(); 19 | } 20 | 21 | [Test] 22 | public void the_subscription_fails_to_connect() 23 | { 24 | try 25 | { 26 | _conn.ConnectToPersistentSubscription( 27 | _stream, 28 | "agroupname55", 29 | (sub, e) => Console.Write("appeared"), 30 | (sub, reason, ex) => Console.WriteLine("dropped.")); 31 | throw new Exception("should have thrown."); 32 | } 33 | catch (Exception ex) 34 | { 35 | var innerEx = ex.InnerException; 36 | Assert.IsInstanceOf(innerEx); 37 | Assert.IsInstanceOf(innerEx.InnerException); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/connect_to_existing_persistent_subscription_without_permissions_async.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using EventStore.ClientAPI.Exceptions; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture, Category("LongRunning")] 9 | public class connect_to_existing_persistent_subscription_without_permissions_async : SpecificationWithConnection 10 | { 11 | private readonly string _stream = "$" + Guid.NewGuid(); 12 | 13 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 14 | .DoNotResolveLinkTos() 15 | .StartFromCurrent(); 16 | 17 | private Exception _innerEx; 18 | 19 | protected override void When() 20 | { 21 | _conn.CreatePersistentSubscriptionAsync(_stream, "agroupname55", _settings, 22 | DefaultData.AdminCredentials).Wait(); 23 | _innerEx = Assert.Throws(() => 24 | { 25 | _conn.ConnectToPersistentSubscriptionAsync( 26 | _stream, 27 | "agroupname55", 28 | (sub, e) => Console.Write("appeared"), 29 | (sub, reason, ex) => Console.WriteLine("dropped.")).Wait(); 30 | }).InnerException; 31 | } 32 | 33 | [Test] 34 | public void the_subscription_fails_to_connect_with_access_denied_exception() 35 | { 36 | Assert.IsInstanceOf(_innerEx); 37 | Assert.IsInstanceOf(_innerEx.InnerException); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/connect_to_non_existing_persistent_subscription_with_permissions_async.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class connect_to_non_existing_persistent_subscription_with_permissions_async : SpecificationWithConnection 9 | { 10 | private Exception _innerEx; 11 | 12 | protected override void When() 13 | { 14 | _innerEx = Assert.Throws(() => 15 | { 16 | _conn.ConnectToPersistentSubscriptionAsync( 17 | "nonexisting2", 18 | "foo", 19 | (sub, e, i) => 20 | { 21 | Console.Write("appeared"); 22 | return Task.CompletedTask; 23 | }, 24 | (sub, reason, ex) => 25 | { 26 | }).Wait(); 27 | }).InnerException; 28 | } 29 | 30 | [Test] 31 | public void the_subscription_fails_to_connect_with_argument_exception() 32 | { 33 | Assert.IsInstanceOf(_innerEx); 34 | Assert.IsInstanceOf(_innerEx.InnerException); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_duplicate_persistent_subscription_group.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class create_duplicate_persistent_subscription_group : SpecificationWithConnection 9 | { 10 | private readonly string _stream = Guid.NewGuid().ToString(); 11 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 12 | .DoNotResolveLinkTos() 13 | .StartFromCurrent(); 14 | protected override void When() 15 | { 16 | _conn.CreatePersistentSubscriptionAsync(_stream, "group32", _settings, DefaultData.AdminCredentials).Wait(); 17 | } 18 | 19 | [Test] 20 | public void the_completion_fails_with_invalid_operation_exception() 21 | { 22 | 23 | try 24 | { 25 | _conn.CreatePersistentSubscriptionAsync(_stream, "group32",_settings, DefaultData.AdminCredentials).Wait(); 26 | throw new Exception("expected exception"); 27 | } 28 | catch (Exception ex) 29 | { 30 | Assert.IsInstanceOf(typeof(AggregateException), ex); 31 | var inner = ex.InnerException; 32 | Assert.IsInstanceOf(typeof(InvalidOperationException), inner); 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_persistent_subscription_after_deleting_the_same.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using EventStore.ClientAPI; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture, Category("LongRunning")] 9 | public class create_persistent_subscription_after_deleting_the_same : SpecificationWithConnection 10 | { 11 | private readonly string _stream = Guid.NewGuid().ToString(); 12 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 13 | .DoNotResolveLinkTos() 14 | .StartFromCurrent(); 15 | protected override void When() 16 | { 17 | _conn.AppendToStreamAsync(_stream, ExpectedVersion.Any, 18 | new EventData(Guid.NewGuid(), "whatever", true, Encoding.UTF8.GetBytes("{'foo' : 2}"), new Byte[0])); 19 | _conn.CreatePersistentSubscriptionAsync(_stream, "existing", _settings, DefaultData.AdminCredentials).Wait(); 20 | _conn.DeletePersistentSubscriptionAsync(_stream, "existing", DefaultData.AdminCredentials).Wait(); 21 | 22 | } 23 | 24 | [Test] 25 | public void the_completion_succeeds() 26 | { 27 | Assert.DoesNotThrow(() => _conn.CreatePersistentSubscriptionAsync(_stream, "existing", _settings, DefaultData.AdminCredentials).Wait()); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_persistent_subscription_group_without_permissions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using EventStore.ClientAPI.Exceptions; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture, Category("LongRunning")] 9 | public class create_persistent_subscription_group_without_permissions : SpecificationWithConnection 10 | { 11 | private readonly string _stream = Guid.NewGuid().ToString(); 12 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 13 | .DoNotResolveLinkTos() 14 | .StartFromCurrent(); 15 | protected override void When() 16 | { 17 | } 18 | 19 | [Test] 20 | public void the_completion_succeeds() 21 | { 22 | try 23 | { 24 | _conn.CreatePersistentSubscriptionAsync(_stream, "group57", _settings, null).Wait(); 25 | throw new Exception("expected exception"); 26 | } 27 | catch (Exception ex) 28 | { 29 | Assert.IsInstanceOf(typeof(AggregateException), ex); 30 | var inner = ex.InnerException; 31 | Assert.IsInstanceOf(typeof(AccessDeniedException), inner); 32 | } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_persistent_subscription_on_all_stream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class create_persistent_subscription_on_all_stream : SpecificationWithConnection 9 | { 10 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 11 | .DoNotResolveLinkTos() 12 | .StartFromCurrent(); 13 | protected override void When() 14 | { 15 | 16 | } 17 | 18 | [Test] 19 | public void the_completion_fails_with_invalid_stream() 20 | { 21 | Assert.Throws(() => _conn.CreatePersistentSubscriptionAsync("$all", "shitbird", _settings, DefaultData.AdminCredentials).Wait()); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_persistent_subscription_on_existing_stream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using EventStore.ClientAPI; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture, Category("LongRunning")] 9 | public class create_persistent_subscription_on_existing_stream : SpecificationWithConnection 10 | { 11 | private readonly string _stream = Guid.NewGuid().ToString(); 12 | 13 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 14 | .DoNotResolveLinkTos() 15 | .StartFromCurrent(); 16 | 17 | protected override void When() 18 | { 19 | _conn.AppendToStreamAsync(_stream, ExpectedVersion.Any, 20 | new EventData(Guid.NewGuid(), "whatever", true, Encoding.UTF8.GetBytes("{'foo' : 2}"), new Byte[0])); 21 | } 22 | 23 | [Test] 24 | public void the_completion_succeeds() 25 | { 26 | Assert.DoesNotThrow( 27 | () => 28 | _conn.CreatePersistentSubscriptionAsync(_stream, "existing", _settings, DefaultData.AdminCredentials) 29 | .Wait()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_persistent_subscription_on_non_existing_stream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class create_persistent_subscription_on_non_existing_stream : SpecificationWithConnection 9 | { 10 | private readonly string _stream = Guid.NewGuid().ToString(); 11 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 12 | .DoNotResolveLinkTos() 13 | .StartFromCurrent(); 14 | protected override void When() 15 | { 16 | 17 | } 18 | 19 | [Test] 20 | public void the_completion_succeeds() 21 | { 22 | Assert.DoesNotThrow(() => _conn.CreatePersistentSubscriptionAsync(_stream, "nonexistinggroup", _settings, DefaultData.AdminCredentials).Wait()); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_persistent_subscription_with_dont_timeout.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class create_persistent_subscription_with_dont_timeout : SpecificationWithConnection 9 | { 10 | private readonly string _stream = Guid.NewGuid().ToString(); 11 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 12 | .DoNotResolveLinkTos() 13 | .StartFromCurrent() 14 | .DontTimeoutMessages(); 15 | protected override void When() 16 | { 17 | } 18 | 19 | [Test] 20 | public void the_message_timeout_should_be_zero() 21 | { 22 | Assert.That(_settings.MessageTimeout == TimeSpan.Zero); 23 | } 24 | 25 | [Test] 26 | public void the_subscription_is_created_without_error() 27 | { 28 | Assert.DoesNotThrow( 29 | () => 30 | _conn.CreatePersistentSubscriptionAsync(_stream, "dont-timeout", _settings, DefaultData.AdminCredentials).Wait() 31 | ); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_persistent_subscription_with_too_big_checkpoint_after.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class create_persistent_subscription_with_too_big_checkpoint_after : SpecificationWithConnection 9 | { 10 | 11 | protected override void When() 12 | { 13 | 14 | } 15 | 16 | [Test] 17 | public void the_build_fails_with_argument_exception() 18 | { 19 | Assert.Throws(() => PersistentSubscriptionSettings.Create().CheckPointAfter(TimeSpan.FromDays(25 * 365)).Build()); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_persistent_subscription_with_too_big_message_timeout.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class create_persistent_subscription_with_too_big_message_timeout : SpecificationWithConnection 9 | { 10 | protected override void When() 11 | { 12 | 13 | } 14 | 15 | [Test] 16 | public void the_build_fails_with_argument_exception() 17 | { 18 | Assert.Throws(() => PersistentSubscriptionSettings.Create().WithMessageTimeoutOf(TimeSpan.FromDays(25 * 365)).Build()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/create_persistent_subscription_with_too_big_retry_after.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class create_persistent_subscription_with_too_big_retry_after : SpecificationWithConnection 9 | { 10 | protected override void When() 11 | { 12 | 13 | } 14 | [Test] 15 | public void the_build_fails_with_argument_exception() 16 | { 17 | Assert.Throws(() => PersistentSubscriptionSettings.Create().CheckPointAfter(TimeSpan.FromDays(25 * 365)).Build()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/deleting_existing_persistent_subscription_with_subscriber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using EventStore.ClientAPI; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture, Category("LongRunning")] 9 | public class deleting_existing_persistent_subscription_with_subscriber : SpecificationWithConnection 10 | { 11 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 12 | .DoNotResolveLinkTos() 13 | .StartFromCurrent(); 14 | private readonly string _stream = Guid.NewGuid().ToString(); 15 | private readonly ManualResetEvent _called = new ManualResetEvent(false); 16 | 17 | protected override void Given() 18 | { 19 | base.Given(); 20 | _conn.CreatePersistentSubscriptionAsync(_stream, "groupname123", _settings, 21 | DefaultData.AdminCredentials).Wait(); 22 | _conn.ConnectToPersistentSubscription(_stream, "groupname123", 23 | (s, e) => { }, 24 | (s, r, e) => _called.Set()); 25 | } 26 | 27 | protected override void When() 28 | { 29 | _conn.DeletePersistentSubscriptionAsync(_stream, "groupname123", DefaultData.AdminCredentials).Wait(); 30 | } 31 | 32 | [Test] 33 | public void the_subscription_is_dropped() 34 | { 35 | Assert.IsTrue(_called.WaitOne(TimeSpan.FromSeconds(5))); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/deleting_persistent_subscription_group_that_doesnt_exist.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI 5 | { 6 | [TestFixture, Category("LongRunning")] 7 | public class deleting_persistent_subscription_group_that_doesnt_exist : SpecificationWithConnection 8 | { 9 | private readonly string _stream = Guid.NewGuid().ToString(); 10 | 11 | protected override void When() 12 | { 13 | } 14 | 15 | [Test] 16 | public void the_delete_fails_with_argument_exception() 17 | { 18 | try 19 | { 20 | _conn.DeletePersistentSubscriptionAsync(_stream, Guid.NewGuid().ToString(), DefaultData.AdminCredentials).Wait(); 21 | throw new Exception("expected exception"); 22 | } 23 | catch (Exception ex) 24 | { 25 | Assert.IsInstanceOf(typeof(AggregateException), ex); 26 | var inner = ex.InnerException; 27 | Assert.IsInstanceOf(typeof(InvalidOperationException), inner); 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/deleting_persistent_subscription_group_without_permissions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI.Exceptions; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class deleting_persistent_subscription_group_without_permissions : SpecificationWithConnection 9 | { 10 | private readonly string _stream = Guid.NewGuid().ToString(); 11 | 12 | protected override void When() 13 | { 14 | } 15 | 16 | [Test] 17 | public void the_delete_fails_with_access_denied() 18 | { 19 | try 20 | { 21 | _conn.DeletePersistentSubscriptionAsync(_stream, Guid.NewGuid().ToString()).Wait(); 22 | throw new Exception("expected exception"); 23 | } 24 | catch (Exception ex) 25 | { 26 | Assert.IsInstanceOf(typeof(AggregateException), ex); 27 | var inner = ex.InnerException; 28 | Assert.IsInstanceOf(typeof(AccessDeniedException), inner); 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/happy_case_writing_and_subscribing_to_normal_events_auto_ack.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using EventStore.ClientAPI; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture, Category("LongRunning")] 9 | public class happy_case_writing_and_subscribing_to_normal_events_auto_ack : SpecificationWithConnection 10 | { 11 | private readonly string StreamName = Guid.NewGuid().ToString(); 12 | private readonly string GroupName = Guid.NewGuid().ToString(); 13 | private const int BufferCount = 10; 14 | private const int EventWriteCount = BufferCount*2; 15 | 16 | private readonly ManualResetEvent _eventsReceived = new ManualResetEvent(false); 17 | private int _eventReceivedCount; 18 | 19 | protected override void When() 20 | { 21 | } 22 | 23 | [Test] 24 | public void Test() 25 | { 26 | var settings = PersistentSubscriptionSettings 27 | .Create() 28 | .StartFromCurrent() 29 | .ResolveLinkTos() 30 | .Build(); 31 | _conn.CreatePersistentSubscriptionAsync(StreamName, GroupName, settings, DefaultData.AdminCredentials) 32 | .Wait(); 33 | _conn.ConnectToPersistentSubscription(StreamName, GroupName, 34 | (subscription, resolvedEvent) => 35 | { 36 | if (Interlocked.Increment(ref _eventReceivedCount) == EventWriteCount) 37 | { 38 | _eventsReceived.Set(); 39 | } 40 | }, 41 | (sub, reason, exception) => 42 | Console.WriteLine("Subscription dropped (reason:{0}, exception:{1}).", reason, exception), 43 | userCredentials: DefaultData.AdminCredentials); 44 | 45 | for (var i = 0; i < EventWriteCount; i++) 46 | { 47 | var eventData = new EventData(Guid.NewGuid(), "SomeEvent", false, new byte[0], new byte[0]); 48 | 49 | _conn.AppendToStreamAsync(StreamName, ExpectedVersion.Any, DefaultData.AdminCredentials, eventData); 50 | } 51 | 52 | if (!_eventsReceived.WaitOne(TimeSpan.FromSeconds(5))) 53 | { 54 | throw new Exception("Timed out waiting for events."); 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/read_all_events_forward_with_linkto_passed_max_count.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI 5 | { 6 | [TestFixture] 7 | public class read_all_events_forward_with_linkto_passed_max_count : SpecificationWithLinkToToMaxCountDeletedEvents 8 | { 9 | private StreamEventsSlice _read; 10 | 11 | protected override void When() 12 | { 13 | _read = _conn.ReadStreamEventsForwardAsync(LinkedStreamName, 0, 1, true).Result; 14 | } 15 | 16 | [Test] 17 | public void one_event_is_read() 18 | { 19 | Assert.AreEqual(1, _read.Events.Length); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/read_all_events_forward_with_linkto_to_deleted_event.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI 5 | { 6 | [TestFixture, Category("LongRunning")] 7 | public class read_all_events_forward_with_linkto_to_deleted_event : SpecificationWithLinkToToDeletedEvents 8 | { 9 | private StreamEventsSlice _read; 10 | protected override void When() 11 | { 12 | _read = _conn.ReadStreamEventsForwardAsync(LinkedStreamName, 0, 1, true, null).Result; 13 | } 14 | 15 | [Test] 16 | public void one_event_is_read() 17 | { 18 | Assert.AreEqual(1, _read.Events.Length); 19 | } 20 | 21 | [Test] 22 | public void the_linked_event_is_not_resolved() 23 | { 24 | Assert.IsNull(_read.Events[0].Event); 25 | } 26 | 27 | [Test] 28 | public void the_link_event_is_included() 29 | { 30 | Assert.IsNotNull(_read.Events[0].OriginalEvent); 31 | } 32 | 33 | [Test] 34 | public void the_event_is_not_resolved() 35 | { 36 | Assert.IsFalse(_read.Events[0].IsResolved); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/read_allevents_backward_with_linkto_deleted_event.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI 5 | { 6 | [TestFixture, Category("LongRunning")] 7 | public class read_allevents_backward_with_linkto_deleted_event : SpecificationWithLinkToToDeletedEvents 8 | { 9 | private StreamEventsSlice _read; 10 | protected override void When() 11 | { 12 | _read = _conn.ReadStreamEventsBackwardAsync(LinkedStreamName, 0, 1, true, null).Result; 13 | } 14 | 15 | [Test] 16 | public void one_event_is_read() 17 | { 18 | Assert.AreEqual(1, _read.Events.Length); 19 | } 20 | 21 | [Test] 22 | public void the_linked_event_is_not_resolved() 23 | { 24 | Assert.IsNull(_read.Events[0].Event); 25 | } 26 | 27 | [Test] 28 | public void the_link_event_is_included() 29 | { 30 | Assert.IsNotNull(_read.Events[0].OriginalEvent); 31 | } 32 | 33 | [Test] 34 | public void the_event_is_not_resolved() 35 | { 36 | Assert.IsFalse(_read.Events[0].IsResolved); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/read_event_of_linkto_to_deleted_event.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI 5 | { 6 | [TestFixture, Category("LongRunning")] 7 | public class read_event_of_linkto_to_deleted_event : SpecificationWithLinkToToDeletedEvents 8 | { 9 | private EventReadResult _read; 10 | protected override void When() 11 | { 12 | _read = _conn.ReadEventAsync(LinkedStreamName, 0,true).Result; 13 | } 14 | 15 | [Test] 16 | public void the_linked_event_is_returned() 17 | { 18 | Assert.IsNotNull(_read.Event.Value.Link); 19 | } 20 | 21 | [Test] 22 | public void the_deleted_event_is_not_resolved() 23 | { 24 | Assert.IsNull(_read.Event.Value.Event); 25 | } 26 | 27 | [Test] 28 | public void the_status_is_success() 29 | { 30 | Assert.AreEqual(EventReadStatus.Success, _read.Status); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/update_existing_persistent_subscription.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using EventStore.ClientAPI; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture, Category("LongRunning")] 9 | public class update_existing_persistent_subscription : SpecificationWithConnection 10 | { 11 | private readonly string _stream = Guid.NewGuid().ToString(); 12 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 13 | .DoNotResolveLinkTos() 14 | .StartFromCurrent(); 15 | 16 | protected override void Given() 17 | { 18 | _conn.AppendToStreamAsync(_stream, ExpectedVersion.Any, 19 | new EventData(Guid.NewGuid(), "whatever", true, Encoding.UTF8.GetBytes("{'foo' : 2}"), new Byte[0])); 20 | _conn.CreatePersistentSubscriptionAsync(_stream, "existing", _settings, DefaultData.AdminCredentials).Wait(); 21 | } 22 | 23 | protected override void When() 24 | { 25 | 26 | } 27 | 28 | [Test] 29 | public void the_completion_succeeds() 30 | { 31 | Assert.DoesNotThrow(() => _conn.UpdatePersistentSubscriptionAsync(_stream, "existing", _settings, DefaultData.AdminCredentials).Wait()); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/update_existing_persistent_subscription_without_permissions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using EventStore.ClientAPI; 4 | using EventStore.ClientAPI.Exceptions; 5 | using NUnit.Framework; 6 | 7 | namespace EventStore.Core.Tests.ClientAPI 8 | { 9 | [TestFixture, Category("LongRunning")] 10 | public class update_existing_persistent_subscription_without_permissions : SpecificationWithConnection 11 | { 12 | private readonly string _stream = Guid.NewGuid().ToString(); 13 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 14 | .DoNotResolveLinkTos() 15 | .StartFromCurrent(); 16 | 17 | protected override void When() 18 | { 19 | _conn.AppendToStreamAsync(_stream, ExpectedVersion.Any, 20 | new EventData(Guid.NewGuid(), "whatever", true, Encoding.UTF8.GetBytes("{'foo' : 2}"), new Byte[0])); 21 | _conn.CreatePersistentSubscriptionAsync(_stream, "existing", _settings, DefaultData.AdminCredentials).Wait(); 22 | } 23 | 24 | [Test] 25 | public void the_completion_fails_with_access_denied() 26 | { 27 | try 28 | { 29 | _conn.UpdatePersistentSubscriptionAsync(_stream, "existing", _settings, null).Wait(); 30 | Assert.Fail("should have thrown"); 31 | } 32 | catch (Exception ex) 33 | { 34 | Assert.IsInstanceOf(ex); 35 | Assert.IsInstanceOf(ex.InnerException); 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/update_non_existing_persistent_subscription.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI; 3 | using NUnit.Framework; 4 | 5 | namespace EventStore.Core.Tests.ClientAPI 6 | { 7 | [TestFixture, Category("LongRunning")] 8 | public class update_non_existing_persistent_subscription : SpecificationWithConnection 9 | { 10 | private readonly string _stream = Guid.NewGuid().ToString(); 11 | private readonly PersistentSubscriptionSettings _settings = PersistentSubscriptionSettings.Create() 12 | .DoNotResolveLinkTos() 13 | .StartFromCurrent(); 14 | 15 | protected override void When() 16 | { 17 | 18 | } 19 | 20 | [Test] 21 | public void the_completion_fails_with_not_found() 22 | { 23 | try 24 | { 25 | _conn.UpdatePersistentSubscriptionAsync(_stream, "existing", _settings, 26 | DefaultData.AdminCredentials).Wait(); 27 | Assert.Fail("should have thrown"); 28 | } 29 | catch (Exception ex) 30 | { 31 | Assert.IsInstanceOf(ex); 32 | Assert.IsInstanceOf(ex.InnerException); 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_a_projection_is_running.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI 5 | { 6 | [TestFixture] 7 | [Category("ProjectionsManager")] 8 | public class when_a_projection_is_running : ProjectionSpecification 9 | { 10 | private string _projectionName; 11 | private string _streamName; 12 | private string _query; 13 | 14 | public override void Given() 15 | { 16 | _projectionName = "when_getting_projection_information"; 17 | _streamName = "test-stream-" + Guid.NewGuid().ToString(); 18 | 19 | PostEvent(_streamName, "testEvent", "{\"A\":\"1\"}"); 20 | PostEvent(_streamName, "testEvent", "{\"A\":\"2\"}"); 21 | } 22 | 23 | public override void When() 24 | { 25 | _query = CreateStandardQuery(_streamName); 26 | _projManager.CreateContinuousAsync(_projectionName, _query, _credentials).Wait(); 27 | } 28 | 29 | [Test] 30 | public void should_be_able_to_get_the_projection_state() 31 | { 32 | var state = _projManager.GetStateAsync(_projectionName, _credentials).Result; 33 | Assert.IsNotEmpty((string) state); 34 | } 35 | 36 | [Test] 37 | public void should_be_able_to_get_the_projection_status() 38 | { 39 | var status = _projManager.GetStatusAsync(_projectionName, _credentials).Result; 40 | Assert.IsNotEmpty((string) status); 41 | } 42 | 43 | [Test] 44 | public void should_be_able_to_get_the_projection_result() 45 | { 46 | var result = _projManager.GetResultAsync(_projectionName, _credentials).Result; 47 | Assert.AreEqual("{\"count\":1}", result); 48 | } 49 | 50 | [Test] 51 | public void should_be_able_to_get_the_projection_query() 52 | { 53 | var query = _projManager.GetQueryAsync(_projectionName, _credentials).Result; 54 | Assert.AreEqual(_query, query); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_connecting_with_connection_string.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using EventStore.ClientAPI; 4 | using EventStore.Core.Tests.ClientAPI.Helpers; 5 | using NUnit.Framework; 6 | 7 | namespace EventStore.Core.Tests.ClientAPI 8 | { 9 | public class when_connecting_with_connection_string 10 | { 11 | [Test] 12 | [Category("Network")] 13 | public void should_not_throw_when_connect_to_is_set() 14 | { 15 | string connectionString = string.Format("ConnectTo=tcp://{0};", TestNode.TcpEndPoint); 16 | using(var connection = EventStoreConnection.Create(connectionString)) 17 | { 18 | Assert.DoesNotThrow(connection.ConnectAsync().Wait); 19 | connection.Close(); 20 | } 21 | } 22 | 23 | [Test] 24 | public void should_not_throw_when_only_gossip_seeds_is_set() 25 | { 26 | string connectionString = string.Format("GossipSeeds={0};", TestNode.GossipEndPoint); 27 | IEventStoreConnection connection = null; 28 | 29 | Assert.DoesNotThrow(() => connection = EventStoreConnection.Create(connectionString)); 30 | Assert.AreEqual(TestNode.GossipEndPoint, connection.Settings.GossipSeeds.First().EndPoint); 31 | 32 | connection.Dispose(); 33 | } 34 | 35 | [Test] 36 | public void should_throw_when_gossip_seeds_and_connect_to_is_set() 37 | { 38 | string connectionString = string.Format("ConnectTo=tcp://{0};GossipSeeds={1}", TestNode.TcpEndPoint, TestNode.GossipEndPoint); 39 | Assert.Throws(() => EventStoreConnection.Create(connectionString)); 40 | } 41 | 42 | [Test] 43 | public void should_throw_when_neither_gossip_seeds_nor_connect_to_is_set() 44 | { 45 | string connectionString = string.Format("HeartBeatTimeout=2000"); 46 | Assert.Throws(() => EventStoreConnection.Create(connectionString)); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_creating_continuous_projection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | using EventStore.ClientAPI.Projections; 5 | using Newtonsoft.Json.Linq; 6 | using NUnit.Framework; 7 | using EventStore.ClientAPI.Common.Utils; 8 | 9 | namespace EventStore.Core.Tests.ClientAPI 10 | { 11 | [TestFixture] 12 | [Category("ProjectionsManager")] 13 | public class when_creating_continuous_projection : ProjectionSpecification 14 | { 15 | private string _streamName; 16 | private string _emittedStreamName; 17 | private string _projectionName; 18 | private string _query; 19 | private string _projectionId; 20 | 21 | public override void Given() 22 | { 23 | _streamName = "test-stream-" + Guid.NewGuid(); 24 | _projectionName = "when_creating_continuous_projection"; 25 | _emittedStreamName = "emittedStream-" + Guid.NewGuid(); 26 | PostEvent(_streamName, "testEvent", "{\"A\":\"1\"}"); 27 | PostEvent(_streamName, "testEvent", "{\"A\":\"2\"}"); 28 | 29 | _query = CreateEmittingQuery(_streamName, _emittedStreamName); 30 | } 31 | 32 | public override void When() 33 | { 34 | _projManager.CreateContinuousAsync(_projectionName, _query, _credentials).Wait(); 35 | } 36 | 37 | [Test] 38 | public void should_create_projection() 39 | { 40 | var allProjections = _projManager.ListContinuousAsync(_credentials).Result; 41 | var proj = Enumerable.FirstOrDefault(allProjections, x => x.EffectiveName == _projectionName); 42 | _projectionId = proj.Name; 43 | Assert.IsNotNull(proj); 44 | } 45 | 46 | [Test] 47 | public void should_have_turn_on_emit_to_stream() 48 | { 49 | var events = _connection.ReadEventAsync(string.Format((string) "$projections-{0}", (object) _projectionId), 0, true, _credentials).Result; 50 | var data = Encoding.UTF8.GetString(events.Event.Value.Event.Data); 51 | var eventData = data.ParseJson(); 52 | Assert.IsTrue((bool)eventData["emitEnabled"]); 53 | } 54 | 55 | } 56 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_creating_continuous_projection_with_track_emitted_streams.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | using EventStore.ClientAPI.Common.Utils; 5 | using EventStore.ClientAPI.Projections; 6 | using Newtonsoft.Json.Linq; 7 | using NUnit.Framework; 8 | 9 | namespace EventStore.Core.Tests.ClientAPI 10 | { 11 | [TestFixture] 12 | [Category("ProjectionsManager")] 13 | public class when_creating_continuous_projection_with_track_emitted_streams : ProjectionSpecification 14 | { 15 | private string _streamName; 16 | private string _emittedStreamName; 17 | private string _projectionName; 18 | private string _query; 19 | private string _projectionId; 20 | 21 | public override void Given() 22 | { 23 | _streamName = "test-stream-" + Guid.NewGuid(); 24 | _projectionName = "when_creating_continuous_projection_with_track_emitted_streams"; 25 | _emittedStreamName = "emittedStream-" + Guid.NewGuid(); 26 | PostEvent(_streamName, "testEvent", "{\"A\":\"1\"}"); 27 | 28 | _query = CreateEmittingQuery(_streamName, _emittedStreamName); 29 | } 30 | 31 | public override void When() 32 | { 33 | _projManager.CreateContinuousAsync(_projectionName, _query, true, _credentials).Wait(); 34 | } 35 | 36 | [Test] 37 | public void should_create_projection() 38 | { 39 | var allProjections = _projManager.ListContinuousAsync(_credentials).Result; 40 | var proj = Enumerable.FirstOrDefault(allProjections, x => x.EffectiveName == _projectionName); 41 | _projectionId = proj.Name; 42 | Assert.IsNotNull(proj); 43 | } 44 | 45 | [Test] 46 | public void should_enable_track_emitted_streams() 47 | { 48 | var events = _connection.ReadEventAsync(string.Format((string) "$projections-{0}", (object) _projectionId), 0, true, _credentials).Result; 49 | var data = Encoding.UTF8.GetString(events.Event.Value.Event.Data); 50 | var eventData = data.ParseJson(); 51 | Assert.IsTrue((bool)eventData["trackEmittedStreams"]); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_creating_one_time_projection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI 5 | { 6 | [TestFixture] 7 | [Category("ProjectionsManager")] 8 | public class when_creating_one_time_projection : ProjectionSpecification 9 | { 10 | private string _streamName; 11 | private string _query; 12 | 13 | public override void Given() 14 | { 15 | _streamName = "test-stream-" + Guid.NewGuid().ToString(); 16 | PostEvent(_streamName, "testEvent", "{\"A\":\"1\"}"); 17 | PostEvent(_streamName, "testEvent", "{\"A\":\"2\"}"); 18 | 19 | _query = CreateStandardQuery(_streamName); 20 | } 21 | 22 | public override void When() 23 | { 24 | _projManager.CreateOneTimeAsync(_query, _credentials).Wait(); 25 | } 26 | 27 | [Test] 28 | public void should_create_projection() 29 | { 30 | var projections = _projManager.ListOneTimeAsync(_credentials).Result; 31 | Assert.AreEqual(1, projections.Count); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_creating_transient_projection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI 5 | { 6 | [TestFixture] 7 | [Category("ProjectionsManager")] 8 | public class when_creating_transient_projection : ProjectionSpecification 9 | { 10 | private string _streamName; 11 | private string _projectionName; 12 | private string _query; 13 | 14 | public override void Given() 15 | { 16 | _streamName = "test-stream-" + Guid.NewGuid().ToString(); 17 | _projectionName = "when_creating_transient_projection"; 18 | PostEvent(_streamName, "testEvent", "{\"A\":\"1\"}"); 19 | PostEvent(_streamName, "testEvent", "{\"A\":\"2\"}"); 20 | 21 | _query = CreateStandardQuery(_streamName); 22 | } 23 | 24 | public override void When() 25 | { 26 | _projManager.CreateTransientAsync(_projectionName, _query, _credentials).Wait(); 27 | } 28 | 29 | [Test] 30 | public void should_create_projection() 31 | { 32 | var status = _projManager.GetStatusAsync(_projectionName, _credentials).Result; 33 | Assert.IsNotEmpty((string) status); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_disabling_projections.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EventStore.ClientAPI.Common.Utils; 3 | using Newtonsoft.Json.Linq; 4 | using NUnit.Framework; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture] 9 | [Category("ProjectionsManager")] 10 | public class when_disabling_projections : ProjectionSpecification 11 | { 12 | private string _streamName; 13 | private string _projectionName; 14 | private string _query; 15 | 16 | public override void Given() 17 | { 18 | _streamName = "test-stream-" + Guid.NewGuid().ToString(); 19 | _projectionName = "when_disabling_projection"; 20 | PostEvent(_streamName, "testEvent", "{\"A\":\"1\"}"); 21 | PostEvent(_streamName, "testEvent", "{\"A\":\"2\"}"); 22 | 23 | _query = CreateStandardQuery(_streamName); 24 | 25 | _projManager.CreateContinuousAsync(_projectionName, _query, _credentials).Wait(); 26 | } 27 | 28 | public override void When() 29 | { 30 | _projManager.DisableAsync(_projectionName, _credentials).Wait(); 31 | } 32 | 33 | [Test] 34 | public void should_stop_the_projection() 35 | { 36 | var projectionStatus = _projManager.GetStatusAsync(_projectionName, _credentials).Result; 37 | var status = projectionStatus.ParseJson()["status"].ToString(); 38 | Assert.IsTrue(status.Contains("Stopped"), "Status did not contain 'Stopped' : {0}", status); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_enabling_projections.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json.Linq; 3 | using NUnit.Framework; 4 | using EventStore.ClientAPI.Common.Utils; 5 | 6 | namespace EventStore.Core.Tests.ClientAPI 7 | { 8 | [TestFixture] 9 | [Category("ProjectionsManager")] 10 | public class when_enabling_projections : ProjectionSpecification 11 | { 12 | private string _streamName; 13 | private string _projectionName; 14 | private string _query; 15 | 16 | public override void Given() 17 | { 18 | _streamName = "test-stream-" + Guid.NewGuid().ToString(); 19 | _projectionName = "when_enabling_projections"; 20 | PostEvent(_streamName, "testEvent", "{\"A\":\"1\"}"); 21 | PostEvent(_streamName, "testEvent", "{\"A\":\"2\"}"); 22 | 23 | _query = CreateStandardQuery(_streamName); 24 | 25 | _projManager.CreateContinuousAsync(_projectionName, _query, _credentials).Wait(); 26 | _projManager.DisableAsync(_projectionName, _credentials).Wait(); 27 | } 28 | 29 | public override void When() 30 | { 31 | _projManager.EnableAsync(_projectionName, _credentials).Wait(); 32 | } 33 | 34 | [Test] 35 | public void should_reenable_projection() 36 | { 37 | var projectionStatus = _projManager.GetStatusAsync(_projectionName, _credentials).Result; 38 | var status = projectionStatus.ParseJson()["status"].ToString(); 39 | Assert.IsTrue(status.Contains("Running"), "Status did not contain 'Running' : {0}", status); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_listing_all_projections.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using EventStore.ClientAPI.Projections; 5 | using NUnit.Framework; 6 | 7 | namespace EventStore.Core.Tests.ClientAPI 8 | { 9 | [TestFixture] 10 | [Category("ProjectionsManager")] 11 | public class when_listing_all_projections : ProjectionSpecification 12 | { 13 | private List _result; 14 | public override void Given() 15 | { 16 | } 17 | 18 | public override void When() 19 | { 20 | _result = Enumerable.ToList(_projManager.ListAllAsync(_credentials).Result); 21 | } 22 | 23 | [Test] 24 | public void should_return_all_projections() 25 | { 26 | Assert.IsNotEmpty((IEnumerable) _result); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_listing_continuous_projections.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using EventStore.ClientAPI.Projections; 5 | using NUnit.Framework; 6 | 7 | namespace EventStore.Core.Tests.ClientAPI 8 | { 9 | [TestFixture] 10 | [Category("ProjectionsManager")] 11 | public class when_listing_continuous_projections : ProjectionSpecification 12 | { 13 | private List _result; 14 | private string _projectionName; 15 | 16 | public override void Given() 17 | { 18 | _projectionName = Guid.NewGuid().ToString(); 19 | CreateContinuousProjection(_projectionName); 20 | } 21 | 22 | public override void When() 23 | { 24 | _result = Enumerable.ToList(_projManager.ListContinuousAsync(_credentials).Result); 25 | } 26 | 27 | [Test] 28 | public void should_return_continuous_projections() 29 | { 30 | Assert.IsTrue(Enumerable.Any(_result, x => x.EffectiveName == _projectionName)); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_listing_one_time_projections.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using EventStore.ClientAPI.Projections; 5 | using NUnit.Framework; 6 | 7 | namespace EventStore.Core.Tests.ClientAPI 8 | { 9 | [TestFixture] 10 | [Category("ProjectionsManager")] 11 | public class when_listing_one_time_projections : ProjectionSpecification 12 | { 13 | private List _result; 14 | public override void Given() 15 | { 16 | CreateOneTimeProjection(); 17 | } 18 | 19 | public override void When() 20 | { 21 | _result = Enumerable.ToList(_projManager.ListOneTimeAsync(_credentials).Result); 22 | } 23 | 24 | [Test] 25 | public void should_return_projections() 26 | { 27 | Assert.IsNotEmpty((IEnumerable) _result); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_updating_a_projection_query.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace EventStore.Core.Tests.ClientAPI 5 | { 6 | [TestFixture] 7 | [Category("ProjectionsManager")] 8 | public class when_updating_a_projection_query : ProjectionSpecification 9 | { 10 | private string _projectionName; 11 | private string _streamName; 12 | private string _newQuery; 13 | 14 | public override void Given() 15 | { 16 | _projectionName = "when_updating_a_projection_query"; 17 | _streamName = "test-stream-" + Guid.NewGuid().ToString(); 18 | 19 | PostEvent(_streamName, "testEvent", "{\"A\":\"1\"}"); 20 | PostEvent(_streamName, "testEvent", "{\"A\":\"2\"}"); 21 | 22 | var origQuery = CreateStandardQuery(_streamName); 23 | _newQuery = CreateStandardQuery("DifferentStream"); 24 | _projManager.CreateContinuousAsync(_projectionName, origQuery, _credentials).Wait(); 25 | } 26 | 27 | public override void When() 28 | { 29 | _projManager.UpdateQueryAsync(_projectionName, _newQuery, _credentials).Wait(); 30 | } 31 | 32 | [Test] 33 | public void should_update_the_projection_query() 34 | { 35 | var query = _projManager.GetQueryAsync(_projectionName, _credentials).Result; 36 | Assert.AreEqual(_newQuery, query); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /test/EventStore.ClientAPI.NetCore.Tests/when_working_with_metadata.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | using EventStore.ClientAPI.Common.Utils; 3 | using EventStore.Core.Tests.ClientAPI.Helpers; 4 | using NUnit.Framework; 5 | using ExpectedVersion = EventStore.ClientAPI.ExpectedVersion; 6 | 7 | namespace EventStore.Core.Tests.ClientAPI 8 | { 9 | [TestFixture, Category("LongRunning")] 10 | public class when_working_with_metadata 11 | { 12 | private IEventStoreConnection _connection; 13 | 14 | [OneTimeSetUp] 15 | public void OneTimeSetUp() 16 | { 17 | 18 | _connection = BuildConnection(); 19 | _connection.ConnectAsync().Wait(); 20 | } 21 | 22 | protected virtual IEventStoreConnection BuildConnection() 23 | { 24 | return TestConnection.Create(TcpType.Normal); 25 | } 26 | 27 | [OneTimeTearDown] 28 | public void OneTimeTearDown() 29 | { 30 | _connection.Close(); 31 | } 32 | 33 | [Test] 34 | public void when_getting_metadata_for_an_existing_stream_and_no_metadata_exists() 35 | { 36 | const string stream = "when_getting_metadata_for_an_existing_stream_and_no_metadata_exists"; 37 | 38 | _connection.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, TestEvent.NewTestEvent()).Wait(); 39 | 40 | var meta = _connection.GetStreamMetadataAsRawBytesAsync(stream).Result; 41 | Assert.AreEqual(stream, meta.Stream); 42 | Assert.AreEqual(false, meta.IsStreamDeleted); 43 | Assert.AreEqual(-1, meta.MetastreamVersion); 44 | Assert.AreEqual(Helper.UTF8NoBom.GetBytes(""), meta.StreamMetadata); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /wercker.yml: -------------------------------------------------------------------------------- 1 | box: ubuntu:16.04 2 | build: 3 | steps: 4 | - script: 5 | name: install dotnet core 6 | code: | 7 | apt-get update 8 | apt-get install apt-transport-https -y 9 | apt-get install curl 10 | curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg 11 | mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg 12 | sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list' 13 | apt-get update 14 | apt-get install dotnet-sdk-2.0.0 -y 15 | 16 | - script: 17 | name: install and run eventstore 18 | code: | 19 | apt-get install wget tzdata curl iproute2 -y 20 | wget https://eventstore.org/downloads/EventStore-OSS-Ubuntu-14.04-v4.1.0.tar.gz 21 | tar xfv EventStore-OSS-Ubuntu-14.04-v4.1.0.tar.gz 22 | pushd ./EventStore-OSS-Ubuntu-14.04-v4.1.0 23 | nohup ./eventstored --run-projections All --mem-db --log ~/logs & 24 | popd 25 | 26 | # Build 27 | - script: 28 | name: Build project 29 | code: | 30 | ./build.sh 31 | 32 | # Run tests 33 | - script: 34 | name: Run tests 35 | code: | 36 | dotnet restore 37 | dotnet test test/EventStore.ClientAPI.NetCore.Tests/EventStore.ClientAPI.NetCore.Tests.csproj --no-build --logger trx;LogFileName=~/TestResults.xml 38 | 39 | after-steps: 40 | - script: 41 | name: copy log files 42 | code: | 43 | echo "copying test results" 44 | cp ./test/EventStore.ClientAPI.NetCore.Tests/TestResults/*.trx $WERCKER_REPORT_ARTIFACTS_DIR 45 | echo "copying server logs" 46 | cp -R ~/logs $WERCKER_REPORT_ARTIFACTS_DIR 47 | # TODO: copy test output --------------------------------------------------------------------------------