コード例 #1
0
        public async Task PlayCardCommandHandler_ThrowsException_WhenSymbolNotFound()
        {
            // Given
            var command = new PlayCardCommand(this._session.UrlId.StringId, (await this.Context.UserStories.FirstAsync()).Id, -1);
            var handler = new PlayCardCommandHandler(Substitute.For <IMediator>(), this.Context, Substitute.For <ICurrentParticipantService>(), Substitute.For <IMapper>());

            // When
            TestDelegate action = () => handler.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            // Then
            Assert.That(action, Throws.InstanceOf <NotFoundException>());
        }
コード例 #2
0
        public async Task PlayCardCommandHandler_ThrowsException_ForEstimationInWrongSymbolSet()
        {
            // Given
            var mediator = Substitute.For <IMediator>();
            var currentParticipantService = Substitute.For <ICurrentParticipantService>();

            currentParticipantService.GetParticipant().
            Returns(new ValueTask <CurrentParticipantModel>(
                        new CurrentParticipantModel(this._participantId, null, null, false)
                        ));

            Symbol symbol = this.Context.Symbols.Add(new Symbol {
                Type          = SymbolType.Number,
                ValueAsNumber = 1,
                SymbolSet     = new SymbolSet {
                    Name = "wrong "
                }
            }).Entity;

            await this.Context.SaveChangesAsync();

            var command = new PlayCardCommand(
                this._session.UrlId.StringId,
                (await this.Context.UserStories.FirstAsync()).Id,
                symbol.Id
                );

            var handler = new PlayCardCommandHandler(mediator,
                                                     this.Context,
                                                     currentParticipantService,
                                                     Substitute.For <IMapper>());

            // When
            TestDelegate action = () => handler.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            // Then
            Assert.That(action, Throws.InstanceOf <InvalidOperationException>());
        }
コード例 #3
0
        public async Task PlayCardCommandHandler_AddsEstimationAndBroadcast_ForNewEstimation()
        {
            // Given
            var mediator = Substitute.For <IMediator>();
            var currentParticipantService = Substitute.For <ICurrentParticipantService>();

            currentParticipantService.GetParticipant().
            Returns(new ValueTask <CurrentParticipantModel>(
                        new CurrentParticipantModel(this._participantId, null, null, false)
                        ));

            var command = new PlayCardCommand(
                this._session.UrlId.StringId,
                (await this.Context.UserStories.FirstAsync()).Id,
                (await this.Context.Symbols.Where(x => x.SymbolSetId == this._session.SymbolSetId).FirstAsync()).Id
                );
            var handler = new PlayCardCommandHandler(mediator,
                                                     this.Context,
                                                     currentParticipantService,
                                                     Substitute.For <IMapper>());

            // When
            await handler.Handle(command, CancellationToken.None);

            // Then
            await currentParticipantService.ReceivedWithAnyArgs(Quantity.Exactly(1))
            .GetParticipant();

            UserStory checkUserStory = await this.Context.UserStories.
                                       Include(x => x.Estimations).
                                       LastOrDefaultAsync();

            Assert.That(checkUserStory.Estimations.Select(x => x.Symbol.Id), Is.EquivalentTo(new[] { command.SymbolId }));

            await mediator.Received().
            Publish(Arg.Any <EstimationGivenNotification>(), Arg.Any <CancellationToken>());
        }