public StreamStoreConnectionFixture()
        {
            AdminCredentials = new UserCredentials("admin", "changeit");
#if LIVE_ES_CONNECTION
            //Connection = new EventStoreConnectionWrapper(
            //                  EventStoreConnection.Create("ConnectTo=tcp://admin:changeit@localhost:1113; HeartBeatTimeout=500"));
            string esUser      = "******";
            string esPwd       = "changeit";
            var    creds       = new ES.SystemData.UserCredentials(esUser, esPwd);
            string esIpAddress = "127.0.0.1";
            int    esPort      = 1113;
            var    tcpEndpoint = new IPEndPoint(IPAddress.Parse(esIpAddress), esPort);

            var settings = ES.ConnectionSettings.Create()
                           .SetDefaultUserCredentials(creds)
                           .KeepReconnecting()
                           .KeepRetrying()
                           .UseConsoleLogger()
                           .DisableTls()
                           .DisableServerCertificateValidation()
                           .WithConnectionTimeoutOf(TimeSpan.FromSeconds(15))
                           .Build();
            Connection = new EventStoreConnectionWrapper(ES.EventStoreConnection.Create(settings, tcpEndpoint, Guid.NewGuid().ToString()));
            Connection.Connect();
#else
            Connection = new ReactiveDomain.Testing.EventStore.MockStreamStoreConnection("Test Fixture");
            Connection.Connect();
#endif
        }
Beispiel #2
0
        public EventStoreFixture()
        {
            _node = EmbeddedVNodeBuilder
                    .AsSingleNode()
                    .OnDefaultEndpoints()
                    .RunInMemory()
                    .DisableDnsDiscovery()
                    .DisableHTTPCaching()
                    //.DisableScavengeMerging()
                    .DoNotVerifyDbHashes()
                    .Build();

            _node.StartAndWaitUntilReady().Wait();

            var conns = ConnectionSettings.Create()
                        .SetDefaultUserCredentials(new EventStore.ClientAPI.SystemData.UserCredentials("admin", "changeit"))
                        .Build();

            var eventStoreConnection = EmbeddedEventStoreConnection.Create(_node, conns);

            StreamStoreConnection = new EventStoreConnectionWrapper(eventStoreConnection);

            EventSerializer   = new JsonMessageSerializer();
            StreamNameBuilder = new PrefixedCamelCaseStreamNameBuilder("masterdata");

            _repo = new StreamStoreRepository(StreamNameBuilder, StreamStoreConnection, EventSerializer);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            IEventStoreConnection conn = EventStoreConnection.Create("ConnectTo=tcp://admin:changeit@localhost:1113");

            conn.Connected += (_, __) => Console.WriteLine("Connected");
            conn.ConnectAsync().Wait();

            conn.AppendToStreamAsync("Test", ExpectedVersion.Any, new[] {
                new EventData(
                    Guid.NewGuid(),
                    "TestEvent",
                    false,
                    Encoding.UTF8.GetBytes("Test event data"),
                    Encoding.UTF8.GetBytes("Test event Metadata"))
            });

            Console.WriteLine("Event Written");

            var evt = conn.ReadStreamEventsForwardAsync("Test", StreamPosition.Start, 1, false).Result;

            Console.WriteLine(Encoding.UTF8.GetString(evt.Events[0].Event.Data));
            Console.ReadKey();
            return;

            IStreamStoreConnection streamConn  = new EventStoreConnectionWrapper(conn);
            IStreamNameBuilder     nameBuilder = new PrefixedCamelCaseStreamNameBuilder();
            IEventSerializer       serializer  = new JsonMessageSerializer();
            IRepository            repo        = new StreamStoreRepository(nameBuilder, streamConn, serializer);

            repo.Save(new Account(Guid.NewGuid()));

            IListener myListener = new StreamListener("Account Listener", streamConn, nameBuilder, serializer);
        }
Beispiel #4
0
        public static DomainEntry CreateDomainEntry()
        {
            var connection       = EventStoreConnectionWrapper.Connect();
            var domainRepository = new EventStoreDomainRepository(connection);
            var domainEntry      = new DomainEntry(domainRepository);

            return(domainEntry);
        }
Beispiel #5
0
 private void ConnectToEventstore()
 {
     _latestPosition        = Position.Start;
     _connection            = EventStoreConnectionWrapper.Connect();
     _connection.Connected +=
         (sender, args) => _connection.SubscribeToAllFrom(_latestPosition, false, HandleEvent);
     Console.WriteLine("Indexing service started");
 }
