Пример #1
0
 public ProductService() : base(cfg =>
 {
     cfg.CreateMap <Product, ProductDto>();
     cfg.CreateMap <ProductDto, Product>();
 })
 {
     _onAddProduct = new EventObservable <ProductDto>();
 }
        public EventObservable GetObservable(string name)
        {
            Span <int> hashCodes  = stackalloc[] { name.GetHashCode() };
            var        hashTypeId = Atma.HashCode.Hash(hashCodes);

            if (!_observables.TryGetValue(hashTypeId, out var it))
            {
                it = new EventObservable(name);
                _observables.Add(hashTypeId, it);
            }
            return((EventObservable)it);
        }
    }
Пример #3
0
        public void CanMergeEventStreams()
        {
            var        subject1 = new EventSubject <int, IEventContext, TestModel>(_eventObservationRegistrar);
            var        subject2 = new EventSubject <int, IEventContext, TestModel>(_eventObservationRegistrar);
            var        stream   = EventObservable.Merge(subject1, subject2);
            List <int> received = new List <int>();

            stream.Observe((e, c, m) => received.Add(e));
            subject1.OnNext(1, _eventContext, _model);
            subject2.OnNext(2, _eventContext, _model);
            subject1.OnNext(3, _eventContext, _model);
            subject2.OnNext(4, _eventContext, _model);
            Assert.IsTrue(received.SequenceEqual(new[] { 1, 2, 3, 4 }));
        }
        public EventEmitterFixture()
        {
            fixture = InlineServicesAttribute.CreateFixture();
            var container = fixture.Create <Container>();

            emitter = container.CreateEventEmitter(
                "test-event-emitter",
                container.GetInstance <IConfiguration>()["mongo:url"],
                new[] { "test.entities" });

            observable = new EventObservable();
            consumer   = new EventObserverConsumer(
                "test-event-observer",
                fixture.Create <IMongoDatabase>(),
                fixture.Create <ILogger>(),
                observable);
        }
Пример #5
0
        protected AutomatonymousStateMachine()
        {
            _registrations = new Lazy <StateMachineRegistration[]>(GetRegistrations);
            _stateCache    = new Dictionary <string, State <TInstance> >();
            _eventCache    = new Dictionary <string, StateMachineEvent <TInstance> >();

            _eventObservers = new EventObservable <TInstance>();
            _stateObservers = new StateObservable <TInstance>();

            _initial = new StateMachineState <TInstance>(this, "Initial", _eventObservers);
            _stateCache[_initial.Name] = _initial;
            _final = new StateMachineState <TInstance>(this, "Final", _eventObservers);
            _stateCache[_final.Name] = _final;

            _accessor = new DefaultInstanceStateAccessor <TInstance>(this, _stateCache[Initial.Name], _stateObservers);

            _unhandledEventCallback = DefaultUnhandledEventCallback;

            _name = GetType().Name;

            RegisterImplicit();
        }
Пример #6
0
        public void CanHoldByBaseEvent()
        {
            List <BaseEvent> receivedBarEvents = new List <BaseEvent>();
            IEventObservable <BaseEvent, IEventContext, TestModel> fooEventStream = _router.GetEventObservable(_model.Id, new HoldBaseEventsBasedOnModelStrategy <FooEvent, BaseEvent>());
            IEventObservable <BaseEvent, IEventContext, TestModel> barEventStream = _router.GetEventObservable(_model.Id, new HoldBaseEventsBasedOnModelStrategy <BarEvent, BaseEvent>());
            var stream = EventObservable.Merge(fooEventStream, barEventStream);

            stream.Observe((baseEvent, context, model) =>
            {
                receivedBarEvents.Add(baseEvent);
            });
            var event1 = new FooEvent("EventPayload1");
            var event2 = new BarEvent("EventPayload2");

            _router.PublishEvent(_model.Id, event1);
            _router.PublishEvent(_model.Id, event2);
            ReleasedEvent(event1.Id, HeldEventAction.Release);
            ReleasedEvent(event2.Id, HeldEventAction.Release);
            receivedBarEvents.Count.ShouldBe(2);
            receivedBarEvents[0].ShouldBeAssignableTo <FooEvent>();
            receivedBarEvents[1].ShouldBeAssignableTo <BarEvent>();
        }