コード例 #1
0
        async public Task <IActionResult> Run(string roomId, FunctionCallViewModel fcall)
        {
            var normalisedRoomId = roomId.ToUpperInvariant();

            if (!RoomRepository.Exists(normalisedRoomId))
            {
                return(NotFound("Room not found"));
            }

            var room = RoomRepository.Get(normalisedRoomId);

            return(await RoomHelpers.WithRoomLock <IActionResult>(room, async() =>
            {
                if (room.Library == null)
                {
                    return base.BadRequest();
                }

                if (!room.Library.GetFunctionList().Any(f => f.Name == fcall.Name))
                {
                    return base.NotFound("Function not found");
                }

                var results = room.Library.Call(fcall.Name, fcall.Arguments);
                ResultGroup resultGroup = GroupResults(results);
                await ResultPublisher.Publish(room, resultGroup);
                return base.Ok();
            }));
        }
コード例 #2
0
        public void ResultAreCleanupUpAfterTwiceAGivenTime()
        {
            var result = new DomainResult(_mockTrackedMessage.Object, ResultCode.OK, string.Empty);

            _mockResultStore.Setup(x => x.Save(It.IsAny <DomainResult>())).Verifiable();
            _mockResultStore.Setup(x => x.Delete(_id.ToString()));
            _publisher = new ResultPublisher(_mockResultStore.Object, new TimeoutProvider(200));
            _publisher.Publish(result);
            Thread.Sleep(250);
            _mockResultStore.Verify(x => x.Delete(_trackingId.ToString()), Times.Exactly(0));
            Thread.Sleep(200);
            _mockResultStore.Verify(x => x.Delete(_trackingId.ToString()), Times.Exactly(1));
        }
コード例 #3
0
        public void ResultCanBePublished()
        {
            var result = new DomainResult(_mockTrackedMessage.Object, ResultCode.OK, string.Empty);

            _mockResultStore.Setup(x => x.Save(It.IsAny <DomainResult>())).Verifiable();
            _publisher = new ResultPublisher(_mockResultStore.Object, new TimeoutProvider(200));
            _publisher.Publish(result);

            Assert.AreEqual(ResultCode.OK, result.ResultCode);
            Assert.AreEqual(_id.ToString(), result.Id);
            Assert.AreEqual(string.Empty, result.ResultMessage);
            _mockResultStore.Verify();
            _mockResultStore.Verify(x => x.Delete(_id.ToString()), Times.Never);
        }
コード例 #4
0
        public void ResultCanBeUpdated()
        {
            var intercepted = new List <DomainResult>();
            var result      = new DomainResult(_mockTrackedMessage.Object, ResultCode.Unknown, string.Empty);

            _mockResultStore.Setup(x => x.Save(It.IsAny <DomainResult>())).Callback <DomainResult>(x => intercepted.Add(x));
            _publisher = new ResultPublisher(_mockResultStore.Object, new TimeoutProvider(200));
            _publisher.Publish(result);
            result = new DomainResult(_mockTrackedMessage.Object, ResultCode.OK, "finished");
            _publisher.Publish(result);
            Assert.AreEqual(2, intercepted.Count);
            Assert.AreEqual(intercepted[0].Id, intercepted[1].Id);
            Assert.AreEqual(intercepted[0].TrackingId, intercepted[1].TrackingId);
            Assert.AreEqual(intercepted[0].ResultCode, ResultCode.Unknown);
            Assert.AreEqual(intercepted[1].ResultCode, ResultCode.OK);
            Assert.AreEqual(string.Empty, intercepted[0].ResultMessage);
            Assert.AreEqual("finished", intercepted[1].ResultMessage);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: decarufe/CqrsDemo
        private static MessagingBus SetupBus(OrderView orderView)
        {
            IPersistanceStore persitenceStore  = new MemoryPersistance();
            IDomainEventQuery domainEventQuery = new InProcPersistedDomainEventQuery(persitenceStore);
            IDomainEventStore domainEventStore = new PyxisDomainEventStore(
                persitenceStore,
                domainEventQuery);
            IDomainResultStoreQuery storeQuery  = new InProcDomainResultStoreQuery(persitenceStore);
            IDomainResultStore      resultStore = new DomainResultPersistanceStore(
                persitenceStore,
                storeQuery);
            ITimeoutProvider timeoutProvider = new TimeoutProvider(1000);
            IResultPublisher resultPublisher = new ResultPublisher(
                resultStore,
                timeoutProvider);
            IResultAwaiter resultAwaiter = new ResultAwaiter(
                resultStore,
                timeoutProvider);
            IList <IHandleCommand>        commandHanlders   = new List <IHandleCommand>();
            IList <IHandleEvent>          eventHandlers     = new List <IHandleEvent>();
            IMessageDispatcher <ICommand> commandDispatcher = new CqrsMessagingHandler(
                resultPublisher,
                commandHanlders,
                eventHandlers);
            ICommandQueue commandQueue = new InProcCommandQueue(commandDispatcher);
            MessagingBus  bus          = new MessagingBus(
                commandQueue,
                resultPublisher,
                resultAwaiter);
            IDomainRepository domainRepository = new DomainRepository(
                domainEventStore,
                bus);
            ISession session = new Session(domainRepository);

            commandHanlders.Add(new OrderCommandHandler(session));
            eventHandlers.Add(new OrderEventHandler(orderView));

            return(bus);
        }