Example #1
0
        public void WhenAlertDetailsControlClosedEventWasInvokedThenSelectedAlertWasSetToNull()
        {
            var alertsControlViewModel = new AlertsControlViewModel(this.smartDetectorRunner, this.systemProcessClientMock.Object);
            var emulationAlert         = EmulationAlertHelper.CreateEmulationAlert(new TestAlert());

            alertsControlViewModel.SelectedAlert = emulationAlert;

            Assert.IsNotNull(alertsControlViewModel.AlertDetailsControlViewModel, "Alert details control view model should not be null");
            Assert.AreEqual(emulationAlert, alertsControlViewModel.AlertDetailsControlViewModel.Alert, "Unexpected alert details control view model");

            alertsControlViewModel.AlertDetailsControlViewModel.CloseControlCommand.Execute(parameter: null);

            Assert.IsNull(alertsControlViewModel.SelectedAlert, "Selected alert should be null");
        }
        public void WhenCreatingNewViewModelWithArmRequestThenItWasInitializedCorrectly()
        {
            EmulationAlert emulationAlert            = EmulationAlertHelper.CreateEmulationAlert(new TestAlertWithArm(this.virtualMachineResourceIdentifier));
            bool           wasCloseEventHandlerFired = false;

            string         responseContent = (Encoding.Default.GetString(ArmResponses.ActivityLogResponse));
            JObject        responseObject  = JObject.Parse(responseContent);
            List <JObject> mockResponse    = new List <JObject>(responseObject["value"].ToObject <List <JObject> >());
            string         subscriptionId  = emulationAlert.ResourceIdentifier.SubscriptionId;

            var armClientMock = new Mock <IAzureResourceManagerClient>();

            armClientMock
            .Setup(m => m.ExecuteArmQueryAsync(new Uri("subscriptions/subscriptionId/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01", UriKind.Relative), CancellationToken.None))
            .ReturnsAsync(mockResponse);

            var alertDetailsControlViewModel = new AlertDetailsControlViewModel(
                emulationAlert,
                () =>
            {
                wasCloseEventHandlerFired = true;
            },
                armClientMock.Object);

            var alertPropreties = alertDetailsControlViewModel.DisplayablePropertiesTask.Result;

            // Verify "Essentials" properties
            AssertEssentialProperties(alertDetailsControlViewModel.EssentialsSectionProperties);

            // Verify "Details" properties
            AssertAlertProperties(alertPropreties);
            Assert.AreEqual(7, alertPropreties.Count, "Unexpected count of displayable properties");
            for (var index = 0; index < alertPropreties.Count - 1; index++)
            {
                string invalidOrderMessage =
                    $"Unexpected order of details section properties: Order of property in {index} index is {alertPropreties[index].Order}, " +
                    $"while order of property in {index + 1} index is {alertPropreties[index + 1].Order}";

                Assert.IsTrue(
                    alertPropreties[index].Order <= alertPropreties[index + 1].Order,
                    invalidOrderMessage);
            }

            // Verify close event was fired
            Assert.IsFalse(wasCloseEventHandlerFired);
            alertDetailsControlViewModel.CloseControlCommand.Execute(parameter: null);
            Assert.IsTrue(wasCloseEventHandlerFired);
        }
