Exemplo n.º 1
0
        public async Task Handle_Success(ParticipantStatus status, NotificationType expectedNotificationType, string expectedMessage)
        {
            // Arrange
            var notification = new ParticipationChangedEvent(
                validParticipantId,
                validEventId,
                validDiverId,
                ParticipantStatus.Accepted);

            A.CallTo(() => participantRepository.GetParticipantByIdAsync(A <Guid> ._))
            .ReturnsLazily(call => Task.FromResult(
                               (Guid)call.Arguments[0] == validParticipantId
                        ? new Participant
            {
                Id      = validParticipantId,
                EventId = validEventId,
                ParticipatingDiverId = validDiverId,
                Status        = status,
                CountPeople   = 1,
                BuddyTeamName = "team1"
            }
                        : null
                               ));

            var recordedMessage = "";

            A.CallTo(() => notificationPublisher.PublishAsync(
                         expectedNotificationType,
                         A <string> .That.Matches(m =>
                                                  !string.IsNullOrWhiteSpace(m)),
                         A <IEnumerable <Diver> > .That.Matches(l => l.Count() == 2),
                         A <Diver> ._,
                         validEventId,
                         null)).Invokes(call => recordedMessage = (string)call.Arguments[1]);

            // Act
            await policy.Handle(notification, CancellationToken.None);

            // Assert
            A.CallTo(() => notificationPublisher.PublishAsync(
                         expectedNotificationType,
                         A <string> .That.Matches(m =>
                                                  !string.IsNullOrWhiteSpace(m)),
                         A <IEnumerable <Diver> > .That.Matches(l => l.Count() == 2),
                         A <Diver> ._,
                         validEventId,
                         null))
            .MustHaveHappenedOnceExactly();
            recordedMessage.Should().Be(expectedMessage);
        }
Exemplo n.º 2
0
        public void Handle_ParticipantNotFound()
        {
            // Arrange
            var notification = new ParticipationChangedEvent(
                new Guid("0F5C1EE0-7EE9-43CC-B2DA-4B19568A1A3F"),
                validEventId,
                validDiverId,
                ParticipantStatus.Accepted);

            // Act
            Func <Task> act = () => policy.Handle(notification, CancellationToken.None);

            // Assert
            act.Should().Throw <InvalidOperationException>().WithMessage("Participant not found!");
        }
Exemplo n.º 3
0
        public void Handle_EventNotFound()
        {
            // Arrange
            var notification = new ParticipationChangedEvent(
                validParticipantId,
                new Guid("40E7F3FB-FA27-4349-9DB5-BB846D2D6DFA"),
                validDiverId,
                ParticipantStatus.Accepted);

            foundParticipant = new Participant
            {
                Id = notification.ParticipationId,
                ParticipatingDiverId = notification.DiverId,
                EventId = notification.EventId,
            };

            // Act
            Func <Task> act = () => policy.Handle(notification, CancellationToken.None);

            // Assert
            act.Should().Throw <InvalidOperationException>().WithMessage("Event not found!");
        }
Exemplo n.º 4
0
        public void Handle_DiverNotFound()
        {
            // Arrange
            var notification = new ParticipationChangedEvent(
                validParticipantId,
                validEventId,
                new Guid("9B05C53E-C54F-494D-B352-CF80B1D44E97"),
                ParticipantStatus.Accepted);

            foundParticipant = new Participant
            {
                Id = notification.ParticipationId,
                ParticipatingDiverId = notification.DiverId,
                EventId = notification.EventId,
            };

            // Act
            Func <Task> act = () => policy.Handle(notification, CancellationToken.None);

            // Assert
            act.Should().Throw <InvalidOperationException>().WithMessage("Diver not found!");
        }