Beispiel #6
0
        public async Task GetConnectionAsync_should_return_connection()
        {
            var connStr = new Uri(_fixture.ConnectionString);
            var logger  = NSubstitute.Substitute.For <ILogger <EventStoreConnectionWrapper> >();

            using var sut = new EventStoreConnectionWrapper(connStr, logger);

            var conn = await sut.GetConnectionAsync();

            conn.Should().NotBeNull();
        }
        public async Task RehydrateAsync_should_return_null_when_id_invalid()
        {
            var connStr = new Uri(_fixture.ConnectionString);
            var logger  = NSubstitute.Substitute.For <ILogger <EventStoreConnectionWrapper> >();

            using var conn = new EventStoreConnectionWrapper(connStr, logger);

            var serializer = NSubstitute.Substitute.For <IEventSerializer>();

            var sut = new EventsRepository <DummyAggregate, Guid>(conn, serializer);

            var rehydrated = await sut.RehydrateAsync(Guid.NewGuid());

            rehydrated.Should().BeNull();
        }
Beispiel #8
0
        public AccountService()
        {
            IEventStoreConnection esConnection = EventStoreConnection.Create("ConnectTo=tcp://admin:changeit@localhost:1113");
            var conn = new EventStoreConnectionWrapper(esConnection);

            esConnection.Connected += (_, __) => { };
            //Console.WriteLine("Connected");
            esConnection.ConnectAsync().Wait();
            IStreamNameBuilder namer = new PrefixedCamelCaseStreamNameBuilder();
            IEventSerializer   ser   = new JsonMessageSerializer();

            _repo       = new StreamStoreRepository(namer, conn, ser);
            _cmdHandler = new AccountCommandHandler(_repo);

            var listener = new StreamListener("AccountAggregate", conn, namer, ser);

            _readModel = new BalanceReadModel(() => listener);
        }
Beispiel #9
0
        protected AccountTestsBase()
        {
            AccountId = Guid.NewGuid();
            IEventStoreConnection esConnection = EventStoreConnection.Create("ConnectTo=tcp://admin:changeit@localhost:1113");
            var conn = new EventStoreConnectionWrapper(esConnection);

            esConnection.Connected += (_, __) => { };
            esConnection.ConnectAsync().Wait();
            IStreamNameBuilder namer = new PrefixedCamelCaseStreamNameBuilder("Tests");
            IEventSerializer   ser   = new JsonMessageSerializer();

            Repo       = new StreamStoreRepository(namer, conn, ser);
            CmdHandler = new AccountCommandHandler(Repo);

            var listener = new StreamListener("AccountAggregate", conn, namer, ser);

            ReadModel = new BalanceReadModel(() => listener);
        }
Beispiel #10
0
        public StreamStoreConnectionFixture()
        {
            AdminCredentials = new UserCredentials("admin", "changeit");
#if LIVE_ES_CONNECTION
            Connection = new EventStoreConnectionWrapper(
                EventStoreConnection.Create("ConnectTo=tcp://admin:changeit@localhost:1113; HeartBeatTimeout=500"));

            return;
#endif

#if NETCOREAPP2_0 || NETSTANDARD2_0 || NET452
            Connection = new ReactiveDomain.Testing.EventStore.MockStreamStoreConnection("Test Fixture");
            Connection.Connect();
#else
            var node = EmbeddedVNodeBuilder
                       .AsSingleNode()
                       .OnDefaultEndpoints()
                       .RunInMemory()
                       .DisableDnsDiscovery()
                       .DisableHTTPCaching()
                       //.DisableScavengeMerging()
                       .DoNotVerifyDbHashes()
                       .RunProjections(ProjectionType.System)
                       .StartStandardProjections()
                       .Build();

            node.StartAndWaitUntilReady().Wait();
            Connection = new EventStoreConnectionWrapper(EmbeddedEventStoreConnection.Create(node));

            _node = new Disposer(() => {
                if (!node.Stop(TimeToStop, true, true))
                {
                    Trace.WriteLine(
                        $"Failed to gracefully shut down the embedded Eventstore within {TimeToStop.TotalMilliseconds}ms.");
                }
                return(Unit.Default);
            });
#endif
        }
        public async Task AppendAsync_should_store_events()
        {
            var connStr = new Uri(_fixture.ConnectionString);
            var logger  = NSubstitute.Substitute.For <ILogger <EventStoreConnectionWrapper> >();

            using var conn = new EventStoreConnectionWrapper(connStr, logger);

            var serializer = NSubstitute.Substitute.For <IEventSerializer>();

            var sut = new EventsRepository <DummyAggregate, Guid>(conn, serializer);

            var aggregate = new DummyAggregate(Guid.NewGuid());

            aggregate.DoSomething("foo");
            aggregate.DoSomething("bar");

            await sut.AppendAsync(aggregate);

            var rehydrated = await sut.RehydrateAsync(aggregate.Id);

            rehydrated.Should().NotBeNull();
            rehydrated.Version.Should().Be(3);
        }