public void ParseWithOneApplicationAndNoOrchestrations(BizTalkOrchestrationParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with one application and no orchestrations"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;
                group.Applications.Add(new ParsedBizTalkApplication {
                    Application = new BizTalkApplication()
                });
            });

            "And a logger"
            .x(() => logger = new Mock <ILogger>().Object);

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

            "And a BizTalk Orchestration Parser"
            .x(() => parser = new BizTalkOrchestrationParser(model, context, logger));

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

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

            "And the error count should be 0"
            .x(() =>
            {
                context.Errors.Should().BeNullOrEmpty();
            });
        }
        public void ParseIsSkippedIfModelIsMissing(BizTalkOrchestrationParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
            });

            "And a logger"
            .x(() => logger = new Mock <ILogger>().Object);

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

            "And a parser"
            .x(() => parser = new BizTalkOrchestrationParser(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 = new Mock <ILogger>().Object);

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

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

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

            "Then the parser constructor should succeed"
            .x(() =>
            {
                e.Should().BeNull();
                parser.Should().NotBeNull();
            });
        }
        public void ParseWithTwoApplicationsAndOneOrchestration(BizTalkOrchestrationParser parser, ILogger logger, MigrationContext context, BizTalkApplication applicationOne, BizTalkApplication applicationTwo, MetaModel metaModel, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;
            });

            "And a logger"
            .x(() => logger = new Mock <ILogger>().Object);

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

            "And an application with one orchestration with a valid ODX"
            .x(() =>
            {
                metaModel = new MetaModel
                {
                    Core    = "Core",
                    Element = new Element[]
                    {
                        new Element {
                            Type = MetaModelConstants.ElementTypeModule
                        }
                    },
                    MajorVersion = "MajorVersion",
                    MinorVersion = "MinorVersion"
                };

                var msiContainer = new ResourceContainer()
                {
                    Key = "TestMsi.Key", Name = "TestMsi", Type = ModelConstants.ResourceContainerMsi, ContainerLocation = @"C:\Test\Test.msi"
                };
                model.MigrationSource.ResourceContainers.Add(msiContainer);

                var cabContainer = new ResourceContainer()
                {
                    Key = "TestCab.Key", Name = "TestCab", Type = ModelConstants.ResourceContainerCab, ContainerLocation = @"C:\Test\Test.CAB"
                };
                msiContainer.ResourceContainers.Add(cabContainer);

                var asmContainer = new ResourceContainer()
                {
                    Key = "TestAssembly.Key", Name = "TestAssembly", Type = ModelConstants.ResourceContainerAssembly, ContainerLocation = @"C:\Test\Test.dll"
                };
                cabContainer.ResourceContainers.Add(asmContainer);

                var orchestration = new ResourceDefinition()
                {
                    Key = "TestOrchestration.Key", Name = "TestOrchestration", Type = ModelConstants.ResourceDefinitionOrchestration, ResourceContent = SerializeToString(metaModel)
                };
                asmContainer.ResourceDefinitions.Add(orchestration);

                applicationOne = new BizTalkApplication()
                {
                    Name = "ApplicationOne"
                };
                applicationOne.Orchestrations.Add(new Orchestration(asmContainer.Key, orchestration.Key)
                {
                    Name = "OrchestrationOne"
                });
                applicationOne.ApplicationDefinition = new ApplicationDefinitionFile {
                    ResourceKey = "ResourceKey"
                };

                var parsedApplication = new ParsedBizTalkApplication
                {
                    Application = applicationOne
                };
                group.Applications.Add(parsedApplication);

                var container = new ResourceContainer();
                container.ResourceDefinitions.Add(new ResourceDefinition());
                container.ResourceDefinitions[0].Resources.Add(new ResourceItem {
                    Key = "ResourceKey"
                });
                model.MigrationSource.ResourceContainers.Add(container);
            });

            "And an application with no orchestrations"
            .x(() =>
            {
                applicationTwo = new BizTalkApplication()
                {
                    Name = "ApplicationTwo"
                };

                group.Applications.Add(
                    new ParsedBizTalkApplication
                {
                    Application = applicationTwo
                });
            });

            "And a BizTalk Orchestration Parser"
            .x(() => parser = new BizTalkOrchestrationParser(model, context, logger));

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

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

            "And the error count should be 0"
            .x(() =>
            {
                context.Errors.Should().BeNullOrEmpty();
            });

            "And the model on the orchestration should be equivalent to the ODX for the first application"
            .x(() =>
            {
                // Validate the structure of the model.
                group.Applications[0].Application.Orchestrations.Should().NotBeNullOrEmpty().And.HaveCount(1);
                var orchestration = group.Applications[0].Application.Orchestrations[0];
                group.Applications[0].Application.Orchestrations[0].Model.Should().NotBeNull();

                // Validate the contents of the model.
                orchestration.Model.MajorVersion.Should().Be(metaModel.MajorVersion);
                orchestration.Model.MinorVersion.Should().Be(metaModel.MinorVersion);
                orchestration.Model.Core.Should().Be(metaModel.Core);
                orchestration.Model.Element.Should().NotBeNullOrEmpty();
                orchestration.Model.Element.Should().HaveCount(metaModel.Element.Length);
            });
        }
        public void ParseFailureInvalidXml(BizTalkOrchestrationParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with invalid XML"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;
                group.Applications.Add(new ParsedBizTalkApplication()
                {
                    Application = new BizTalkApplication()
                });

                var msiContainer = new ResourceContainer()
                {
                    Key = "TestMsi.Key", Name = "TestMsi", Type = ModelConstants.ResourceContainerMsi, ContainerLocation = @"C:\Test\Test.msi"
                };
                model.MigrationSource.ResourceContainers.Add(msiContainer);

                var cabContainer = new ResourceContainer()
                {
                    Key = "TestCab.Key", Name = "TestCab", Type = ModelConstants.ResourceContainerCab, ContainerLocation = @"C:\Test\Test.CAB"
                };
                msiContainer.ResourceContainers.Add(cabContainer);

                var asmContainer = new ResourceContainer()
                {
                    Key = "TestAssembly.Key", Name = "TestAssembly", Type = ModelConstants.ResourceContainerAssembly, ContainerLocation = @"C:\Test\Test.dll"
                };
                cabContainer.ResourceContainers.Add(asmContainer);

                var orchestration = new ResourceDefinition()
                {
                    Key = "TestOrchestration.Key", Name = "TestOrchestration", Type = ModelConstants.ResourceDefinitionOrchestration, ResourceContent = @"Not valid XML"
                };
                asmContainer.ResourceDefinitions.Add(orchestration);

                group.Applications[0].Application.Orchestrations.Add(new Orchestration(asmContainer.Key, orchestration.Key)
                {
                    Name = "Test Name"
                });
            });

            "And a logger"
            .x(() => logger = new Mock <ILogger>().Object);

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

            "And a BizTalk Orchestration Parser"
            .x(() => parser = new BizTalkOrchestrationParser(model, context, logger));

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

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

            "And the error count should be 1"
            .x(() =>
            {
                context.Errors.Should().NotBeNull().And.HaveCount(1);
            });

            "And the error should indicate a failure with parsing the XML"
            .x(() =>
            {
                context.Errors[0].Message.Should().Contain("error in XML document");
            });
        }