public void TestHandleCommandForBuildNotificationRaisesCommandReceivedEvent()
        {
            // Setup
            Listener listener = new Listener(IPAddress.Any, 0);
            IBuildServerNotification actualNotification = null;
            listener.OnCommandReceived += delegate(object sender, EventArgs args) { actualNotification = (IBuildServerNotification)sender; };
            BuildServerNotificationType notificationType = BuildServerNotificationType.BuildBuilding;
            string projectId = "project1";
            string buildConfigId = "buildconfig1";
            string username1 = "user1";
            string username2 = "user2";
            string[] recipients = { username1, username2 };
            BuildNotification expectedBuildNotification = new BuildNotification(notificationType, projectId, buildConfigId, recipients);
            string command = Parser.Encode(expectedBuildNotification);

            // Fire
            listener.HandleCommand(command);

            // Test
            Assert.That(actualNotification, Is.Not.Null);
            Assert.That(actualNotification, Is.InstanceOf(typeof(BuildNotification)));
            BuildNotification actualBuildNotification = (BuildNotification)actualNotification;
            Assert.That(actualBuildNotification.Type, Is.EqualTo(notificationType));
            Assert.That(actualBuildNotification.ProjectId.Equals(projectId));
            Assert.That(actualBuildNotification.BuildConfigId.Equals(buildConfigId));
            Assert.That(actualBuildNotification.Recipients.Length, Is.EqualTo(2));
            Assert.That(actualBuildNotification.Recipients, Is.EqualTo(recipients));
        }
        public void TestHandleCommandForResponsibilityNotificationRaisesCommandReceivedEvent()
        {
            // Setup
            Listener listener = new Listener(IPAddress.Any, 0);
            IBuildServerNotification actualNotification = null;
            listener.OnCommandReceived += delegate(object sender, EventArgs args) { actualNotification = (IBuildServerNotification)sender; };
            BuildServerNotificationType notificationType = BuildServerNotificationType.BuildResponsibilityAssigned;
            string projectId = "project1";
            string buildConfigId = "buildconfig1";
            string username = "******";
            string state = BuildServerResponsibilityState.Taken;
            ResponsibilityNotification actualResponsibilityNotification = new ResponsibilityNotification(notificationType, projectId, buildConfigId, username, state);
            string command = Parser.Encode(actualResponsibilityNotification);

            // Fire
            listener.HandleCommand(command);

            // Test
            Assert.That(actualNotification, Is.Not.Null);
            Assert.That(actualNotification, Is.InstanceOf(typeof(ResponsibilityNotification)));
            ResponsibilityNotification expectedResponsibilityNotification = (ResponsibilityNotification)actualNotification;
            Assert.That(expectedResponsibilityNotification.Type, Is.EqualTo(notificationType));
            Assert.That(expectedResponsibilityNotification.ProjectId.Equals(projectId));
            Assert.That(expectedResponsibilityNotification.BuildConfigId.Equals(buildConfigId));
            Assert.That(expectedResponsibilityNotification.Recipient, Is.EqualTo(username));
            Assert.That(expectedResponsibilityNotification.State, Is.EqualTo(state));
        }
        public void TestHandleCommandForRegistrationRequestRaisesCommandReceivedEvent()
        {
            // Setup
            Listener listener = new Listener(IPAddress.Any, 0);
            IRequest actualRequest = null;
            listener.OnCommandReceived += delegate(object sender, EventArgs args) { actualRequest = (IRequest)sender; };
            string username = "******";
            string hostname = username + "-ws";
            RegistrationRequest actualRegistrationRequest = new RegistrationRequest(hostname, username);
            string command = Parser.Encode(actualRegistrationRequest);

            // Fire
            listener.HandleCommand(command);

            // Test
            Assert.That(actualRequest, Is.Not.Null);
            Assert.That(actualRequest, Is.InstanceOf(typeof(RegistrationRequest)));
            RegistrationRequest expectedRegistrationRequest = (RegistrationRequest)actualRequest;
            Assert.That(expectedRegistrationRequest.Username, Is.EqualTo(username));
            Assert.That(expectedRegistrationRequest.Hostname, Is.EqualTo(hostname));
        }