public async Task ReconnectTeam_TeamAndMemberName_ReturnsScrumTeamWithEstimationFinishedAndEstimationIsNull()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.ReconnectTeam(PlanningPokerData.TeamName, PlanningPokerData.ScrumMasterName, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var estimationResult = PlanningPokerData.GetEstimationResult(scrumMasterEstimation: 8, memberEstimation: double.NaN);
            var scrumTeam        = PlanningPokerData.GetScrumTeam(member: true, state: TeamState.EstimationFinished, estimationResult: estimationResult);
            var reconnectResult  = PlanningPokerData.GetReconnectTeamResult(scrumTeam, lastMessageId: 2157483849, selectedEstimation: 8);
            var returnMessage    = new CompletionMessage(invocationId, null, reconnectResult, true);
            await fixture.ReceiveMessage(returnMessage);

            var result = await resultTask;

            Assert.AreEqual(reconnectResult, result);
            AssertAvailableEstimations(result.ScrumTeam);
            Assert.IsNotNull(result.SelectedEstimation);
            Assert.AreEqual(8.0, result.SelectedEstimation.Value);
            Assert.AreEqual(8.0, result.ScrumTeam.EstimationResult[0].Estimation.Value);
            Assert.IsNull(result.ScrumTeam.EstimationResult[1].Estimation);
        }
        public async Task GetMessages_LastMessageId_InvocationMessageIsSent()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.GetMessages(PlanningPokerData.TeamName, PlanningPokerData.MemberName, 2157483849, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            Assert.IsNotNull(sentMessage);
            Assert.IsInstanceOfType(sentMessage, typeof(InvocationMessage));
            var sentInvocationMessage = (InvocationMessage)sentMessage;

            Assert.AreEqual(RequestName, sentInvocationMessage.Target);
            var expectedArguments = new object[] { PlanningPokerData.TeamName, PlanningPokerData.MemberName, 2157483849L };

            CollectionAssert.AreEqual(expectedArguments, sentInvocationMessage.Arguments);

            var notifyMessage = new InvocationMessage(ResponseName, new object[] { new List <Message>() });
            await fixture.ReceiveMessage(notifyMessage);

            var returnMessage = new CompletionMessage(sentInvocationMessage.InvocationId, null, null, false);
            await fixture.ReceiveMessage(returnMessage);

            await resultTask;

            // Ensure asynchronous Dispose. Otherwise, Dispose is executed in OnNotify handler and it causes deadlock.
            await Task.Yield();
        }
        public async Task JoinTeam_TeamDoesNotExist_PlanningPokerException()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.JoinTeam(PlanningPokerData.TeamName, PlanningPokerData.MemberName, false, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var returnMessage = new CompletionMessage(invocationId, "Team 'Test team' does not exist.", null, false);
            await fixture.ReceiveMessage(returnMessage);

            var exception = await Assert.ThrowsExceptionAsync <PlanningPokerException>(() => resultTask);

            Assert.AreEqual("Team 'Test team' does not exist.", exception.Message);
        }
        public async Task JoinTeam_ReturnsEmptyErrorMessage_PlanningPokerException()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.JoinTeam(PlanningPokerData.TeamName, PlanningPokerData.MemberName, false, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var returnMessage = new CompletionMessage(invocationId, "An unexpected error occured. HubException: ", null, false);
            await fixture.ReceiveMessage(returnMessage);

            var exception = await Assert.ThrowsExceptionAsync <PlanningPokerException>(() => resultTask);

            Assert.AreEqual(string.Empty, exception.Message);
        }
        public async Task CreateTeam_TeamNameExists_PlanningPokerException()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.CreateTeam(PlanningPokerData.TeamName, PlanningPokerData.ScrumMasterName, Deck.Standard, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var returnMessage = new CompletionMessage(invocationId, "An unexpected error occured. HubException: Team 'Test team' already exists.", null, false);
            await fixture.ReceiveMessage(returnMessage);

            var exception = await Assert.ThrowsExceptionAsync <PlanningPokerException>(() => resultTask);

            Assert.AreEqual("Team 'Test team' already exists.", exception.Message);
        }
        public async Task CreateTeam_TeamAndScrumMasterName_ReturnsScrumTeam()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.CreateTeam(PlanningPokerData.TeamName, PlanningPokerData.ScrumMasterName, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var scrumTeam     = PlanningPokerData.GetScrumTeam();
            var returnMessage = new CompletionMessage(invocationId, null, scrumTeam, true);
            await fixture.ReceiveMessage(returnMessage);

            var result = await resultTask;

            Assert.AreEqual(scrumTeam, result);
            AssertAvailableEstimations(result);
        }
        private static async Task ProvideMessages(PlanningPokerSignalRClientFixture fixture, params Message[] messages)
        {
            var sentMessage = await fixture.GetSentMessage();

            Assert.IsNotNull(sentMessage);
            Assert.IsInstanceOfType(sentMessage, typeof(InvocationMessage));
            var sentInvocationMessage = (InvocationMessage)sentMessage;

            Assert.AreEqual(RequestName, sentInvocationMessage.Target);
            var expectedArguments = new object[] { PlanningPokerData.TeamName, PlanningPokerData.MemberName, 0L };

            CollectionAssert.AreEqual(expectedArguments, sentInvocationMessage.Arguments);

            var returnMessage = new CompletionMessage(sentInvocationMessage.InvocationId, null, null, false);
            await fixture.ReceiveMessage(returnMessage);

            var notifyMessage = new InvocationMessage(ResponseName, new object[] { messages.ToList() });
            await fixture.ReceiveMessage(notifyMessage);
        }
        public async Task JoinTeam_TeamAndObserverName_ReturnsScrumTeam()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.JoinTeam(PlanningPokerData.TeamName, PlanningPokerData.ObserverName, false, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var scrumTeam     = PlanningPokerData.GetScrumTeam(observer: true);
            var teamResult    = PlanningPokerData.GetTeamResult(scrumTeam);
            var returnMessage = new CompletionMessage(invocationId, null, teamResult, true);
            await fixture.ReceiveMessage(returnMessage);

            var result = await resultTask;

            Assert.AreEqual(teamResult, result);
            AssertAvailableEstimations(result.ScrumTeam);
        }
        public async Task DisconnectTeam_TeamNameAndMemberName_InvocationMessageIsSent()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.DisconnectTeam(PlanningPokerData.TeamName, PlanningPokerData.MemberName, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var sentInvocationMessage = AssertIsInvocationMessage(sentMessage);

            Assert.AreEqual("DisconnectTeam", sentInvocationMessage.Target);
            var expectedArguments = new object[] { PlanningPokerData.TeamName, PlanningPokerData.MemberName };

            CollectionAssert.AreEqual(expectedArguments, sentInvocationMessage.Arguments);

            var returnMessage = new CompletionMessage(sentInvocationMessage.InvocationId, null, null, false);
            await fixture.ReceiveMessage(returnMessage);

            await resultTask;
        }
        public async Task SubmitEstimation_EstimationValue_InvocationMessageIsSent(string memberName, double?estimation, double?expectedSentValue)
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.SubmitEstimation(PlanningPokerData.TeamName, memberName, estimation, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var sentInvocationMessage = AssertIsInvocationMessage(sentMessage);

            Assert.AreEqual("SubmitEstimation", sentInvocationMessage.Target);
            var expectedArguments = new object[] { PlanningPokerData.TeamName, memberName, expectedSentValue };

            CollectionAssert.AreEqual(expectedArguments, sentInvocationMessage.Arguments);

            var returnMessage = new CompletionMessage(sentInvocationMessage.InvocationId, null, null, false);
            await fixture.ReceiveMessage(returnMessage);

            await resultTask;
        }
        public async Task JoinTeam_TeamAndMemberName_ReturnsScrumTeamWithEstimationInProgress()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.JoinTeam(PlanningPokerData.TeamName, PlanningPokerData.MemberName, false, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var estimationParticipants = PlanningPokerData.GetEstimationParticipants();
            var scrumTeam     = PlanningPokerData.GetScrumTeam(member: true, state: TeamState.EstimationInProgress, estimationParticipants: estimationParticipants);
            var returnMessage = new CompletionMessage(invocationId, null, scrumTeam, true);
            await fixture.ReceiveMessage(returnMessage);

            var result = await resultTask;

            Assert.AreEqual(scrumTeam, result);
            AssertAvailableEstimations(result);
        }
        public async Task ReconnectTeam_TeamAndMemberName_ReturnsScrumTeam()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.ReconnectTeam(PlanningPokerData.TeamName, PlanningPokerData.MemberName, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var scrumTeam       = PlanningPokerData.GetScrumTeam(member: true);
            var reconnectResult = PlanningPokerData.GetReconnectTeamResultJson(scrumTeam);
            var returnMessage   = new CompletionMessage(invocationId, null, reconnectResult, true);
            await fixture.ReceiveMessage(returnMessage);

            var result = await resultTask;

            Assert.AreEqual(reconnectResult, result);
            AssertAvailableEstimations(result.ScrumTeam);
            Assert.IsNull(reconnectResult.SelectedEstimation);
        }
        public async Task JoinTeam_TeamNameAndObserverName_InvocationMessageIsSent()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.JoinTeam(PlanningPokerData.TeamName, PlanningPokerData.ObserverName, true, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var sentInvocationMessage = AssertIsInvocationMessage(sentMessage);

            Assert.AreEqual("JoinTeam", sentInvocationMessage.Target);
            var expectedArguments = new object[] { PlanningPokerData.TeamName, PlanningPokerData.ObserverName, true };

            CollectionAssert.AreEqual(expectedArguments, sentInvocationMessage.Arguments);

            var scrumTeam     = PlanningPokerData.GetScrumTeam(observer: true);
            var returnMessage = new CompletionMessage(sentInvocationMessage.InvocationId, null, scrumTeam, true);
            await fixture.ReceiveMessage(returnMessage);

            await resultTask;
        }
        public async Task JoinTeam_TeamAndMemberName_ReturnsScrumTeamWithEstimationCanceled()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.JoinTeam(PlanningPokerData.TeamName, PlanningPokerData.MemberName, false, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var estimationResult = PlanningPokerData.GetEstimationResult(scrumMasterEstimation: 0, memberEstimation: double.NaN);
            var scrumTeam        = PlanningPokerData.GetScrumTeam(member: true, state: TeamState.EstimationCanceled, estimationResult: estimationResult);
            var returnMessage    = new CompletionMessage(invocationId, null, scrumTeam, true);
            await fixture.ReceiveMessage(returnMessage);

            var result = await resultTask;

            Assert.AreEqual(scrumTeam, result);
            AssertAvailableEstimations(result);
            Assert.AreEqual(0.0, result.EstimationResult[0].Estimation.Value);
            Assert.IsNull(result.EstimationResult[1].Estimation);
        }
        public async Task CreateTeam_TeamNameAndScrumMaster_InvocationMessageIsSent(Deck deck)
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.CreateTeam(PlanningPokerData.TeamName, PlanningPokerData.ScrumMasterName, deck, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var sentInvocationMessage = AssertIsInvocationMessage(sentMessage);

            Assert.AreEqual("CreateTeam", sentInvocationMessage.Target);
            var expectedArguments = new object[] { PlanningPokerData.TeamName, PlanningPokerData.ScrumMasterName, deck };

            CollectionAssert.AreEqual(expectedArguments, sentInvocationMessage.Arguments);

            var scrumTeam     = PlanningPokerData.GetScrumTeam();
            var teamResult    = PlanningPokerData.GetTeamResult(scrumTeam);
            var returnMessage = new CompletionMessage(sentInvocationMessage.InvocationId, null, teamResult, true);
            await fixture.ReceiveMessage(returnMessage);

            await resultTask;
        }
        public async Task ReconnectTeam_TeamAndMemberName_ReturnsScrumTeamWithEstimationInProgress()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.ReconnectTeam(PlanningPokerData.TeamName, PlanningPokerData.ScrumMasterName, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var estimationParticipants = PlanningPokerData.GetEstimationParticipants(scrumMaster: false, member: true);
            var scrumTeam       = PlanningPokerData.GetScrumTeam(member: true, state: TeamState.EstimationInProgress, estimationParticipants: estimationParticipants);
            var reconnectResult = PlanningPokerData.GetReconnectTeamResult(scrumTeam, lastMessageId: 1, selectedEstimation: null);
            var returnMessage   = new CompletionMessage(invocationId, null, reconnectResult, true);
            await fixture.ReceiveMessage(returnMessage);

            var result = await resultTask;

            Assert.AreEqual(reconnectResult, result);
            AssertAvailableEstimations(result.ScrumTeam);
            Assert.IsNotNull(result.SelectedEstimation);
            Assert.IsNull(result.SelectedEstimation.Value);
        }
        public async Task JoinTeam_TeamAndMemberName_ReturnsScrumTeamWithEstimationFinishedAndEstimationIsInfinity()
        {
            await using var fixture = new PlanningPokerSignalRClientFixture();

            var resultTask = fixture.Target.JoinTeam(PlanningPokerData.TeamName, PlanningPokerData.MemberName, false, fixture.CancellationToken);

            var sentMessage = await fixture.GetSentMessage();

            var invocationId = GetInvocationId(sentMessage);

            var estimationResult = PlanningPokerData.GetEstimationResult(scrumMasterEstimation: Estimation.PositiveInfinity, memberEstimation: null);
            var scrumTeam        = PlanningPokerData.GetScrumTeam(member: true, observer: true, state: TeamState.EstimationFinished, estimationResult: estimationResult);
            var teamResult       = PlanningPokerData.GetTeamResult(scrumTeam);
            var returnMessage    = new CompletionMessage(invocationId, null, teamResult, true);
            await fixture.ReceiveMessage(returnMessage);

            var result = await resultTask;

            Assert.AreEqual(teamResult, result);
            AssertAvailableEstimations(result.ScrumTeam);
            Assert.IsTrue(double.IsPositiveInfinity(result.ScrumTeam.EstimationResult[0].Estimation.Value.Value));
            Assert.IsNull(result.ScrumTeam.EstimationResult[1].Estimation.Value);
        }