public void DP004ResolveApplicationDependenciesWithWarnings(DP004ApplicationDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e)
        {
            "Given a source model"
            .x(() =>
            {
                model = TestHelper.CreateDefaultModelForAnalyzing();

                foreach (var application in model.GetSourceModel <ParsedBizTalkApplicationGroup>().Applications)
                {
                    var appDef = application.Application.ApplicationDefinition.ApplicationDefinition;
                    if (appDef.References != null && appDef.References.Length > 0)
                    {
                        application.Application.ApplicationDefinition.ApplicationDefinition.References[0].Name = "unknown app";
                    }
                }
            });

            "And a context"
            .x(() => context = TestHelper.BuildContext());

            "And a logger"
            .x(() => logger = _mockLogger.Object);

            "And an analyzer"
            .x(() => analyzer = new DP004ApplicationDependencyAnalyzer(model, context, logger));

            "When analyzing"
            .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false));

            "Then there should be no exception"
            .x(() => e.Should().BeNull());

            "And there should be no context errors"
            .x(() => context.Errors.Should().HaveCount(0));

            "And report resource node should have warning messages"
            .x(() =>
            {
                // Test the applications
                var applications = model.GetSourceModel <ParsedBizTalkApplicationGroup>().Applications;
                applications.Should().NotBeNull().And.HaveCount(3);

                applications[0].Application.ApplicationDefinition.Resource.ReportMessages.Should().HaveCount(0);
                applications[0].Application.ApplicationDefinition.Resource.ResourceRelationships.Should().HaveCount(0);

                applications[1].Application.ApplicationDefinition.Resource.ReportMessages.Should().HaveCount(1);
                applications[1].Application.ApplicationDefinition.Resource.ResourceRelationships.Should().HaveCount(0);

                applications[2].Application.ApplicationDefinition.Resource.ReportMessages.Should().HaveCount(0);
                applications[2].Application.ApplicationDefinition.Resource.ResourceRelationships.Should().HaveCount(0);
            });
        }
        public void ConstructWithNullContext(DP004ApplicationDependencyAnalyzer analyzer, ILogger logger, IApplicationModel model, MigrationContext context, Exception e)
        {
            "Given an analyzer"
            .x(() => analyzer.Should().BeNull());

            "And a model"
            .x(() => model = new AzureIntegrationServicesModel());

            "And null context"
            .x(() => context.Should().BeNull());

            "And a logger"
            .x(() => logger = _mockLogger.Object);

            "When constructing with a null context"
            .x(() => e = Record.Exception(() => new DP004ApplicationDependencyAnalyzer(model, context, logger)));

            "Then the constructor should throw an exception"
            .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("context"));
        }
        public void ConstructWithSuccess(DP004ApplicationDependencyAnalyzer analyzer, ILogger logger, IApplicationModel model, MigrationContext context, Exception e)
        {
            "Given an analyzer"
            .x(() => analyzer.Should().BeNull());

            "And a model"
            .x(() => model = new AzureIntegrationServicesModel());

            "And a context"
            .x(() => context = TestHelper.BuildContext());

            "And a logger"
            .x(() => logger = _mockLogger.Object);

            "When constructing"
            .x(() => e = Record.Exception(() => new DP004ApplicationDependencyAnalyzer(model, context, logger)));

            "Then the constructor should NOT throw an exception"
            .x(() => e.Should().BeNull());
        }
        public void DP004RuleSkippedIfModelIsEmpty(DP004ApplicationDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e)
        {
            "Given an source model"
            .x(() => model = new AzureIntegrationServicesModel());

            "And a context"
            .x(() => context = TestHelper.BuildContext());

            "And a logger"
            .x(() => logger = _mockLogger.Object);

            "And an analyzer"
            .x(() => analyzer = new DP004ApplicationDependencyAnalyzer(model, context, logger));

            "When analyzing"
            .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false));

            "Then there should be no exception"
            .x(() => e.Should().BeNull());

            "And there should be no context errors"
            .x(() => context.Errors.Should().HaveCount(0));
        }
        public void DP004ResolveApplicationDependenciesWithNoReferencingApplicationResourceWithErrors(DP004ApplicationDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e)
        {
            "Given a source model with an application resource with the wrong key"
            .x(() =>
            {
                model     = TestHelper.CreateDefaultModelForAnalyzing();
                var group = model.GetSourceModel <ParsedBizTalkApplicationGroup>();
                group.Applications[1].Application.ApplicationDefinition.Resource = null;      // Lose pointer to the resource.
            });

            "And a context"
            .x(() => context = TestHelper.BuildContext());

            "And a logger"
            .x(() => logger = _mockLogger.Object);

            "And an analyzer"
            .x(() => analyzer = new DP004ApplicationDependencyAnalyzer(model, context, logger));

            "When analyzing"
            .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false));

            "Then there should be no exception"
            .x(() => e.Should().BeNull());

            "And there should be an error"
            .x(() => context.Errors.Should().HaveCount(1));

            "And report resource node should not have the expected relationships created"
            .x(() =>
            {
                // Test the errors
                context.Errors.Count.Should().Be(1);
                context.Errors[0].Message.Should().Contain("app-resource-2");
            });
        }