Ejemplo n.º 1
0
        public async Task FindSagasAsync_ByClassId()
        {
            Guid saga1Id      = Guid.Parse("6B3577DF-B0F7-444A-8506-029591BC9894");
            Guid saga2Id      = Guid.Parse("75E24A6E-29BF-4863-AB6A-299EB107947D");
            Guid saga1ClassId = Guid.Parse("D3F5C4A9-DC44-49F7-B629-230852265B87");
            Guid saga2ClassId = Guid.Parse("B68CFFB0-5ECD-424B-B837-BCC4394F5465");

            var sagaMetadata1 = new SagaMetadataRecord(saga1Id, saga1ClassId);
            var sagaMetadata2 = new SagaMetadataRecord(saga2Id, saga2ClassId);

            inMemoryCrudRepository.AttachRange(new[]
            {
                sagaMetadata1, sagaMetadata2
            });

            SagaMatch[] result = await sut.FindSagasAsync(saga1ClassId);

            result.Should().BeEquivalentTo(new[]
            {
                new SagaMatch()
                {
                    Id = sagaMetadata1.Id, ClassId = sagaMetadata1.ClassId
                }
            });
        }
Ejemplo n.º 2
0
        public EventStoreTests()
        {
            inMemoryCrudRepository = Substitute.ForPartsOf <InMemoryCrudRepository>();

            eventStreams = new[]
            {
                new EventStream(Guid.NewGuid()),
                new EventStream(Guid.NewGuid()),
                new EventStream(Guid.NewGuid())
            };
            inMemoryCrudRepository.AttachRange(eventStreams);

            eventSerializer = Substitute.For <IEventSerializer>();

            eventSerializer.SerializeEvent(null)
            .ReturnsForAnyArgs(ci => ("{\"bar\":" + ci.ArgAt <Event1>(0).Foo + "}", new VersionedTypeId("EventName", 5)));
            eventSerializer.DeserializeEvent(Arg.Any <string>(), new VersionedTypeId("EventName", 5))
            .Returns(ci => new Event1((int)JObject.Parse(ci.ArgAt <string>(0))["bar"]));
            eventSerializer.SerializeEventMetadata(null)
            .ReturnsForAnyArgs(ci => JsonConvert.SerializeObject(ci.Arg <IReadOnlyDictionary <string, string> >()
                                                                 .Append(new KeyValuePair <string, string>("fakeSer", "true"))
                                                                 .ToDictionary(x => x.Key, x => x.Value)));
            eventSerializer.DeserializeEventMetadata(null)
            .ReturnsForAnyArgs(ci =>
            {
                var json          = JObject.Parse(ci.Arg <string>());
                json["fakeDeser"] = "true";
                return(new JsonMetadata(json));
            });

            FakeClock.Setup();

            eventStreamRows = new[]
            {
                new EventStreamRow(Guid.NewGuid(), "{\"bar\":1}", "EventName", 5, eventStreams[0].Id, 1, Clock.Current.Now, "{\"doh\":\"1\"}"),
                new EventStreamRow(Guid.NewGuid(), "{\"bar\":2}", "EventName", 5, eventStreams[0].Id, 2, Clock.Current.Now, "{\"doh\":\"2\"}"),
                new EventStreamRow(Guid.NewGuid(), "{\"bar\":3}", "EventName", 5, eventStreams[1].Id, 3, Clock.Current.Now, "{\"doh\":\"3\"}"),
                new EventStreamRow(Guid.NewGuid(), "{\"bar\":4}", "EventName", 5, eventStreams[1].Id, 2, Clock.Current.Now, "{\"doh\":\"4\"}"),
                new EventStreamRow(Guid.NewGuid(), "{\"bar\":5}", "EventName", 5, eventStreams[1].Id, 4, Clock.Current.Now, "{\"doh\":\"5\"}"),
                new EventStreamRow(Guid.NewGuid(), "{\"bar\":6}", "EventName", 5, eventStreams[1].Id, 5, Clock.Current.Now, "{\"doh\":\"6\"}")
            };

            expectedStoreRecords = eventStreamRows.Select((x, i) =>
                                                          new FakeEventStoreRecord()
            {
                Event = eventSerializer.DeserializeEvent(x.EventJson, new VersionedTypeId(x.EventName, x.EventVersion)),
                AdditionalMetadata = new Dictionary <string, string>()
                {
                    { "doh", (i + 1).ToString() }, { "fakeDeser", "true" }
                },
                EventId = eventStreamRows[i].Id,
                StreamSequenceNumber = eventStreamRows[i].StreamSequenceNumber
            })
                                   .ToArray();

            inMemoryCrudRepository.AttachRange(eventStreamRows);

            sut = new EventStore(inMemoryCrudRepository, eventSerializer);
        }
Ejemplo n.º 3
0
        public DbMessageLoaderTests()
        {
            inMemoryCrudRepository = new InMemoryCrudRepository();
            dbMessageCache         = Substitute.For <IDbMessageCache>();

            messages = new[]
            {
                new LocalizationMessage(Guid.NewGuid(), null, "hello", "ahoj", new Locale("cs-CZ"), null),
                new LocalizationMessage(Guid.NewGuid(), null, "coffee", "kafe", new Locale("cs-CZ"), null)
            };

            inMemoryCrudRepository.AttachRange(messages);

            sut = new DbMessageLoader(dbMessageCache, inMemoryCrudRepository);
        }