Beispiel #1
0
        public async Task ShouldAddBetIfBetExists()
        {
            //arrange
            var memberId = Guid.NewGuid();
            var betId    = Guid.NewGuid();
            var member   = new Member(new(memberId), "toto", 0);
            var bet      = Bet.Domain.Bets.Bet.Create(new BetId(betId),
                                                      new DateTime(2022, 2, 3),
                                                      "desc1", 10, member, new DateTime(2021, 3, 2));
            var betRepository      = new InMemoryBetRepository(null, bet.State);
            var queryBetRepository = new InMemoryBetQueryRepository(new List <BetDto>());
            var command            = new InsertBetQuerySideNotification(betId, memberId);
            var handler            = new InsertBetQuerySideNotificationHandler(betRepository, queryBetRepository);

            //act
            await handler.Handle(command, default);

            //assert
            BetDto betInserted = await queryBetRepository.GetByIdAsync(betId);

            Assert.NotNull(betInserted);
            Assert.Equal(bet.State.Coins, betInserted.Coins);
            Assert.Equal(bet.State.Description, betInserted.Description);
            Assert.Equal(bet.State.EndDate, betInserted.EndDate);
            Assert.Equal(bet.State.BetId, betInserted.Id);
            Assert.Equal(bet.State.Creator.Id.Value, betInserted.Creator.Id);
        }
Beispiel #2
0
        public async Task ShouldThrowBetUnknownExceptionIfBetIdUnknown()
        {
            //arrange
            var betId    = Guid.NewGuid();
            var memberId = Guid.NewGuid();
            var member   = new Member(new(memberId), "toto", 0);
            var bet      = Bet.Domain.Bets.Bet.Create(new BetId(Guid.NewGuid()),
                                                      new DateTime(2022, 2, 3),
                                                      "desc1", 10, member, new DateTime(2021, 3, 2));
            var betRepository      = new InMemoryBetRepository(null, bet.State);
            var queryBetRepository = new InMemoryBetQueryRepository(new List <BetDto>());
            var command            = new InsertBetQuerySideNotification(betId, memberId);
            var handler            = new InsertBetQuerySideNotificationHandler(betRepository, queryBetRepository);

            //act
            var record = await Record.ExceptionAsync(() => handler.Handle(command, default));

            //assert
            Assert.IsType <BetUnknownException>(record);
        }
        public async Task ShouldReturnBet()
        {
            var betId = Guid.NewGuid();
            var bets  = new List <BetDto>()
            {
                new BetDto(new(betId,
                               new(new(Guid.NewGuid()), "username", 300),
                               new DateTime(2021, 10, 10),
                               "description",
                               20,
                               new DateTime(2021, 3, 3), null, null, null))
            };
            var betQueryRepository = new InMemoryBetQueryRepository(bets);
            var handler            = new RetrieveBetQueryHandler(betQueryRepository);
            var query = new RetrieveBetQuery(betId);

            var betDto = await handler.Handle(query, default);

            Assert.Equal("description", betDto.Description);
            Assert.Equal(20, betDto.Coins);
            Assert.Equal(new DateTime(2021, 10, 10), betDto.EndDate);
            Assert.Equal(betId, betDto.Id);
        }