public void Start_EstimationEnded_NoMessageIsSentToServiceBus()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >()));
            planningPoker.Setup(p => p.EndInitialization());
            var message = new ScrumTeamMessage(TeamName, MessageType.EstimationEnded);
            var startPlanningPokerMsg = SetupPlanningPokerMsg(planningPoker, message);

            var sendServiceBusMsg = SetupServiceBus(serviceBus, target.NodeId, null);

            // Act
            target.Start();
            sendServiceBusMsg();
            startPlanningPokerMsg();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            serviceBus.Verify(b => b.SendMessage(It.Is <NodeMessage>(m => m.MessageType != NodeMessageType.RequestTeamList)), Times.Never());
        }
        public void Start_RequestTeamsMessageReceived_TeamIsSentToServiceBus()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var teamList    = new string[] { TeamName };
            var nodeMessage = new NodeMessage(NodeMessageType.RequestTeams)
            {
                Data = teamList
            };

            serviceBus.Setup(b => b.SendMessage(It.IsAny <NodeMessage>()));
            var         sendMessages          = SetupServiceBus(serviceBus, target.NodeId, nodeMessage);
            NodeMessage initializeTeamMessage = null;

            serviceBus.Setup(b => b.SendMessage(It.Is <NodeMessage>(m => m.MessageType == NodeMessageType.InitializeTeam)))
            .Callback <NodeMessage>(m => initializeTeamMessage = m).Verifiable();

            SetupPlanningPoker(planningPoker, CreateBasicTeam());

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            Assert.IsNotNull(initializeTeamMessage);
            Assert.IsNotNull(initializeTeamMessage.Data);
            Assert.IsInstanceOfType(initializeTeamMessage.Data, typeof(byte[]));
            Assert.AreEqual <string>(nodeMessage.SenderNodeId, initializeTeamMessage.RecipientNodeId);
        }
        public void Start_MemberJoined_MessageIsSentToServiceBus()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >()));
            planningPoker.Setup(p => p.EndInitialization());
            var message = new ScrumTeamMemberMessage(TeamName, MessageType.MemberJoined)
            {
                MemberName = MemberName
            };
            var startPlanningPokerMsg = SetupPlanningPokerMsg(planningPoker, message);

            var         sendServiceBusMsg = SetupServiceBus(serviceBus, target.NodeId, null);
            NodeMessage nodeMessage       = null;

            serviceBus.Setup(b => b.SendMessage(It.Is <NodeMessage>(m => m.MessageType == NodeMessageType.ScrumTeamMessage))).Callback <NodeMessage>(m => nodeMessage = m).Verifiable();

            // Act
            target.Start();
            sendServiceBusMsg();
            startPlanningPokerMsg();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            Assert.IsNotNull(nodeMessage);
            Assert.AreEqual <NodeMessageType>(NodeMessageType.ScrumTeamMessage, nodeMessage.MessageType);
            Assert.AreEqual <string>(target.NodeId, nodeMessage.SenderNodeId);
            Assert.AreEqual(message, nodeMessage.Data);
        }
        public void Start_NotInitAndMasterActivityFromServiceBus_MessageIgnored()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var message = new ScrumTeamMemberMessage(TeamName, MessageType.MemberActivity)
            {
                MemberName = ScrumMasterName,
                MemberType = "ScrumMaster"
            };
            var nodeMessage = new NodeMessage(NodeMessageType.ScrumTeamMessage)
            {
                Data = message
            };
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, new string[] { TeamName }, nodeMessage);

            SetupPlanningPoker(planningPoker, null, true);
            planningPoker.Setup(p => p.DateTimeProvider).Returns(new DateTimeProviderMock()).Verifiable();

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify(p => p.GetScrumTeam(It.IsAny <string>()), Times.Never());
            planningPoker.Verify();
            serviceBus.Verify();
        }
        public void Start_RequestTeamListMessageReceived_TeamListIsObtainedFromPlanningPoker()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var nodeMessage = new NodeMessage(NodeMessageType.RequestTeamList);

            serviceBus.Setup(b => b.SendMessage(It.IsAny <NodeMessage>()));
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, nodeMessage);

            var teamList = new string[] { TeamName };

            planningPoker.Setup(p => p.ObservableMessages).Returns(Observable.Empty <ScrumTeamMessage>());
            planningPoker.Setup(p => p.DateTimeProvider).Returns(DateTimeProvider.Default);
            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >()));
            planningPoker.Setup(p => p.EndInitialization());
            planningPoker.Setup(p => p.ScrumTeamNames).Returns(teamList).Verifiable();

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
        }
        public void Start_InitializeTeamMessageReceivedButAnotherTeamIsNotInitializedYet_EndInitializationIsNotExecuted()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var teamList    = new string[] { TeamName, "team 2" };
            var nodeMessage = new NodeMessage(NodeMessageType.InitializeTeam)
            {
                Data = CreateSerializedBasicTeam()
            };

            serviceBus.Setup(b => b.SendMessage(It.IsAny <NodeMessage>()));
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, teamList, nodeMessage);

            planningPoker.Setup(p => p.ObservableMessages).Returns(Observable.Empty <ScrumTeamMessage>());
            planningPoker.Setup(p => p.DateTimeProvider).Returns(DateTimeProvider.Default);
            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >()));
            planningPoker.Setup(p => p.EndInitialization());
            planningPoker.Setup(p => p.InitializeScrumTeam(It.IsAny <ScrumTeam>())).Verifiable();

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            planningPoker.Verify(p => p.EndInitialization(), Times.Never());
        }
        public void Start_TeamCreatedFromServiceBus_TeamAttachedToPlanningPoker()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var nodeMessage = new NodeMessage(NodeMessageType.TeamCreated)
            {
                Data = CreateSerializedBasicTeam()
            };
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, nodeMessage);

            var       dateTimeProvider = new DateTimeProviderMock();
            ScrumTeam team             = null;

            planningPoker.Setup(p => p.AttachScrumTeam(It.IsAny <ScrumTeam>()))
            .Callback <ScrumTeam>(t => team = t).Returns <ScrumTeam>(null).Verifiable();
            planningPoker.Setup(p => p.DateTimeProvider).Returns(dateTimeProvider).Verifiable();
            planningPoker.Setup(p => p.ObservableMessages).Returns(Observable.Empty <ScrumTeamMessage>()).Verifiable();
            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >()));
            planningPoker.Setup(p => p.EndInitialization());

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            Assert.IsNotNull(team);
            Assert.AreEqual <string>(TeamName, team.Name);
            Assert.AreEqual <DateTimeProvider>(dateTimeProvider, team.DateTimeProvider);
        }
        public void Start_TeamListMessageReceived_SetScrumTeamListOnPlanningPoker()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var teamList = new string[] { TeamName };

            serviceBus.Setup(b => b.SendMessage(It.IsAny <NodeMessage>()));
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, teamList, null);

            planningPoker.Setup(p => p.ObservableMessages).Returns(Observable.Empty <ScrumTeamMessage>());
            planningPoker.Setup(p => p.DateTimeProvider).Returns(DateTimeProvider.Default);
            IEnumerable <string> initializationTeamList = null;

            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >()))
            .Callback <IEnumerable <string> >(t => initializationTeamList = t).Verifiable();

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            Assert.IsNotNull(initializationTeamList);
            CollectionAssert.AreEquivalent(teamList, initializationTeamList.ToList());
        }
        public void Start_InitializeTeamMessageReceived_InitializeTeamOnPlanningPoker()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var teamList    = new string[] { TeamName };
            var nodeMessage = new NodeMessage(NodeMessageType.InitializeTeam)
            {
                Data = CreateSerializedBasicTeam()
            };

            serviceBus.Setup(b => b.SendMessage(It.IsAny <NodeMessage>()));
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, teamList, nodeMessage);

            planningPoker.Setup(p => p.ObservableMessages).Returns(Observable.Empty <ScrumTeamMessage>());
            planningPoker.Setup(p => p.DateTimeProvider).Returns(DateTimeProvider.Default);
            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >()));
            ScrumTeam initializingTeam = null;

            planningPoker.Setup(p => p.InitializeScrumTeam(It.IsAny <ScrumTeam>())).Callback <ScrumTeam>(t => initializingTeam = t).Verifiable();
            planningPoker.Setup(p => p.EndInitialization()).Verifiable();

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            Assert.IsNotNull(initializingTeam);
            Assert.AreEqual <string>(TeamName, initializingTeam.Name);
        }
        public void Start_TeamListMessageReceived_RequestForTeams()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var         teamList            = new string[] { TeamName };
            var         sendMessages        = SetupServiceBus(serviceBus, target.NodeId, teamList, null);
            NodeMessage requestTeamsMessage = null;

            serviceBus.Setup(b => b.SendMessage(It.Is <NodeMessage>(m => m.MessageType == NodeMessageType.RequestTeams)))
            .Callback <NodeMessage>(m => requestTeamsMessage = m).Verifiable();

            planningPoker.Setup(p => p.ObservableMessages).Returns(Observable.Empty <ScrumTeamMessage>());
            planningPoker.Setup(p => p.DateTimeProvider).Returns(DateTimeProvider.Default);
            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >())).Verifiable();

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            Assert.IsNotNull(requestTeamsMessage);
            Assert.IsNotNull(requestTeamsMessage.Data);
            var requestedTeams = (string[])requestTeamsMessage.Data;

            CollectionAssert.AreEquivalent(teamList, requestedTeams);
        }
        public void Start_RequestTeamsMessageReceived_TeamIsObtainedFromPlanningPoker()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var teamList    = new string[] { TeamName };
            var nodeMessage = new NodeMessage(NodeMessageType.RequestTeams)
            {
                Data = teamList
            };

            serviceBus.Setup(b => b.SendMessage(It.IsAny <NodeMessage>()));
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, nodeMessage);

            var teamLock = SetupPlanningPoker(planningPoker, CreateBasicTeam());

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            teamLock.Verify();
        }
        public void Start_NotInitAndTeamCreatedFromServiceBus_IgnoreMessage()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var nodeMessage = new NodeMessage(NodeMessageType.TeamCreated)
            {
                Data = CreateSerializedBasicTeam()
            };
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, new string[] { TeamName }, nodeMessage);

            SetupPlanningPoker(planningPoker, null, true);
            planningPoker.Setup(p => p.DateTimeProvider).Returns(new DateTimeProviderMock()).Verifiable();

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify(p => p.AttachScrumTeam(It.IsAny <ScrumTeam>()), Times.Never());
            planningPoker.Verify();
            serviceBus.Verify();
        }
        public void Start_MasterEstimatedFromServiceBus_MasterEstimationIsSet()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var message = new ScrumTeamMemberEstimationMessage(TeamName, MessageType.MemberEstimated)
            {
                MemberName = ScrumMasterName,
                Estimation = 5.0
            };
            var nodeMessage = new NodeMessage(NodeMessageType.ScrumTeamMessage)
            {
                Data = message
            };
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, nodeMessage);

            var team = CreateBasicTeam();

            team.ScrumMaster.StartEstimation();
            var teamLock = SetupPlanningPoker(planningPoker, team);

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            teamLock.Verify();
            Assert.IsNotNull(team.ScrumMaster.Estimation);
            Assert.AreEqual <double?>(5.0, team.ScrumMaster.Estimation.Value);
        }
        public void Start_EstimationCanceledFromServiceBus_TeamEstimationCanceled()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var message     = new ScrumTeamMessage(TeamName, MessageType.EstimationCanceled);
            var nodeMessage = new NodeMessage(NodeMessageType.ScrumTeamMessage)
            {
                Data = message
            };
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, nodeMessage);

            var team = CreateBasicTeam();

            team.ScrumMaster.StartEstimation();
            var teamLock = SetupPlanningPoker(planningPoker, team);

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            teamLock.Verify();
            Assert.AreEqual <TeamState>(TeamState.EstimationCanceled, team.State);
        }
        public void Constructor_PlanningPokerIsNull_ArgumentNullException()
        {
            // Arrange
            var serviceBus = new Mock <IServiceBus>(MockBehavior.Strict);

            // Act
            var result = new PlanningPokerAzureNode(null, serviceBus.Object, null);
        }
        public void Constructor_ServiceBusIsNull_ArgumentNullException()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);

            // Act
            var result = new PlanningPokerAzureNode(planningPoker.Object, null, null);
        }
        public void Constructor_NoConfiguration_DefaultConfigurationIsSet()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);

            // Act
            var result = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, null);

            // Verify
            Assert.IsNotNull(result.Configuration);
        }
        public void Constructor_PlanningPoker_PlanningPokerIsSet()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);

            // Act
            var result = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, null);

            // Verify
            Assert.AreEqual <IAzurePlanningPoker>(planningPoker.Object, result.PlanningPoker);
        }
        public void Constructor_Configuration_ConfigurationIsSet()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var configuration = CreateConfigutartion();

            // Act
            var result = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, configuration);

            // Verify
            Assert.AreEqual <IAzurePlanningPokerConfiguration>(configuration, result.Configuration);
        }
        public void Start_MasterActivityFromServiceBus_MasterUpdatedActivityInTeam()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var message = new ScrumTeamMemberMessage(TeamName, MessageType.MemberActivity)
            {
                MemberName = ScrumMasterName,
                MemberType = "ScrumMaster"
            };
            var nodeMessage = new NodeMessage(NodeMessageType.ScrumTeamMessage)
            {
                Data = message
            };
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, nodeMessage);

            var dateTimeProvider = new DateTimeProviderMock();

            dateTimeProvider.SetUtcNow(new DateTime(2012, 9, 9, 23, 27, 33, DateTimeKind.Utc));

            var team = new ScrumTeam(TeamName, dateTimeProvider);

            team.SetScrumMaster(ScrumMasterName);
            var teamLock = SetupPlanningPoker(planningPoker, team);

            dateTimeProvider.SetUtcNow(new DateTime(2012, 9, 9, 23, 28, 27, DateTimeKind.Utc));

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            teamLock.Verify();
            Assert.AreEqual <DateTime>(dateTimeProvider.UtcNow, team.ScrumMaster.LastActivity);
        }
        public void Start_RequestTeamsMessageReceivedButTeamDoesNotExistAnymore_TeamNameIsSentToServiceBus()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var teamList    = new string[] { TeamName };
            var nodeMessage = new NodeMessage(NodeMessageType.RequestTeams)
            {
                Data = teamList
            };

            serviceBus.Setup(b => b.SendMessage(It.IsAny <NodeMessage>()));
            var         sendMessages          = SetupServiceBus(serviceBus, target.NodeId, nodeMessage);
            NodeMessage initializeTeamMessage = null;

            serviceBus.Setup(b => b.SendMessage(It.Is <NodeMessage>(m => m.MessageType == NodeMessageType.InitializeTeam)))
            .Callback <NodeMessage>(m => initializeTeamMessage = m).Verifiable();

            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >()));
            planningPoker.Setup(p => p.EndInitialization()).Verifiable();
            planningPoker.Setup(p => p.ObservableMessages).Returns(Observable.Empty <ScrumTeamMessage>()).Verifiable();
            planningPoker.Setup(p => p.GetScrumTeam(TeamName)).Throws(new ArgumentException()).Verifiable();

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            Assert.IsNotNull(initializeTeamMessage);
            Assert.IsNotNull(initializeTeamMessage.Data);
            Assert.IsInstanceOfType(initializeTeamMessage.Data, typeof(string));
            Assert.AreEqual <string>(TeamName, (string)initializeTeamMessage.Data);
            Assert.AreEqual <string>(nodeMessage.SenderNodeId, initializeTeamMessage.RecipientNodeId);
        }
        public void Start_TeamCreatedMessage_MessageIsSentToServiceBus()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            planningPoker.Setup(p => p.SetTeamsInitializingList(It.IsAny <IEnumerable <string> >()));
            planningPoker.Setup(p => p.EndInitialization());
            var team     = CreateBasicTeam();
            var teamLock = CreateTeamLock(team);
            var message  = new ScrumTeamMessage(TeamName, MessageType.TeamCreated);
            var startPlanningPokerMsg = SetupPlanningPokerMsg(planningPoker, message);

            planningPoker.Setup(p => p.GetScrumTeam(TeamName)).Returns(teamLock.Object).Verifiable();

            var         sendServiceBusMsg = SetupServiceBus(serviceBus, target.NodeId, null);
            NodeMessage nodeMessage       = null;

            serviceBus.Setup(b => b.SendMessage(It.Is <NodeMessage>(m => m.MessageType == NodeMessageType.TeamCreated))).Callback <NodeMessage>(m => nodeMessage = m).Verifiable();

            // Act
            target.Start();
            sendServiceBusMsg();
            startPlanningPokerMsg();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            teamLock.Verify();
            Assert.IsNotNull(nodeMessage);
            Assert.AreEqual <NodeMessageType>(NodeMessageType.TeamCreated, nodeMessage.MessageType);
            Assert.AreEqual <string>(target.NodeId, nodeMessage.SenderNodeId);
            Assert.IsNotNull(nodeMessage.Data);
            Assert.IsInstanceOfType(nodeMessage.Data, typeof(byte[]));
        }
        public void Start_ObserverJoinedFromServiceBus_ObserverJoinedTeam()
        {
            // Arrange
            var planningPoker = new Mock <IAzurePlanningPoker>(MockBehavior.Strict);
            var serviceBus    = new Mock <IServiceBus>(MockBehavior.Strict);
            var target        = new PlanningPokerAzureNode(planningPoker.Object, serviceBus.Object, CreateConfigutartion());

            var message = new ScrumTeamMemberMessage(TeamName, MessageType.MemberJoined)
            {
                MemberName = ObserverName,
                MemberType = "Observer"
            };
            var nodeMessage = new NodeMessage(NodeMessageType.ScrumTeamMessage)
            {
                Data = message
            };
            var sendMessages = SetupServiceBus(serviceBus, target.NodeId, nodeMessage);

            var team     = CreateBasicTeam();
            var teamLock = SetupPlanningPoker(planningPoker, team);

            // Act
            target.Start();
            sendMessages();
            target.Stop();

            // Verify
            planningPoker.Verify();
            serviceBus.Verify();
            teamLock.Verify();
            var observer = team.FindMemberOrObserver(ObserverName);

            Assert.IsNotNull(observer);
            Assert.IsInstanceOfType(observer, typeof(Observer));
            Assert.AreEqual <string>(ObserverName, observer.Name);
        }
 public AzurePlanningPokerNodeService(PlanningPokerAzureNode node)
 {
     _node = node ?? throw new ArgumentNullException(nameof(node));
 }