public void DP005ResolveDistributionListDependenciesMultipleMatches(DP005DistributionListDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e)
        {
            "Given a source model"
            .x(() =>
            {
                model        = TestHelper.CreateDefaultModelForAnalyzing();
                var sendPort = model.FindAllResources().Where(r => r.Type == ModelConstants.ResourceSendPort).Single();
                model.MigrationSource.ResourceContainers[0].ResourceDefinitions[7].Resources.Add(new ResourceItem()
                {
                    Type         = ModelConstants.ResourceSendPort,
                    ParentRefId  = sendPort.ParentRefId,
                    SourceObject = sendPort.SourceObject,
                    Name         = sendPort.Name
                });
            });

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

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

            "And an analyzer"
            .x(() => analyzer = new DP005DistributionListDependencyAnalyzer(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 resources should have the expected relationships created"
            .x(() =>
            {
                var distributionList = model.FindAllResources().Where(r => r.Type == ModelConstants.ResourceDistributionList).Single();
                var sendPort         = model.FindAllResources().Where(r => r.Type == ModelConstants.ResourceSendPort).First();

                // Check that the DL has the correct info
                distributionList.ResourceRelationships.Count.Should().Be(0);
                distributionList.ReportMessages.Count.Should().Be(1);
                distributionList.ReportMessages[0].Severity.Should().Be(MessageSeverity.Warning);
                distributionList.ReportMessages[0].Message.Should().Contain("Dependency cannot be accurately resolved.");

                // Check that the SP has the correct info
                sendPort.ResourceRelationships.Count.Should().Be(0);
                sendPort.ReportMessages.Count.Should().Be(0);
            });
        }
        /// <summary>
        /// Finds all resources in the resource, recursively.
        /// </summary>
        /// <param name="model">The source model.</param>
        /// <param name="key">The key for the resource to find.</param>
        /// <returns>A list of all discovered resources.</returns>
        public static ResourceItem FindResourceByKey(this AzureIntegrationServicesModel model, string key)
        {
            _ = model = model ?? throw new ArgumentNullException(nameof(model));
            var results = model.FindAllResources();

            return(results.Where(r => r.Key == key).FirstOrDefault());
        }
        public void DP005ResolveDistributionListDependenciesWithSuccess(DP005DistributionListDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e)
        {
            "Given a source model"
            .x(() =>
            {
                model = TestHelper.CreateDefaultModelForAnalyzing();
            });

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

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

            "And an analyzer"
            .x(() => analyzer = new DP005DistributionListDependencyAnalyzer(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 resources should have the expected relationships created"
            .x(() =>
            {
                // Test the applications
                var applications = model.GetSourceModel <ParsedBizTalkApplicationGroup>().Applications;
                applications.Should().NotBeNull().And.HaveCount(3);

                var distributionList = model.FindAllResources().Where(r => r.Type == ModelConstants.ResourceDistributionList).Single();
                var sendPort         = model.FindAllResources().Where(r => r.Type == ModelConstants.ResourceSendPort).Single();

                // Check that the DL has a relationship to the send port
                distributionList.ResourceRelationships.Count.Should().Be(1);
                distributionList.ResourceRelationships[0].ResourceRefId.Should().Be(sendPort.RefId);
                distributionList.ResourceRelationships[0].ResourceRelationshipType.Should().Be(ResourceRelationshipType.CallsTo);

                // Check that the SP has a relationship to the DL
                sendPort.ResourceRelationships.Count.Should().Be(1);
                sendPort.ResourceRelationships[0].ResourceRefId.Should().Be(distributionList.RefId);
                sendPort.ResourceRelationships[0].ResourceRelationshipType.Should().Be(ResourceRelationshipType.CalledBy);
            });
        }
        public void DP005ResolveDistributionListDependenciesNullSourceObject(DP005DistributionListDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e)
        {
            "Given a source model"
            .x(() =>
            {
                model = TestHelper.CreateDefaultModelForAnalyzing();
                // Null the source object to make the resource unfindable
                model.FindAllResources().Where(r => r.Type == ModelConstants.ResourceDistributionList).Single().SourceObject = null;
            });

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

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

            "And an analyzer"
            .x(() => analyzer = new DP005DistributionListDependencyAnalyzer(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 resources should have the expected relationships created"
            .x(() =>
            {
                var distributionList = model.FindAllResources().Where(r => r.Type == ModelConstants.ResourceDistributionList).Single();
                var sendPort         = model.FindAllResources().Where(r => r.Type == ModelConstants.ResourceSendPort).Single();

                // Check that the DL has the correct info
                distributionList.ResourceRelationships.Count.Should().Be(0);
                distributionList.ReportMessages.Count.Should().Be(1);
                distributionList.ReportMessages[0].Severity.Should().Be(MessageSeverity.Error);

                // Check that the SP has the correct info
                sendPort.ResourceRelationships.Count.Should().Be(0);
                sendPort.ReportMessages.Count.Should().Be(0);
            });
        }
        public void DP006ResolveDependenciesNoChildren(DP006ParentChildDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e)
        {
            "Given a source model"
            .x(() =>
            {
                model = TestHelper.CreateDefaultModelForAnalyzing();
                model.FindAllResources().Where(r => r.Type == ModelConstants.ResourceReceivePort).ToList().ForEach(r => r.Resources.Clear());      // Clears the children.
            });

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

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

            "And an analyzer"
            .x(() => analyzer = new DP006ParentChildDependencyAnalyzer(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 resources should have the expected relationships created"
            .x(() =>
            {
                // Test the resources
                var resources = model.FindAllResources();

                var receivePort = resources.Where(r => r.Type == ModelConstants.ResourceReceivePort).First();
                receivePort.Should().NotBeNull();

                // Check that the receive port has a parent-child to receive location
                receivePort.ResourceRelationships.Count.Should().Be(0);
            });
        }
 /// <summary>
 /// Gets all the resources of a given type within a resource container.
 /// </summary>
 /// <param name="model">The <see cref="ResourceContainer"/>.</param>
 /// <param name="type">The resource type to filter on.</param>
 /// <returns>A list of <see cref="ResourceItem"/> matching the pattern.</returns>
 public static IList <ResourceItem> FindResourcesByType(this AzureIntegrationServicesModel model, string type)
 {
     _ = model = model ?? throw new ArgumentNullException(nameof(model));
     return(model.FindAllResources().Where(r => r.Type == type).ToList());
 }