public void HandleBuildCompletion(BuildCompletionEvent buildEvent)
        {
            var teamProjectMapping = FindTeamProjectMapping(buildEvent.TeamProject);

            if (teamProjectMapping == null)
            {
                return;
            }

            var notification = (buildEvent.CompletionStatus == "Successfully Completed")
                                   ? Notification.BuildCompletionSuccess
                                   : Notification.BuildCompletionFailure;

            if (!IsNotificationSubscribedTo(teamProjectMapping, notification))
            {
                return;
            }

            if (notification == Notification.BuildCompletionSuccess)
            {
                _hipChatNotifier.SendBuildSuccessNotification(buildEvent, teamProjectMapping.HipChatRoomId);
            }
            else
            {
                _hipChatNotifier.SendBuildFailedNotification(buildEvent, teamProjectMapping.HipChatRoomId);
            }
        }
 public void SendBuildSuccessNotification(BuildCompletionEvent buildEvent, int roomId)
 {
     var message = string.Format("{0} build <a href=\"{1}\">{2}</a> {3} (requested by {4})",
         buildEvent.TeamProject, buildEvent.Url, buildEvent.Id, buildEvent.CompletionStatus,
         buildEvent.GetRequestedByName());
     _hipChatClient.RoomId = roomId;
     _hipChatClient.SendMessage(message, HipChatClient.BackgroundColor.green);
 }
        public void GetRequestedByName_ShouldReturnUnformattedName_WhenNonStandardDomainName()
        {
            var buildEvent = new BuildCompletionEvent { RequestedBy = @"DOMAIN\uname1" };

            var name = buildEvent.GetRequestedByName();

            Assert.Equal(@"DOMAIN\uname1", name);
        }
        public void HandleBuildCompletion_ShouldNotSendBuildSuccess_WhenBuildBroken()
        {
            var notifier = Substitute.For<IHipChatNotifier>();
            var configProvider = CreateFakeConfigurationProvider();
            var notificationHandler = new NotificationHandler(notifier, configProvider);
            var buildEvent = new BuildCompletionEvent { TeamProject = "TestProject" };

            notificationHandler.HandleBuildCompletion(buildEvent);

            notifier.DidNotReceiveWithAnyArgs().SendBuildSuccessNotification(null, 0);
        }
        public void HandleBuildCompletion_ShouldNotSendBuildFailed_WhenNotificationNotSubscribed()
        {
            var notifier = Substitute.For<IHipChatNotifier>();
            var configProvider = CreateFakeConfigurationProvider();
            var notificationHandler = new NotificationHandler(notifier, configProvider);
            var buildEvent = new BuildCompletionEvent { TeamProject = "ProjectWithOnlyCheckin" };

            notificationHandler.HandleBuildCompletion(buildEvent);

            notifier.DidNotReceiveWithAnyArgs().SendBuildFailedNotification(null, 0);
        }
        public void HandleBuildCompletion_ShouldNotSendBuildSuccess_WhenBuildSuccessfulAndMappingNotDefined()
        {
            var notifier = Substitute.For<IHipChatNotifier>();
            var configProvider = CreateFakeConfigurationProvider();
            var notificationHandler = new NotificationHandler(notifier, configProvider);
            var buildEvent = new BuildCompletionEvent
                                 {
                                     CompletionStatus = "Successfully Completed",
                                     TeamProject = "ProjectWithNoMapping"
                                 };

            notificationHandler.HandleBuildCompletion(buildEvent);

            notifier.DidNotReceiveWithAnyArgs().SendBuildSuccessNotification(null, 0);
        }
        public void HandleBuildCompletion_ShouldSendBuildSuccessToCorrectRoom_WhenBuildSuccessful()
        {
            var notifier = Substitute.For<IHipChatNotifier>();
            var configProvider = CreateFakeConfigurationProvider();
            var notificationHandler = new NotificationHandler(notifier, configProvider);
            var buildEvent = new BuildCompletionEvent
                                 {
                                     CompletionStatus = "Successfully Completed",
                                     TeamProject = "AnotherTestProject"
                                 };

            notificationHandler.HandleBuildCompletion(buildEvent);

            notifier.Received().SendBuildSuccessNotification(buildEvent, 456);
        }