Example #3
0
        public void WhenExecutingOpenAnalyticsQueryCommandForAppInsightsResourceThenQueryWasExecutedAsExpected()
        {
            EmulationAlert emulationAlert = EmulationAlertHelper.CreateEmulationAlert(new TestAlert(this.appInsightsResourceIdentifier));

            var alertDetailsControlViewModel = new AlertDetailsControlViewModel(
                emulationAlert,
                () => { },
                this.systemProcessClientMock.Object);

            alertDetailsControlViewModel.OpenAnalyticsQueryCommand.Execute(parameter: "<query>");

            string expectedAbsoluteUri = "https://analytics.applicationinsights.io/subscriptions/7904b7bd-5e6b-4415-99a8-355657b7da19/resourcegroups/MyResourceGroupName/components/someApp?q=H4sIAAAAAAAEALMpLE0tqrQDAJjF8mcHAAAA";

            // Verify that the query was composed and executed as expected
            this.systemProcessClientMock.Verify(m => m.StartWebBrowserProcess(It.Is <Uri>(u => u.AbsoluteUri == expectedAbsoluteUri)), Times.Once());
        }
        public void WhenCreatingNewViewModelWithFailedArmRequestThenItWasInitializedCorrectly()
        {
            EmulationAlert emulationAlert            = EmulationAlertHelper.CreateEmulationAlert(new TestAlertWithArm(this.virtualMachineResourceIdentifier));
            bool           wasCloseEventHandlerFired = false;

            string         responseContent = (Encoding.Default.GetString(ArmResponses.ActivityLogResponse));
            JObject        responseObject  = JObject.Parse(responseContent);
            List <JObject> mockResponse    = new List <JObject>(responseObject["value"].ToObject <List <JObject> >());
            string         subscriptionId  = emulationAlert.ResourceIdentifier.SubscriptionId;

            var armClientMock = new Mock <IAzureResourceManagerClient>();

            armClientMock
            .Setup(m => m.ExecuteArmQueryAsync(new Uri("subscriptions/subscriptionId/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01", UriKind.Relative), CancellationToken.None))
            .Throws(new HttpRequestException("Query returned an error code 500"));

            var alertDetailsControlViewModel = new AlertDetailsControlViewModel(
                emulationAlert,
                () =>
            {
                wasCloseEventHandlerFired = true;
            },
                armClientMock.Object);

            var alertPropreties = alertDetailsControlViewModel.DisplayablePropertiesTask.Result;

            // Verify "Essentials" properties
            AssertEssentialProperties(alertDetailsControlViewModel.EssentialsSectionProperties);

            // Verify "Details" properties
            Assert.AreEqual(7, alertPropreties.Count, "Unexpected count of displayable properties");
            int index = 0;

            // Verify the none Arm properties have the correct information
            Assert.AreEqual("BeforeArmLongTextReference", alertPropreties[index].DisplayName, "unexpected Display name in none ARM property");
            Assert.AreEqual("longTextReferencePathNotArm", ((LongTextAlertProperty)alertPropreties[index]).Value, "unexpected value set in none ARM property");

            // Verify the Arm properties are returned with error response in value
            index++;
            Assert.AreEqual("TextReferenceDisplayName", alertPropreties[index].DisplayName, "unexpected Display name in ARM property");
            Assert.AreEqual("Failed to get Arm Response, Error: Query returned an error code 500", ((TextAlertProperty)alertPropreties[index]).Value, "unexpected value set in ARM property");

            // Verify close event was fired
            Assert.IsFalse(wasCloseEventHandlerFired);
            alertDetailsControlViewModel.CloseControlCommand.Execute(parameter: null);
            Assert.IsTrue(wasCloseEventHandlerFired);
        }
Example #5
0
        public void WhenAlertWasSelectedThenAlertDetailsViewModelWasUpdatedAccordingly()
        {
            var            alertsControlViewModel = new AlertsControlViewModel(this.smartDetectorRunner, this.systemProcessClientMock.Object);
            EmulationAlert emulationAlert         = EmulationAlertHelper.CreateEmulationAlert(new TestAlert());

            alertsControlViewModel.SelectedAlert = emulationAlert;

            Assert.IsNotNull(alertsControlViewModel.AlertDetailsControlViewModel, "Alert details control view model should not be null");
            Assert.AreEqual(emulationAlert, alertsControlViewModel.AlertDetailsControlViewModel.Alert, "Unexpected alert details control view model");

            EmulationAlert anotherEmulationAlert = EmulationAlertHelper.CreateEmulationAlert(new TestAlert());

            alertsControlViewModel.SelectedAlert = anotherEmulationAlert;

            Assert.IsNotNull(alertsControlViewModel.AlertDetailsControlViewModel, "Alert details control view model should not be null");
            Assert.AreEqual(anotherEmulationAlert, alertsControlViewModel.AlertDetailsControlViewModel.Alert, "Unexpected alert details control view model");
        }
