public void ParseSuccessfulOneReceivePort(PipelineDataParser parser, ILogger logger, List <ReceivePort> receivePorts, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with one receive port"
            .x(() =>
            {
                model        = new AzureIntegrationServicesModel();
                receivePorts = new List <ReceivePort> {
                    new ReceivePort()
                    {
                        Name = "Test Port"
                    }
                };
                group = CreateGroup(receivePorts.ToArray());
                model.MigrationSource.MigrationSourceModel = group;
            });

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

            "And a context"
            .x(() => context = new MigrationContext());

            "And a parser"
            .x(() => parser = new ReceivePortPipelineDataParser(model, context, logger));

            "When parsing"
            .x(() => e = Record.Exception(() => parser.Parse()));

            "Then the code should not throw an exception"
            .x(() => e.Should().BeNull());
        }
        public void ParseSuccessfulNoReceivePorts(PipelineDataParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with no receive ports"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = CreateGroup(Array.Empty <ReceivePort>());
                model.MigrationSource.MigrationSourceModel = group;
            });

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

            "And a context"
            .x(() => context = new MigrationContext());

            "And a parser"
            .x(() => parser = new ReceivePortPipelineDataParser(model, context, logger));

            "When parsing"
            .x(() => e = Record.Exception(() => parser.Parse()));

            "Then the code should not throw an exception"
            .x(() => e.Should().BeNull());

            "And the receive pipeline is still empty"
            .x(() => group.Applications[0].Application.Bindings.BindingInfo.ReceivePortCollection.Should().BeNullOrEmpty());
        }
        public void ParseOneReceivePortAndValidSendData(PipelineDataParser parser, ILogger logger, List <ReceivePort> receivePorts, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with one receive port valid send data XML"
            .x(() =>
            {
                model        = new AzureIntegrationServicesModel();
                receivePorts = new List <ReceivePort> {
                    new ReceivePort()
                    {
                        Name = "Test Port"
                    }
                };
                receivePorts[0].SendPipelineData = ValidData;
                group = CreateGroup(receivePorts.ToArray());
                model.MigrationSource.MigrationSourceModel = group;
            });

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

            "And a context"
            .x(() => context = new MigrationContext());

            "And a parser"
            .x(() => parser = new ReceivePortPipelineDataParser(model, context, logger));

            "When parsing"
            .x(() => e = Record.Exception(() => parser.Parse()));

            "Then the code should not throw an exception"
            .x(() => e.Should().BeNull());

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

            "And there should be valid send configuration"
            .x(() =>
            {
                receivePorts[0].SendPipelineCustomConfiguration.Should().NotBeNull();
                receivePorts[0].SendPipelineCustomConfiguration.Stages.Should().HaveCount(1);

                var rootStage = receivePorts[0].SendPipelineCustomConfiguration.Stages.FirstOrDefault();
                rootStage.Components.Should().NotBeNull();
                rootStage.Components[0].Should().NotBeNull();
                rootStage.Components[0].Name.Should().NotBeNullOrWhiteSpace();

                rootStage.Components[0].Properties.Should().HaveCount(1);
                var property = rootStage.Components[0].Properties.SingleOrDefault();
                property.Should().NotBeNull();
                property.Name.Should().NotBeNullOrWhiteSpace();
                property.Value.Should().NotBeNullOrWhiteSpace();
                property.ValueType.Should().NotBeNullOrWhiteSpace();
            });
        }
        public void ParseFailureMissingBindings(PipelineDataParser parser, ILogger logger, List <ReceivePort> receivePorts, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with one receive port"
            .x(() =>
            {
                model        = new AzureIntegrationServicesModel();
                receivePorts = new List <ReceivePort> {
                    new ReceivePort()
                    {
                        Name = "Test Port"
                    }
                };
                group = CreateGroup(receivePorts.ToArray());
                model.MigrationSource.MigrationSourceModel = group;
                group.Applications[0].Application.Bindings = null;     // Set this to be null to force the skip in processing
            });

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

            "And a context"
            .x(() => context = new MigrationContext());

            "And a parser"
            .x(() => parser = new ReceivePortPipelineDataParser(model, context, logger));

            "When parsing"
            .x(() => e = Record.Exception(() => parser.Parse()));

            "And the model should be parsed with a warning."
            .x(() =>
            {
                // There should be no exception logged - this is a handled scenario.
                context.Errors.Count.Should().Be(0);

                // The application definition cannot be read and so the name should be default
                var group = (ParsedBizTalkApplicationGroup)model.MigrationSource.MigrationSourceModel;
                group.Applications[0].Application.Name.Should().Be("(Unknown)");

                // An error should be logged
                var invocation = _mockLogger.Invocations.Where(i => i.Arguments[0].ToString() == "Warning").FirstOrDefault();
                invocation.Should().NotBeNull();
                invocation.Arguments[2].ToString().Should().Contain("Unable to find the binding info resource");
            });
        }
        public void ParseOneReceivePortAndInvalidSendData(PipelineDataParser parser, ILogger logger, List <ReceivePort> receivePorts, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with one receive port invalid send data XML"
            .x(() =>
            {
                model        = new AzureIntegrationServicesModel();
                receivePorts = new List <ReceivePort> {
                    new ReceivePort()
                    {
                        Name = "Test Port"
                    }
                };
                receivePorts[0].SendPipelineData = "Invalid XML";
                group = CreateGroup(receivePorts.ToArray());
                model.MigrationSource.MigrationSourceModel = group;
            });

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

            "And a context"
            .x(() => context = new MigrationContext());

            "And a parser"
            .x(() => parser = new ReceivePortPipelineDataParser(model, context, logger));

            "When parsing"
            .x(() => e = Record.Exception(() => parser.Parse()));

            "Then the code should not throw an exception"
            .x(() => e.Should().BeNull());

            "And there should be one error"
            .x(() =>
            {
                context.Errors.Should().HaveCount(1);
                context.Errors[0].Message.Should().Contain("Send");
            });
        }
        public void ParseIsSkippedIfModelIsMissing(ReceivePortPipelineDataParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
            });

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

            "And a context"
            .x(() => context = new MigrationContext());

            "And a parser"
            .x(() => parser = new ReceivePortPipelineDataParser(model, context, logger));

            "When parsing"
            .x(() => e = Record.Exception(() => parser.Parse()));

            "Then the code should not throw an exception"
            .x(() => e.Should().BeNull());
        }
        public void ConstructWithSuccess(IBizTalkParser parser, ILogger logger, IApplicationModel model, MigrationContext context, Exception e)
        {
            "Given a parser"
            .x(() => parser.Should().BeNull());

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

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

            "And a context"
            .x(() => context = new MigrationContext());

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

            "Then the parser constructor should succeed"
            .x(() =>
            {
                e.Should().BeNull();
                parser.Should().NotBeNull();
            });
        }