public async Task <IActionResult> Create([FromBody] CreateAuctionViewModel viewModel)
        {
            var command = new CreateAuctionCommand(viewModel.Name, viewModel.AuctionDate);
            var result  = await _commandBus.ExecuteAsync <CreateAuctionCommand, AuctionId>(command);

            return(CreatedAtRoute("GetAuctionById", new { id = result.Result.ToString() }, null));
        }
        public async Task <IActionResult> AddItem([FromRoute] string auctionId,
                                                  [FromBody] AddAuctionItemViewModel viewModel)
        {
            var id      = IdentityBase.FromExistingId <AuctionId>(auctionId);
            var item    = new AuctionItem(viewModel.Name, viewModel.Donor, viewModel.Description, viewModel.Quantity);
            var command = new AddAuctionItemCommand(id, item);
            await _commandBus.ExecuteAsync(command);

            return(CreatedAtRoute("GetAuctionItems", new { auctionId }, null));
        }
示例#3
0
        public void ExecuteAsyncTest()
        {
            var bus = new CommandBus(ServiceFactory.CreateContainer(null
                                                                    , f => f.Mock <SimpleCommand>((context, command) => command.ResultValue = command.Value * 2)));

            Assert.Equal(10, bus.ExecuteAsync(new SimpleCommand()
            {
                Value = 5
            }).Result.ResultValue);
            Assert.Equal(0, bus.ExecuteAsync(new SimpleCommand()
            {
                Value = 5
            }, (context, command) => false).Result.ResultValue);
        }
示例#4
0
        public async Task 本を破棄する()
        {
            var item = 本の状況Query.All().First();

            if (item.貸し出しされている)
            {
                Context.Logger.LogInformation("貸し出しされているため、本を破棄できません。");
                return;
            }

            await CommandBus.ExecuteAsync(本を破棄するCommand.Create(item.本のID, item.本のEventNumber));
        }
示例#5
0
        public async Task 発送する()
        {
            var list = 発送本DTOQuery.未発送一覧();

            if (list.Any() == false)
            {
                Context.Logger.LogInformation("未発送な本はありません。");
            }

            var item  = list.First();
            var _発送期間 = 発送期間.デフォルト期間(DateTime.UtcNow);

            await CommandBus.ExecuteAsync(本を発送するCommand.Create(item.本のID, _発送期間));
        }
示例#6
0
 public async void ExecuteAsyncExceptionTest()
 {
     var bus = new CommandBus(ServiceFactory.CreateContainer(null
                                                             , f => f.Mock <SimpleCommand>((context, command) =>
     {
         throw new NotSupportedException();
     })));
     await Assert.ThrowsAsync <NotSupportedException>(() => bus.ExecuteAsync(new SimpleCommand()
     {
         Value = 5
     }, null, (context, command, exception) =>
     {
         Assert.IsType <NotSupportedException>((exception as AggregateException).InnerException);
     }));
 }
示例#7
0
        public async Task 本を借りる()
        {
            var ログイン情報 = ログイン情報Query.First();

            try
            {
                var item = 本の状況Query.借りてない本().First();

                var _貸出期間 = 貸出期間.デフォルト期間(DateTime.UtcNow);
                await CommandBus.ExecuteAsync(本を借りるCommand.Create(ログイン情報.ID, ログイン情報.EventNumber, item.本のID, item.本のEventNumber, _貸出期間));
            }
            catch (System.Exception ex)
            {
                Context.Logger.LogInformation("全て貸しています。 :" + ex.Message);
            }
        }
示例#8
0
        public async Task 本を延長する()
        {
            var ログイン情報 = ログイン情報Query.First();

            try
            {
                var item = 本の状況Query.借りてる本(ログイン情報.ID).First();

                var _貸出期間 = item.貸出期間.延長(TimeSpan.FromDays(14));

                await CommandBus.ExecuteAsync(本を延長するCommand.Create(item.本のID, item.本のEventNumber, _貸出期間));
            }
            catch (System.Exception)
            {
                Context.Logger.LogInformation("借りている本がありません。");
            }
        }
示例#9
0
        public async Task 初期値入力()
        {
            await CommandBus.ExecuteAsync(利用者を登録するCommand.Create("田中", "太郎"));

            await CommandBus.ExecuteAsync(利用者を登録するCommand.Create("山田", "花子"));

            var prop = MessageBroker.ToObservable <I本が登録されたEvent>().ToReadOnlyReactivePropertySlim(null);

            await CommandBus.ExecuteAsync(本を登録するCommand.Create(タイトル.Create(".NETのエンタープライズアプリケーションアーキテクチャ 第2版"), ISBN.Create("9784822298487")));

            if (prop.Value == null)
            {
                await prop;
            }

            await CommandBus.ExecuteAsync(本を登録する2Command.Create(prop.Value.書籍のID));
        }
示例#10
0
        public void ExecuteAsyncExceptionTest()
        {
            var bus = new CommandBus(ServiceFactory.CreateContainer(null
                                                                    , f => f.Mock <SimpleCommand>((context, command) =>
            {
                throw new NotSupportedException();
            })));
            Exception catchException = null;

            Assert.Throws <AggregateException>(() => bus.ExecuteAsync(new SimpleCommand()
            {
                Value = 5
            }, null, (context, command, exception) =>
            {
                catchException = exception;
            }).Result);
            Assert.IsType <NotSupportedException>(catchException);
        }
示例#11
0
        public async Task 本を返す()
        {
            var ログイン情報 = ログイン情報Query.First();

            try
            {
                var item = 本の状況Query.借りてる本(ログイン情報.ID).First();

                await CommandBus.ExecuteAsync(本を返すCommand.Create(ログイン情報.ID, ログイン情報.EventNumber, item.本のID, item.本のEventNumber));
            }
            catch (EventStore.ClientAPI.Exceptions.ServerErrorException ex)
            {
                Context.Logger.LogError(nameof(EventStore.ClientAPI.Exceptions.ServerErrorException) + ex.Message);
            }
            catch (System.Exception ex)
            {
                Context.Logger.LogInformation("借りている本がありません。" + ex.Message);
            }
        }
示例#12
0
        public async Task Execute_HasTransactionAttributeAndOnError_RollbackTransaction()
        {
            _commandHandlerProviderMock
            .Setup(x => x.GetAsyncCommandHandler <BlankSimpleTestCommand, CommandResult>())
            .Returns(new AsyncCommandHandlerWrapper <BlankSimpleTestCommand, CommandResult>(new CommandHandlerWithTransactionAttribute()));

            _commandHandlerProviderMock
            .Setup(x => x.GetCommandHandler <BlankSimpleTestCommand, CommandResult>())
            .Returns(new CommandHandlerWithTransactionAttribute());

            _prerequisitesCheckerMock
            .Setup(x => x.Check(It.IsAny <BlankSimpleTestCommand>()))
            .Throws(new Exception("Test Exception"));

            try
            {
                await _bus.ExecuteAsync(new BlankSimpleTestCommand(), CancellationToken.None);
            }
            catch (Exception)
            {
            }
            _dbSessionManagerMock.Verify(x => x.RollbackTransaction());
        }