Example #6
0
        public void WhenCreatingNewViewModelThenItWasInitializedCorrectly()
        {
            EmulationAlert emulationAlert            = EmulationAlertHelper.CreateEmulationAlert(new TestAlert(this.virtualMachineResourceIdentifier));
            bool           wasCloseEventHandlerFired = false;

            var alertDetailsControlViewModel = new AlertDetailsControlViewModel(
                emulationAlert,
                () =>
            {
                wasCloseEventHandlerFired = true;
            },
                this.systemProcessClientMock.Object);

            // Verify "Essentials" properties
            Assert.AreEqual("Subscription id", alertDetailsControlViewModel.EssentialsSectionProperties[0].ResourceType, "Unexpected essential property 'Subscription id'");
            Assert.AreEqual("someSubscription", alertDetailsControlViewModel.EssentialsSectionProperties[0].ResourceName, "Unexpected essential property 'Subscription id'");

            Assert.AreEqual("Resource group", alertDetailsControlViewModel.EssentialsSectionProperties[1].ResourceType, "Unexpected essential property 'Resource group'");
            Assert.AreEqual("someGroup", alertDetailsControlViewModel.EssentialsSectionProperties[1].ResourceName, "Unexpected essential property 'Resource group'");

            Assert.AreEqual("Resource type", alertDetailsControlViewModel.EssentialsSectionProperties[2].ResourceType, "Unexpected essential property 'Resource type'");
            Assert.AreEqual("VirtualMachine", alertDetailsControlViewModel.EssentialsSectionProperties[2].ResourceName, "Unexpected essential property 'Resource type'");

            Assert.AreEqual("Resource name", alertDetailsControlViewModel.EssentialsSectionProperties[3].ResourceType, "Unexpected essential property 'Resource name'");
            Assert.AreEqual("someVM", alertDetailsControlViewModel.EssentialsSectionProperties[3].ResourceName, "Unexpected essential property 'Resource name'");

            // Verify "Details" properties
            Assert.AreEqual(5, alertDetailsControlViewModel.DisplayableProperties.Count, "Unexpected count of displayable properties");
            for (var index = 0; index < alertDetailsControlViewModel.DisplayableProperties.Count - 1; index++)
            {
                string invalidOrderMessage =
                    $"Unexpected order of details section properties: Order of property in {index} index is {alertDetailsControlViewModel.DisplayableProperties[index].Order}, " +
                    $"while order of property in {index + 1} index is {alertDetailsControlViewModel.DisplayableProperties[index + 1].Order}";

                Assert.IsTrue(
                    alertDetailsControlViewModel.DisplayableProperties[index].Order <= alertDetailsControlViewModel.DisplayableProperties[index + 1].Order,
                    invalidOrderMessage);
            }

            // Verify close event was fired
            Assert.IsFalse(wasCloseEventHandlerFired);
            alertDetailsControlViewModel.CloseControlCommand.Execute(parameter: null);
            Assert.IsTrue(wasCloseEventHandlerFired);
        }
        public void WhenCreatingNewViewModelThenItWasInitializedCorrectly()
        {
            EmulationAlert emulationAlert            = EmulationAlertHelper.CreateEmulationAlert(new TestAlert(this.virtualMachineResourceIdentifier));
            bool           wasCloseEventHandlerFired = false;

            var armClientMock = new Mock <IAzureResourceManagerClient>();
            var alertDetailsControlViewModel = new AlertDetailsControlViewModel(
                emulationAlert,
                () =>
            {
                wasCloseEventHandlerFired = true;
            },
                armClientMock.Object);

            var alertPropreties = alertDetailsControlViewModel.DisplayablePropertiesTask.Result;

            // Verify "Essentials" properties
            AssertEssentialProperties(alertDetailsControlViewModel.EssentialsSectionProperties);

            // Verify "Details" properties
            Assert.AreEqual(5, alertPropreties.Count, "Unexpected count of displayable properties");
            for (var index = 0; index < alertPropreties.Count - 1; index++)
            {
                string invalidOrderMessage =
                    $"Unexpected order of details section properties: Order of property in {index} index is {alertPropreties[index].Order}, " +
                    $"while order of property in {index + 1} index is {alertPropreties[index + 1].Order}";

                Assert.IsTrue(
                    alertPropreties[index].Order <= alertPropreties[index + 1].Order,
                    invalidOrderMessage);
            }

            // Verify close event was fired
            Assert.IsFalse(wasCloseEventHandlerFired);
            alertDetailsControlViewModel.CloseControlCommand.Execute(parameter: null);
            Assert.IsTrue(wasCloseEventHandlerFired);
        }