コード例 #1
0
        public void Test_EventsAreCreated_When_MultipleInputsAreProvided()
        {
            var input = new[] { new[] { 3, 3, 3, 750 }, new[] { 2, 2, 1, 1000 } };

            var events = EventEnricher.GetEnrichedEvents(input);

            Assert.AreEqual(events.Count, 2);
        }
コード例 #2
0
        public void Test_NoEventIsCreated_When_PerilAndRegionValuesAreNotInTheEnum()
        {
            var input = new[] { new[] { 3, 4, 4, 750 } };

            var events = EventEnricher.GetEnrichedEvents(input);

            Assert.AreEqual(events.Count, 0);
        }
コード例 #3
0
        public void Test_NoEventIsCreated_When_InputIsGreaterThan4()
        {
            var input = new[] { new[] { 3, 3, 3, 750, 88 } };

            var events = EventEnricher.GetEnrichedEvents(input);

            Assert.AreEqual(events.Count, 0);
        }
コード例 #4
0
        public void Test_EventIsCreated_When_InputIsAsExpectedForAnEvent()
        {
            var input = new[] { new[] { 3, 3, 3, 750 } };

            var events = EventEnricher.GetEnrichedEvents(input);

            Assert.AreEqual(events.Count, 1);
            var e = events.FirstOrDefault();

            Assert.AreEqual(e.Id, 3);
            Assert.AreEqual(e.Peril, Peril.Flood);
            Assert.AreEqual(e.Region, Region.Florida);
            Assert.AreEqual(e.EventLoss, 750);
        }
コード例 #5
0
        public static void Main(string[] args)
        {
            var events = EventEnricher.GetEnrichedEvents(Data.Events);
            var deals  = DealLoader.GetDeals();


            deals.ForEach(d => Console.WriteLine(d));
            Console.WriteLine();
            Console.WriteLine();
            events.ForEach(d => Console.WriteLine(d));

            Evaluator.Instance.EvaluateLoss(deals, events);

            Console.WriteLine();
            Console.WriteLine();

            events.OrderBy(e => e.Id);
            events.ForEach(o => Console.WriteLine(o.PrintReinsuranceTotalLoss()));

            Console.ReadLine();
        }
コード例 #6
0
        public void Test_NoEventIsCreated_When_InputIsEmptyArray()
        {
            var events = EventEnricher.GetEnrichedEvents(new int[0][]);

            Assert.AreEqual(events.Count, 0);
        }
コード例 #7
0
        public void Test_NoEventIsCreated_When_InputIsNUll()
        {
            var events = EventEnricher.GetEnrichedEvents(null);

            Assert.AreEqual(events.Count, 0);
        }
コード例 #8
0
        public EventEnricherTests()
        {
            var cache = new MemoryCache(Options.Create(new MemoryCacheOptions()));

            sut = new EventEnricher(cache, userResolver);
        }
コード例 #9
0
        public static IEventHandlerBuilder <IRoadRegistryContext, TCommand> UseRoadRegistryContext <TCommand>(
            this IEventHandlerBuilder <TCommand> builder, IStreamStore store, IRoadNetworkSnapshotReader snapshotReader, EventEnricher enricher)
        {
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }
            if (enricher == null)
            {
                throw new ArgumentNullException(nameof(enricher));
            }
            return(builder.Pipe <IRoadRegistryContext>(next => async(message, ct) =>
            {
                var map = new EventSourcedEntityMap();
                var context = new RoadRegistryContext(map, store, snapshotReader, SerializerSettings, EventMapping);

                await next(context, message, ct);

                foreach (var entry in map.Entries)
                {
                    var events = entry.Entity.TakeEvents();
                    if (events.Length != 0)
                    {
                        var messageId = message.MessageId.ToString("N");
                        var version = entry.ExpectedVersion;
                        Array.ForEach(events, @event => enricher(@event));
                        var messages = Array.ConvertAll(
                            events,
                            @event =>
                            new NewStreamMessage(
                                Deterministic.Create(Deterministic.Namespaces.Events,
                                                     $"{messageId}-{version++}"),
                                EventMapping.GetEventName(@event.GetType()),
                                JsonConvert.SerializeObject(@event, SerializerSettings)
                                ));
                        await store.AppendToStream(entry.Stream, entry.ExpectedVersion, messages, ct);
                    }
                }
            }
                                                       ));
        }