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 ParseFailureInvalidXml(BizTalkApplicationParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = new ParsedBizTalkApplicationGroup();
                group.Applications.Add(new ParsedBizTalkApplication()
                {
                    ResourceContainerKey = "MSI.key"
                });
                model.MigrationSource.MigrationSourceModel = group;

                var container = new ResourceContainer()
                {
                    Name = "Test", Key = "MSI.key", Type = ModelConstants.ResourceContainerMsi, ContainerLocation = @"C:\Test\Test.msi"
                };
                model.MigrationSource.ResourceContainers.Add(container);
                var adf      = "<this is not xml>";
                var resource = new ResourceDefinition()
                {
                    Key = "ADF.Key", Name = "ApplicationDefinition", Type = ModelConstants.ResourceDefinitionApplicationDefinition, ResourceContent = adf
                };
                container.ResourceDefinitions.Add(resource);

                group.Applications[0].Application.ApplicationDefinition = new ApplicationDefinitionFile(container.Key, resource.Key);
            });

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

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

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

            "When parsing with invalid XML in the bindings file"
            .x(() => e = Record.Exception(() => parser.Parse()));

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

            "And there should be an exception when parsing."
            .x(() =>
            {
                // There should be an exception logged.
                context.Errors.Count.Should().Be(1);

                // 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() == "Error").FirstOrDefault();
                invocation.Should().NotBeNull();
                invocation.Arguments[2].ToString().Should().Contain("An error occurred reading application from application definition file");
            });
        }
        /// <summary>
        /// Creates an empty group with the fields for parsing the application definition.
        /// </summary>
        /// <returns>A populated <see cref="ParsedBizTalkApplicationGroup"/>.</returns>
        private static ParsedBizTalkApplicationGroup CreateGroup()
        {
            var group       = new ParsedBizTalkApplicationGroup();
            var application = new ParsedBizTalkApplication
            {
                ResourceContainerKey = "TestApplicationKey"
            };

            group.Applications.Add(application);
            return(group);
        }
Esempio n. 4
0
        public void ParseFailureInvalidXml(PropertySchemaPropertyParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;

                model.MigrationSource.ResourceContainers.Add(new ResourceContainer()
                {
                    Key = "TestContainer.Key", Name = "TestContainer"
                });
                var content = "<invalid-xml><b:schemaInfo schema_type=\"property\" xmlns:b=\"http://schemas.microsoft.com/BizTalk/2003\" />";
                model.MigrationSource.ResourceContainers[0].ResourceDefinitions.Add(new ResourceDefinition()
                {
                    Key = "TestSchema.Key", Name = "TestSchema", Type = ModelConstants.ResourceDefinitionSchema, ResourceContent = content
                });

                group.Applications.Add(new ParsedBizTalkApplication()
                {
                    Application = new BizTalkApplication()
                });
                group.Applications[0].Application.Schemas.Add(new Schema("TestContainer.Key", "TestSchema.Key")
                {
                    SchemaType = BizTalkSchemaType.Property
                });
            });

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

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

            "And a parser"
            .x(() => parser = new PropertySchemaPropertyParser(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 parser should have recorded an error when processing the filter."
            .x(() =>
            {
                context.Errors.Count.Should().Be(1);
            });
        }
Esempio n. 5
0
        public void ParseSuccessInvalidXmlInMessageSchema(PropertySchemaPropertyParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;

                model.MigrationSource.ResourceContainers.Add(new ResourceContainer()
                {
                    Key = "TestContainer.Key", Name = "TestContainer"
                });
                var content = "<invalid-xml>";
                model.MigrationSource.ResourceContainers[0].ResourceDefinitions.Add(new ResourceDefinition()
                {
                    Key = "TestSchema.Key", Name = "TestSchema", Type = ModelConstants.ResourceDefinitionSchema, ResourceContent = content
                });

                group.Applications.Add(new ParsedBizTalkApplication()
                {
                    Application = new BizTalkApplication()
                });
                group.Applications[0].Application.Schemas.Add(new Schema("TestContainer.Key", "TestSchema.Key"));
            });

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

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

            "And a parser"
            .x(() => parser = new PropertySchemaPropertyParser(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 parser should have recorded an error when processing the filter."
            .x(() =>
            {
                var item = group.Applications[0].Application.Schemas[0].SchemaType.Should().Be(BizTalkSchemaType.Unknown);     // haven't been able to ascertain the type
                context.Errors.Count.Should().Be(0);
            });
        }
        public void ParseFailureApplicationNameBlank(BizTalkApplicationParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;
                group.Applications.Add(new ParsedBizTalkApplication()
                {
                    ResourceContainerKey = "TestMsi.Key",
                });
                model.MigrationSource.MigrationSourceModel = group;

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

                var adf      = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ApplicationDefinition xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://Microsoft.BizTalk.ApplicationDeployment/ApplicationDefinition.xsd\">  <Properties>    <Property Name=\"DisplayName\" Value=\"\" />    <Property Name=\"Guid\" Value=\"{319AC06C-0FAB-4B68-B2C9-2659DF322B63}\" />    <Property Name=\"Manufacturer\" Value=\"Generated by BizTalk Application Deployment\" />    <Property Name=\"Version\" Value=\"1.0.0.0\" />    <Property Name=\"ApplicationDescription\" Value=\"BizTalk Application 1\" />  </Properties>  <Resources>    <Resource Type=\"System.BizTalk:BizTalkBinding\" Luid=\"Application/SimpleMessagingApplication\">      <Properties>        <Property Name=\"IsDynamic\" Value=\"True\" />        <Property Name=\"IncludeGlobalPartyBinding\" Value=\"True\" />        <Property Name=\"ShortCabinetName\" Value=\"ITEM~0.CAB\" />        <Property Name=\"FullName\" Value=\"BindingInfo.xml\" />        <Property Name=\"Attributes\" Value=\"Archive\" />        <Property Name=\"CreationTime\" Value=\"2020-04-06 16:47:47Z\" />        <Property Name=\"LastAccessTime\" Value=\"2020-04-06 16:47:47Z\" />        <Property Name=\"LastWriteTime\" Value=\"2020-04-06 16:47:47Z\" />      </Properties>      <Files>        <File RelativePath=\"BindingInfo.xml\" Key=\"Binding\" />      </Files>    </Resource>  </Resources>  <References>    <Reference Name=\"BizTalk.System\" />    <Reference Name=\"Simple Referenced Application\" />  </References></ApplicationDefinition>";
                var resource = new ResourceDefinition()
                {
                    Key = "ApplicationDefinition.adf.Key", Name = "ApplicationDefinition.adf", Type = ModelConstants.ResourceDefinitionApplicationDefinition, ResourceContent = adf
                };
                msiContainer.ResourceDefinitions.Add(resource);

                group.Applications[0].Application.ApplicationDefinition = new ApplicationDefinitionFile(msiContainer.Key, resource.Key);
            });

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

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

            "And a parser"
            .x(() => parser = new BizTalkApplicationParser(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 context should have an error."
            .x(() => context.Errors.Count.Should().Be(1));
        }
        /// <summary>
        /// Resolves dependencies between schemas in transform and schemas in a BizTalk application.
        /// </summary>
        /// <param name="group">The group of BizTalk applications.</param>
        /// <param name="transform">The transform.</param>
        /// <param name="isSourceSchema">Is source (true) or target (false) schema list.</param>
        private void ResolveSchemaDependencies(ParsedBizTalkApplicationGroup group, Transform transform, bool isSourceSchema)
        {
            // Determine which schema list based on the isSource flag.
            var transformSchemas = isSourceSchema ? transform.SourceSchemaTypeNames : transform.TargetSchemaTypeNames;

            foreach (var transformSchema in transformSchemas)
            {
                // Find related schema in source model
                var schema = group.Applications.SelectMany(a => a.Application.Schemas).Where(s => transformSchema == s.FullName).FirstOrDefault();
                if (schema != null)
                {
                    // Defensive check
                    if (schema.Resource == null)
                    {
                        _logger.LogError(ErrorMessages.UnableToFindAssociatedResource, schema.GetType(), schema.Name, schema.ResourceKey);
                        Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindAssociatedResource, schema.GetType(), schema.Name, schema.ResourceKey)));
                        continue;
                    }

                    // Add relationships between transform resource and schema resource
                    var transformDirection = isSourceSchema ? ResourceRelationshipType.ReferencedBy : ResourceRelationshipType.ReferencesTo;
                    transform.Resource.AddRelationship(new ResourceRelationship(schema.Resource.RefId, transformDirection));

                    _logger.LogDebug(TraceMessages.RelationshipCreated, RuleName, transform.ResourceKey, schema.ResourceKey, transformDirection);

                    // Add reverse relationship between schema resource and transform resource
                    var schemaDirection = isSourceSchema ? ResourceRelationshipType.ReferencesTo : ResourceRelationshipType.ReferencedBy;
                    schema.Resource.AddRelationship(new ResourceRelationship(transform.Resource.RefId, schemaDirection));

                    _logger.LogDebug(TraceMessages.RelationshipCreated, RuleName, schema.ResourceKey, transform.ResourceKey, schemaDirection);
                }
                else
                {
                    // Add unresolved dependency message to transform resource
                    var warning = string.Format(CultureInfo.CurrentCulture, WarningMessages.SchemaReferencedByTransformIsMissing, transformSchema, transform.ResourceKey);
                    transform.Resource.ReportMessages.Add(new ReportMessage()
                    {
                        Severity = MessageSeverity.Warning, Message = warning
                    });
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a group with the fields for send port parsing.
        /// </summary>
        /// <param name="sendPortCollection">The send port collection.</param>
        /// <returns>A populated <see cref="ParsedBizTalkApplicationGroup"/>.</returns>
        private static ParsedBizTalkApplicationGroup CreateGroup(SendPort[] sendPortCollection)
        {
            var group       = new ParsedBizTalkApplicationGroup();
            var application = new ParsedBizTalkApplication()
            {
                Application = new BizTalkApplication
                {
                    Bindings = new BindingFile("TestContainer", "BindingInfo")
                    {
                        BindingInfo = new BindingInfo
                        {
                            SendPortCollection = sendPortCollection
                        }
                    }
                }
            };

            group.Applications.Add(application);
            return(group);
        }
        /// <summary>
        /// Creates a group with the fields for receive port parsing.
        /// </summary>
        /// <param name="receivePortCollection">The receive port collection.</param>
        /// <returns>A populated <see cref="ParsedBizTalkApplicationGroup"/>.</returns>
        private static ParsedBizTalkApplicationGroup CreateGroup(ReceivePort[] receivePortCollection)
        {
            var group = new ParsedBizTalkApplicationGroup();

            group.Applications.Add(new ParsedBizTalkApplication()
            {
                Application = new BizTalkApplication
                {
                    Bindings = new BindingFile("TestContainer", "BindingInfo")
                    {
                        BindingInfo = new BindingInfo
                        {
                            ReceivePortCollection = receivePortCollection
                        }
                    }
                }
            });

            return(group);
        }
        /// <summary>
        /// Creates a group with the fields for send port parsing.
        /// </summary>
        /// <returns>A populated <see cref="ParsedBizTalkApplicationGroup"/>.</returns>
        private static ParsedBizTalkApplicationGroup CreateGroup()
        {
            var group             = new ParsedBizTalkApplicationGroup();
            var application       = new ParsedBizTalkApplication();
            var bindingInfo       = new BindingInfo();
            var distributionLists = new List <DistributionList>
            {
                new DistributionList()
                {
                    Name = "Send Port Group 1", Filter = ""
                }
            };

            bindingInfo.DistributionListCollection = distributionLists.ToArray();
            application.Application.Bindings       = new BindingFile("TestContainer", "BindingInfo")
            {
                BindingInfo = bindingInfo
            };
            group.Applications.Add(application);
            return(group);
        }
        public void ParseSuccessfulSingleDistributionListAndFilter(DistributionListParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            var bindingResourceContainerKey  = "bindingResourceContainerKey";
            var bindingResourceDefinitionKey = "bindingResourceDefinitionKey";

            "Given a model with a filter on the distribution list"
            .x(() =>
            {
                var bindingInfo      = new BindingInfo();
                var distributionList = new List <DistributionList>
                {
                    new DistributionList()
                    {
                        ResourceKey = "distributionlistresourcekey",
                        Name        = "Distribution List 1",
                        Description = "Distribution List Description 1.",
                        Filter      = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<Filter xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n  <Group>\n    <Statement Property=\"AzureBlobStorage.BlobName\" Operator=\"0\" Value=\"Blobby\" />\n  </Group>\n</Filter>"
                    }
                };

                bindingInfo.DistributionListCollection = distributionList.ToArray();

                var application = new ParsedBizTalkApplication();
                application.Application.Bindings = new BindingFile(bindingResourceContainerKey, bindingResourceDefinitionKey)
                {
                    BindingInfo = bindingInfo
                };

                group = new ParsedBizTalkApplicationGroup();
                group.Applications.Add(application);

                model = new AzureIntegrationServicesModel();
                model.MigrationSource.MigrationSourceModel = group;

                var bindingResourceContainer = new ResourceContainer
                {
                    Key = bindingResourceContainerKey
                };

                var bindingResourceDefinition = new ResourceDefinition
                {
                    Key  = bindingResourceDefinitionKey,
                    Type = ModelConstants.ResourceDefinitionBindings
                };

                bindingResourceContainer.ResourceDefinitions.Add(bindingResourceDefinition);
                model.MigrationSource.ResourceContainers.Add(bindingResourceContainer);
            });

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

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

            "And a parser"
            .x(() => parser = new DistributionListParser(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 filter group should be correctly parsed."
            .x(() =>
            {
                var distributionList = group.Applications[0].Application.Bindings.BindingInfo.DistributionListCollection[0];
                distributionList.FilterExpression.Should().NotBeNull();
                distributionList.FilterExpression.Group.Should().NotBeNull();
                distributionList.FilterExpression.Group.Length.Should().Be(1);
                distributionList.FilterExpression.Group[0].Statement.Length.Should().Be(1);
                distributionList.FilterExpression.Group[0].Statement[0].Property.Should().Be("AzureBlobStorage.BlobName");
            });

            "And the resources should be set."
            .x(() =>
            {
                var appModel = (AzureIntegrationServicesModel)model;

                // Check the distribution list source has been created.
                appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Should().NotBeNullOrEmpty();
                appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Should().HaveCount(1);
                var distributionListResource = appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources[0];

                // Get the distribution list from the bindings.
                var distributionList = group.Applications[0].Application.Bindings.BindingInfo.DistributionListCollection[0];

                // Validate the distribution list resource.
                distributionListResource.Name.Should().Be(distributionList.Name);
                distributionListResource.Description.Should().Be(distributionList.Description);
                distributionListResource.Type.Should().Be(ModelConstants.ResourceDistributionList);
                distributionListResource.Key.Should().Be(distributionList.ResourceKey);

                distributionListResource.Resources.Should().NotBeNullOrEmpty();
                distributionListResource.Resources.Should().HaveCount(1);

                distributionList.Resource.Should().Be(distributionListResource);                                                               // The pointer to the resource should be set.
                distributionListResource.ParentRefId.Should().Be(appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].RefId); // The parent ref ID should be set.
                distributionListResource.SourceObject.Should().Be(distributionList);                                                           // The resource should have a pointer to the source object.

                // Validate the filter resource.
                var filterResource = distributionListResource.Resources[0];
                filterResource.Name.Should().StartWith(distributionListResource.Name);
                var expectedFilterKey = string.Concat(distributionListResource.Name, ":", "filter");
                filterResource.Key.Should().Be(expectedFilterKey);
                filterResource.Name.Should().EndWith("filter expression");
                filterResource.Type.Should().Be(ModelConstants.ResourceFilterExpression);

                distributionList.FilterExpression.Resource.Should().Be(filterResource);     // The pointer to the resource should be set.
                filterResource.ParentRefId.Should().Be(distributionListResource.RefId);     // The parent ref ID should be set.
                filterResource.SourceObject.Should().Be(distributionList.FilterExpression); // The resource should have a pointer to the source object.
            });
        }
        public void ParseServiceDeclarationWithAPortDeclarationSuccess(OrchestrationServiceDeclarationParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, Exception e)
        {
            var orchestrationDefinitionName = "orchestrationDefinitionName";
            var orchestrationDefinitionKey  = "orchestrationDefinitionKey";
            var serviceDeclarationName      = "serviceDeclarationName";
            var portDeclarationName         = "portDeclarationName";

            var asmContainerKey = "asmContainerKey";

            "Given a source model with an orchestration and a service declaration, with a port declaration"
            .x(() =>
            {
                var odxModel = new MetaModel
                {
                    Element = new Element[]
                    {
                        new Element
                        {
                            Type     = "Module",
                            Element1 = new Element[]
                            {
                                new Element
                                {
                                    Type     = "ServiceDeclaration",
                                    Property = new ElementProperty[]
                                    {
                                        new ElementProperty {
                                            Name = "Name", Value = serviceDeclarationName
                                        }
                                    },
                                    Element1 = new Element[]
                                    {
                                        new Element
                                        {
                                            Type     = "PortDeclaration",
                                            Property = new ElementProperty[]
                                            {
                                                new ElementProperty {
                                                    Name = "Name", Value = portDeclarationName
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                var orchestration = new Orchestration
                {
                    Name = orchestrationDefinitionName,
                    ResourceContainerKey  = asmContainerKey,
                    ResourceDefinitionKey = orchestrationDefinitionKey,
                    Model = odxModel
                };

                var parsedApplication = new ParsedBizTalkApplication
                {
                    Application = new BizTalkApplication()
                };

                parsedApplication.Application.Orchestrations.Add(orchestration);

                model     = new AzureIntegrationServicesModel();
                var group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;
                group.Applications.Add(parsedApplication);

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

            "And one orchestration in the source report model"
            .x(() =>
            {
                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 = asmContainerKey, Name = "TestAssembly", Type = ModelConstants.ResourceContainerAssembly, ContainerLocation = @"C:\Test\Test.dll"
                };
                cabContainer.ResourceContainers.Add(asmContainer);

                var orchestrationDefinition = new ResourceDefinition()
                {
                    Key  = orchestrationDefinitionKey,
                    Name = orchestrationDefinitionName,
                    Type = ModelConstants.ResourceDefinitionOrchestration
                };
                asmContainer.ResourceDefinitions.Add(orchestrationDefinition);

                var metaModel         = ((ParsedBizTalkApplicationGroup)model.MigrationSource.MigrationSourceModel).Applications[0].Application.Orchestrations[0].Model;
                var metaModelResource = new ResourceItem()
                {
                    Key  = string.Concat(orchestrationDefinitionKey, ":", MetaModelConstants.MetaModelRootElement),
                    Name = MetaModelConstants.MetaModelRootElement,
                    Type = ModelConstants.ResourceMetaModel
                };
                metaModel.Resource             = metaModelResource;
                metaModelResource.SourceObject = metaModel;
                orchestrationDefinition.Resources.Add(metaModelResource);

                var moduleResource = new ResourceItem()
                {
                    Key  = string.Concat(metaModelResource.Key, ":", MetaModelConstants.ElementTypeModule),
                    Name = MetaModelConstants.ElementTypeModule,
                    Type = ModelConstants.ResourceModule
                };
                metaModelResource.Resources.Add(moduleResource);
            });

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

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

            "And a parser"
            .x(() => parser = new OrchestrationServiceDeclarationParser(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 logged"
            .x(() => context.Errors.Should().BeNullOrEmpty());

            "And the resources should be set."
            .x(() =>
            {
                // Check the service declaration resource has been created.
                var moduleResource = model.FindResourcesByType(ModelConstants.ResourceModule).SingleOrDefault();
                moduleResource.Should().NotBeNull();
                var serviceDeclarationResource = model.FindResourcesByType(ModelConstants.ResourceServiceDeclaration).SingleOrDefault();
                serviceDeclarationResource.Should().NotBeNull();
                var serviceDeclaration = ((ParsedBizTalkApplicationGroup)model.MigrationSource.MigrationSourceModel).Applications[0].Application.Orchestrations[0].FindServiceDeclaration();

                // Validate the service declaration resource.
                serviceDeclarationResource.Should().NotBeNull();
                serviceDeclarationResource.Key.Should().Be(string.Concat(moduleResource.Key, ":", serviceDeclarationName));
                serviceDeclarationResource.Name.Should().Be(serviceDeclarationName);
                serviceDeclarationResource.Type.Should().Be(ModelConstants.ResourceServiceDeclaration);

                // Validate the port declaration resource.
                var portDeclarationNameResource = serviceDeclarationResource.Resources[0];
                portDeclarationNameResource.Name.Should().Be(portDeclarationName);
                portDeclarationNameResource.Type.Should().Be(ModelConstants.ResourcePortDeclaration);
                portDeclarationNameResource.Key.Should().StartWith(serviceDeclarationResource.Key);
            });
        }
        public void ParsePortTypeWithMissingModule(OrchestrationServiceDeclarationParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, Exception e)
        {
            var orchestrationDefinitionName = "orchestrationDefinitionName";
            var orchestrationDefinitionKey  = "orchestrationDefinitionKey";
            var asmContainerKey             = "asmContainerKey";
            var wrongKey = "wrongKey";

            "Given a source model with an orchestration with a missing module"
            .x(() =>
            {
                var orchestration = new Orchestration
                {
                    Name = orchestrationDefinitionName,
                    ResourceContainerKey  = asmContainerKey,
                    ResourceDefinitionKey = wrongKey
                };

                var parsedApplication = new ParsedBizTalkApplication
                {
                    Application = new BizTalkApplication()
                };

                parsedApplication.Application.Orchestrations.Add(orchestration);

                model     = new AzureIntegrationServicesModel();
                var group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;
                group.Applications.Add(parsedApplication);
            });

            "And one orchestration in the source report model"
            .x(() =>
            {
                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 = asmContainerKey, Name = "TestAssembly", Type = ModelConstants.ResourceContainerAssembly, ContainerLocation = @"C:\Test\Test.dll"
                };
                cabContainer.ResourceContainers.Add(asmContainer);

                var orchestrationDefinition = new ResourceDefinition()
                {
                    Key  = orchestrationDefinitionKey,
                    Name = orchestrationDefinitionName,
                    Type = ModelConstants.ResourceDefinitionOrchestration
                };
                asmContainer.ResourceDefinitions.Add(orchestrationDefinition);
            });

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

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

            "And a parser"
            .x(() => parser = new OrchestrationServiceDeclarationParser(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 an error logged"
            .x(() =>
            {
                context.Errors.Should().NotBeNull();
                context.Errors.Should().HaveCount(1);
                context.Errors[0].Message.Should().Contain(wrongKey);
                context.Errors[0].Message.Should().Contain(ModelConstants.ResourceModule);
            });
        }
        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);
            });
        }
Esempio n. 15
0
        private void UnpackMsiFiles(AzureIntegrationServicesModel model, MigrationContext context)
        {
            // Create new migration source object model
            var group = new ParsedBizTalkApplicationGroup();

            // Get MSI containers
            var msiContainers = model.MigrationSource.ResourceContainers.Where(c => c.Type == ModelConstants.ResourceContainerMsi).ToArray();

            foreach (var msiContainer in msiContainers)
            {
                if (_fileRepository.CheckFileExists(msiContainer.ContainerLocation))
                {
                    _logger.LogDebug(TraceMessages.UnpackingTheMsi, msiContainer.ContainerLocation);

                    try
                    {
                        // Create application in source model
                        var application = new ParsedBizTalkApplication();
                        group.Applications.Add(application);

                        // Set new working folder
                        var appWorkingFolder = Path.Combine(context.WorkingFolder, msiContainer.Name);

                        // Create a folder for the application
                        application.WorkingFolder = _fileRepository.CreateApplicationWorkingFolder(appWorkingFolder, application.Id.ToString()).FullName;

                        // Set resource container reference
                        application.ResourceContainerKey = msiContainer.Key;

                        // Extract files in MSI file
                        var msiFiles = _fileRepository.ExtractFilesInMsi(msiContainer.ContainerLocation, application.WorkingFolder);
                        foreach (var msiFile in msiFiles.Select(f => new FileInfo(f)).GroupBy(f => f.FullName).Select(f => f.First()))
                        {
                            var resourceName = Path.GetFileNameWithoutExtension(msiFile.Name);
                            var resourceKey  = string.Concat(msiContainer.Name, ":", resourceName);

                            if (msiFile.Extension == MsiDiscoverer.ApplicationDefinitionFileExtension)
                            {
                                // Application definition file
                                var adfFileContents       = _fileRepository.ReadAdfFile(msiFile.FullName);
                                var adfResourceDefinition = new ResourceDefinition()
                                {
                                    Key = resourceKey, Name = resourceName, Type = ModelConstants.ResourceDefinitionApplicationDefinition, ResourceContent = adfFileContents
                                };
                                msiContainer.ResourceDefinitions.Add(adfResourceDefinition);

                                // Set resource container and definition references
                                application.Application.ApplicationDefinition = new ApplicationDefinitionFile(msiContainer.Key, adfResourceDefinition.Key);

                                _logger.LogDebug(TraceMessages.CreatedTheApplicationResourceDefinition, application.Application.ApplicationDefinition.ResourceDefinitionKey);
                            }
                            else if (msiFile.Extension != MsiDiscoverer.CabinetFileExtension)
                            {
                                // Any other file, just add as a file resource
                                var resourceDefinition = new ResourceDefinition()
                                {
                                    Key = resourceKey, Name = resourceName, Type = ModelConstants.ResourceDefinitionFile, ResourceContent = msiFile.FullName
                                };
                                msiContainer.ResourceDefinitions.Add(resourceDefinition);

                                _logger.LogDebug(TraceMessages.CreatedTheResourceDefinition, resourceDefinition.Key);
                            }
                        }

                        // Get CAB files
                        var cabFiles = _fileRepository.GetCabFiles(application.WorkingFolder);
                        foreach (var cabFile in cabFiles.Select(f => new FileInfo(f)).GroupBy(f => f.FullName).Select(f => f.First()))
                        {
                            // Add resource container
                            var containerName = Path.GetFileNameWithoutExtension(cabFile.Name);
                            var containerKey  = string.Concat(msiContainer.Key, ":", containerName);
                            var cabContainer  = new ResourceContainer()
                            {
                                Key = containerKey, Name = containerName, Type = ModelConstants.ResourceContainerCab, ContainerLocation = cabFile.FullName
                            };
                            msiContainer.ResourceContainers.Add(cabContainer);

                            // Set resource container reference
                            application.Application.ResourceContainerKeys.Add(cabContainer.Key);

                            // Now extract files in Cabinet file
                            var cabPath = Path.Combine(application.WorkingFolder, Path.GetFileNameWithoutExtension(cabFile.Name));

                            _logger.LogDebug(TraceMessages.ExtractingCabFilesFromPath, cabPath);

                            var files = _fileRepository.ExtractFilesInCab(cabFile.FullName, cabPath);
                            foreach (var file in files.Select(f => new FileInfo(f)).GroupBy(f => f.FullName).Select(f => f.First()))
                            {
                                var name = Path.GetFileNameWithoutExtension(file.Name);
                                var key  = string.Concat(cabContainer.Key, ":", name);

                                if (file.Name == MsiDiscoverer.BindingFileName)
                                {
                                    // Binding file
                                    var bindingFileContents       = _fileRepository.ReadBindingFile(file.FullName);
                                    var bindingResourceDefinition = new ResourceDefinition()
                                    {
                                        Key = key, Name = name, Type = ModelConstants.ResourceDefinitionBindings, ResourceContent = bindingFileContents
                                    };
                                    cabContainer.ResourceDefinitions.Add(bindingResourceDefinition);

                                    // Set resource container and definition references
                                    application.Application.Bindings = new BindingFile(cabContainer.Key, bindingResourceDefinition.Key);

                                    _logger.LogDebug(TraceMessages.DiscoveredTheBindingFile, bindingResourceDefinition.Key);
                                }
                                else if (file.Extension == MsiDiscoverer.AssemblyFileExtension)
                                {
                                    // Assembly file
                                    var asmContainer = new ResourceContainer()
                                    {
                                        Key = key, Name = name, Type = ModelConstants.ResourceContainerAssembly, ContainerLocation = file.FullName
                                    };
                                    cabContainer.ResourceContainers.Add(asmContainer);

                                    // Set resource container.
                                    application.Application.Assemblies.Add(new AssemblyFile(asmContainer.Key));

                                    _logger.LogDebug(TraceMessages.DiscoveredTheAssembly, asmContainer.Key);
                                }
                                else
                                {
                                    // Any other file, just add as a file resource
                                    cabContainer.ResourceDefinitions.Add(new ResourceDefinition()
                                    {
                                        Key = key, Name = name, Type = ModelConstants.ResourceDefinitionFile, ResourceContent = file.FullName
                                    });
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ErrorProcessingMSIFile, msiContainer.ContainerLocation, ex.ToString());
                        context.Errors.Add(new ErrorMessage(message));
                        _logger.LogError(message);
                    }
                }
                else
                {
                    var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ErrorMsiNotFound, msiContainer.ContainerLocation);
                    context.Errors.Add(new ErrorMessage(message));
                    _logger.LogError(message);
                }
            }

            model.MigrationSource.MigrationSourceModel = group;
        }
        public void ParseFailureMissingBindings(DistributionListParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            var bindingResourceContainerKey  = "bindingResourceContainerKey";
            var bindingResourceDefinitionKey = "bindingResourceDefinitionKey";

            "Given a model with a filter on the distribution list"
            .x(() =>
            {
                var bindingInfo      = new BindingInfo();
                var distributionList = new List <DistributionList>
                {
                    new DistributionList()
                    {
                        ResourceKey = "distributionlistresourcekey",
                        Name        = "Distribution List 1",
                        Description = "Distribution List Description 1.",
                        Filter      = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<Filter xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n  <Group>\n    <Statement Property=\"AzureBlobStorage.BlobName\" Operator=\"0\" Value=\"Blobby\" />\n  </Group>\n</Filter>"
                    }
                };

                bindingInfo.DistributionListCollection = distributionList.ToArray();

                var application = new ParsedBizTalkApplication();

                group = new ParsedBizTalkApplicationGroup();
                group.Applications.Add(application);

                model = new AzureIntegrationServicesModel();
                model.MigrationSource.MigrationSourceModel = group;

                var bindingResourceContainer = new ResourceContainer
                {
                    Key = bindingResourceContainerKey
                };

                var bindingResourceDefinition = new ResourceDefinition
                {
                    Key  = bindingResourceDefinitionKey,
                    Type = ModelConstants.ResourceDefinitionBindings
                };

                bindingResourceContainer.ResourceDefinitions.Add(bindingResourceDefinition);
                model.MigrationSource.ResourceContainers.Add(bindingResourceContainer);
            });

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

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

            "And a parser"
            .x(() => parser = new DistributionListParser(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 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");
            });
        }
Esempio n. 17
0
        public void ParseSuccessfulPropertySchema(PropertySchemaPropertyParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;

                model.MigrationSource.ResourceContainers.Add(new ResourceContainer()
                {
                    Key = "TestContainer.Key", Name = "TestContainer"
                });
                var content = "<?xml version=\"1.0\" encoding=\"utf-16\"?><xs:schema xmlns=\"http://Microsoft.AzureIntegrationMigration.BizTalk.TestApps.Schemas.PropertySchema1\" xmlns:b=\"http://schemas.microsoft.com/BizTalk/2003\" targetNamespace=\"https://Microsoft.AzureIntegrationMigration.BizTalk.TestApps.Schemas.PropertySchema1\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><xs:annotation><xs:appinfo><b:schemaInfo schema_type=\"property\" xmlns:b=\"http://schemas.microsoft.com/BizTalk/2003\" /></xs:appinfo></xs:annotation><xs:element name=\"TestStringProperty1\" type=\"xs:string\"><xs:annotation><xs:appinfo><b:fieldInfo propertyGuid=\"4efaeaed-05b9-4fe5-b05f-677b5d9e2a6b\" /></xs:appinfo></xs:annotation></xs:element><xs:element name=\"TestIntegerProperty1\" type=\"xs:int\"><xs:annotation><xs:appinfo><b:fieldInfo propertyGuid=\"bb67d7e6-103a-4567-a405-6d854bc02d5d\" /></xs:appinfo></xs:annotation></xs:element><xs:element name=\"TestBoolProperty1\" type=\"xs:boolean\"><xs:annotation><xs:appinfo><b:fieldInfo propertyGuid=\"5f6fbe77-d32b-4ff3-a9b4-e9602c7aa52f\" /></xs:appinfo></xs:annotation></xs:element></xs:schema>";
                model.MigrationSource.ResourceContainers[0].ResourceDefinitions.Add(new ResourceDefinition()
                {
                    Key = "TestSchema.Key", Name = "TestSchema", Type = ModelConstants.ResourceDefinitionSchema, ResourceContent = content
                });

                group.Applications.Add(new ParsedBizTalkApplication()
                {
                    Application = new BizTalkApplication()
                });
                group.Applications[0].Application.Schemas.Add(new Schema("TestContainer.Key", "TestSchema.Key")
                {
                    SchemaType = BizTalkSchemaType.Property,
                    Namespace  = "TestNamespace",
                    Name       = "TestPropertySchema",
                    FullName   = "TestNamespace.TestSchema"
                });
            });

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

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

            "And a parser"
            .x(() => parser = new PropertySchemaPropertyParser(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 property schema should be correctly parsed."
            .x(() =>
            {
                var schema = group.Applications[0].Application.Schemas[0];
                schema.SchemaType.Should().Be(BizTalkSchemaType.Property);
                schema.ContextProperties.Count.Should().Be(3);
                schema.ContextProperties[0].PropertyName.Should().Be("TestStringProperty1");
                schema.ContextProperties[0].DataType.Should().Be("xs:string");
                schema.ContextProperties[0].FullyQualifiedName.Should().Be("TestNamespace.TestStringProperty1");
                schema.ContextProperties[1].PropertyName.Should().Be("TestIntegerProperty1");
                schema.ContextProperties[1].DataType.Should().Be("xs:int");
                schema.ContextProperties[1].FullyQualifiedName.Should().Be("TestNamespace.TestIntegerProperty1");
                schema.ContextProperties[2].PropertyName.Should().Be("TestBoolProperty1");
                schema.ContextProperties[2].DataType.Should().Be("xs:boolean");
                schema.ContextProperties[2].FullyQualifiedName.Should().Be("TestNamespace.TestBoolProperty1");

                // Check that the resources have been created
                var resourceDefinition = model.MigrationSource.ResourceContainers[0].ResourceDefinitions[0];
                resourceDefinition.Resources.Count.Should().Be(1);
                resourceDefinition.Resources[0].Name.Should().Be(schema.Name);
                resourceDefinition.Resources[0].Resources.Count.Should().Be(3);
                resourceDefinition.Resources[0].Resources[0].Name.Should().Be("TestStringProperty1");
                resourceDefinition.Resources[0].Resources[1].Name.Should().Be("TestIntegerProperty1");
                resourceDefinition.Resources[0].Resources[2].Name.Should().Be("TestBoolProperty1");
                var schemaResource = resourceDefinition.Resources[0];

                schema.Resource.Should().Be(schemaResource);                      // The pointer to the resource should be set.
                schemaResource.ParentRefId.Should().Be(resourceDefinition.RefId); // The parent ref ID should be set.
                schemaResource.SourceObject.Should().Be(schema);                  // The resource should have a pointer to the source object.
            });
        }
Esempio n. 18
0
        public void ParseSuccessfulEmptyFilterString(SendPortParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            var bindingResourceContainerKey  = "bindingResourceContainerKey";
            var bindingResourceDefinitionKey = "bindingResourceDefinitionKey";

            "Given a model with send port definied in the binding and no filter expression"
            .x(() =>
            {
                var bindingInfo = new BindingInfo();
                var sendPorts   = new List <SendPort>
                {
                    new SendPort()
                    {
                        Name             = "Send Port 1",
                        PrimaryTransport = new TransportInfo
                        {
                            TransportType = new ProtocolType
                            {
                                Name = "transportName"
                            }
                        },
                        IsTwoWay = false
                    }
                };

                bindingInfo.SendPortCollection = sendPorts.ToArray();

                var application = new ParsedBizTalkApplication();
                application.Application.Bindings = new BindingFile(bindingResourceContainerKey, bindingResourceDefinitionKey)
                {
                    BindingInfo = bindingInfo
                };

                group = new ParsedBizTalkApplicationGroup();
                group.Applications.Add(application);

                model = new AzureIntegrationServicesModel();
                model.MigrationSource.MigrationSourceModel = group;

                var bindingResourceContainer = new ResourceContainer
                {
                    Key = bindingResourceContainerKey
                };

                var bindingResourceDefinition = new ResourceDefinition
                {
                    Key  = bindingResourceDefinitionKey,
                    Type = ModelConstants.ResourceDefinitionBindings
                };

                bindingResourceContainer.ResourceDefinitions.Add(bindingResourceDefinition);
                model.MigrationSource.ResourceContainers.Add(bindingResourceContainer);

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

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

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

            "And a parser"
            .x(() => parser = new SendPortParser(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 filter group should be null - nothing created."
            .x(() =>
            {
                var sendPort = group.Applications[0].Application.Bindings.BindingInfo.SendPortCollection[0];
                sendPort.FilterExpression.Should().BeNull();
                context.Errors.Count.Should().Be(0);
            });

            "And the resources should be set."
            .x(() =>
            {
                var appModel = (AzureIntegrationServicesModel)model;

                // Check the send port source has been created.
                appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Should().NotBeNullOrEmpty();
                appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Should().HaveCount(1);
                var sendPortSource = appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources[0];

                // Get the send port from the bindings.
                var sendPort = group.Applications[0].Application.Bindings.BindingInfo.SendPortCollection[0];

                // Validate the send port source.
                sendPortSource.Name.Should().Be(sendPort.Name);
                sendPortSource.Description.Should().Be(sendPort.Description);
                sendPortSource.Type.Should().Be(ModelConstants.ResourceSendPort);
                sendPortSource.Key.Should().Be(sendPort.ResourceKey);

                sendPortSource.Resources.Should().BeNullOrEmpty();

                sendPortSource.Properties.Should().ContainKey("Direction");
                sendPortSource.Properties["Direction"].Should().Be("One-Way");
            });
        }
Esempio n. 19
0
        /// <summary>
        /// Creates a default object model for parsing and building a report.
        /// </summary>
        /// <returns></returns>
        public static AzureIntegrationServicesModel CreateDefaultModelForParsing()
        {
            var aisModel = new AzureIntegrationServicesModel();

            // Create a report node with a resource container and resource definitions
            var resourceContainer = new ResourceContainer()
            {
                Name        = "TestApp1.msi",
                Description = "This is the description of the MSI.",
                Type        = ModelConstants.ResourceContainerMsi,
                Key         = "test-app-1-container-key"
            };

            aisModel.MigrationSource.ResourceContainers.Add(resourceContainer);

            var appResourceDefinition1 = new ResourceDefinition()
            {
                Name        = "App 1 Resource Definition",
                Key         = $"{resourceContainer.Key}:app-1",
                Description = "App 1 Description",
                Type        = ModelConstants.ResourceDefinitionApplicationDefinition
            };

            resourceContainer.ResourceDefinitions.Add(appResourceDefinition1);

            var appResource1 = new ResourceItem
            {
                Name        = "App 1 Resource Definition Application",
                Key         = $"{appResourceDefinition1.Key}:app-resource-1",
                Description = "App 1 Resource Description",
                Type        = ModelConstants.ResourceApplication
            };

            appResourceDefinition1.Resources.Add(appResource1);

            var appResourceDefinition2 = new ResourceDefinition()
            {
                Name        = "App 2 Resource Definition",
                Key         = $"{resourceContainer.Key}:app-2",
                Description = "App 2 Description",
                Type        = ModelConstants.ResourceDefinitionApplicationDefinition
            };

            resourceContainer.ResourceDefinitions.Add(appResourceDefinition2);

            var appResource2 = new ResourceItem
            {
                Name        = "App 2 Resource Definition Application",
                Key         = $"{appResourceDefinition2.Key}:app-resource-2",
                Description = "App 1 Resource Description",
                Type        = ModelConstants.ResourceApplication
            };

            appResourceDefinition2.Resources.Add(appResource2);

            var appResourceDefinition3 = new ResourceDefinition()
            {
                Name        = "App 3 Resource Definition",
                Key         = $"{resourceContainer.Key}:app-3",
                Description = "App 3 Description",
                Type        = ModelConstants.ResourceDefinitionApplicationDefinition
            };

            resourceContainer.ResourceDefinitions.Add(appResourceDefinition3);

            var appResource3 = new ResourceItem
            {
                Name        = "App 3 Resource Definition Application",
                Key         = $"{appResourceDefinition3.Key}:pp-resource-3",
                Description = "App 3 Resource Description",
                Type        = ModelConstants.ResourceApplication
            };

            appResourceDefinition3.Resources.Add(appResource3);

            var schemaResourceDefinition1 = new ResourceDefinition()
            {
                Name        = "DocumentSchema1",
                Description = "This is document schema 1.",
                Type        = ModelConstants.ResourceDefinitionSchema,
                Key         = $"{resourceContainer.Key}:document-schema-1"
            };

            resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition1);

            var schemaResource1 = new ResourceItem()
            {
                Name        = "DocumentSchema1",
                Description = "This is document schema 1.",
                Type        = ModelConstants.ResourceDocumentSchema,
                Key         = $"{schemaResourceDefinition1.Key}:document-schema-1:schema"
            };

            schemaResourceDefinition1.Resources.Add(schemaResource1);

            var schemaResourceDefinition2 = new ResourceDefinition()
            {
                Name        = "DocumentSchema2",
                Description = "This is document schema 2.",
                Type        = ModelConstants.ResourceDefinitionSchema,
                Key         = $"{resourceContainer.Key}:document-schema-2"
            };

            resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition2);

            var schemaResource2 = new ResourceItem()
            {
                Name        = "DocumentSchema2",
                Description = "This is document schema 2.",
                Type        = ModelConstants.ResourceDocumentSchema,
                Key         = $"{schemaResourceDefinition2.Key}:document-schema-2:schema"
            };

            schemaResourceDefinition2.Resources.Add(schemaResource2);

            var schemaResourceDefinition3 = new ResourceDefinition()
            {
                Name        = "PropertySchema1",
                Description = "This is property schema 1.",
                Type        = ModelConstants.ResourceDefinitionSchema,
                Key         = $"{resourceContainer.Key}:property-schema-1"
            };

            resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition3);

            var schemaResource3 = new ResourceItem()
            {
                Name        = "PropertySchema1",
                Description = "This is property schema 2.",
                Type        = ModelConstants.ResourceDocumentSchema,
                Key         = $"{schemaResourceDefinition3.Key}:property-schema-1:schema"
            };

            schemaResourceDefinition3.Resources.Add(schemaResource3);

            var schemaResource3Property1 = new ResourceItem()
            {
                Name        = "Property1",
                Description = "This is property 2",
                Type        = ModelConstants.ResourcePropertySchema,
                Key         = $"{schemaResourceDefinition3.Key}:property-schema-1:schema:Property1"
            };

            schemaResourceDefinition3.Resources.Add(schemaResource3Property1);

            var schemaResource3Property2 = new ResourceItem()
            {
                Name        = "Property2",
                Description = "This is property 2",
                Type        = ModelConstants.ResourcePropertySchema,
                Key         = $"{schemaResourceDefinition3.Key}:property-schema-1:schema:Property2"
            };

            schemaResourceDefinition3.Resources.Add(schemaResource3Property2);

            var transformResourceDefinition1 = new ResourceDefinition()
            {
                Name        = "Transform1",
                Description = "This is transform 1.",
                Type        = ModelConstants.ResourceDefinitionMap,
                Key         = $"{resourceContainer.Key}:transform-1"
            };

            resourceContainer.ResourceDefinitions.Add(transformResourceDefinition1);

            var transformResource1 = new ResourceItem()
            {
                Name        = "Transform1",
                Description = "This is the transform 1, resource",
                Type        = ModelConstants.ResourceMap,
                Key         = $"{transformResourceDefinition1.Key}:transform-1-resource"
            };

            transformResourceDefinition1.Resources.Add(transformResource1);

            var bindingResourceDefinition1 = new ResourceDefinition()
            {
                Name        = "Binding1",
                Description = "This is binding 1.",
                Type        = ModelConstants.ResourceDefinitionBindings,
                Key         = $"{resourceContainer.Key}:binding-1"
            };

            resourceContainer.ResourceDefinitions.Add(bindingResourceDefinition1);

            var sendPortResource1 = new ResourceItem()
            {
                Name        = "SendPort1",
                Description = "This is sendport 1.",
                Type        = ModelConstants.ResourceSendPort,
                Key         = $"{bindingResourceDefinition1.Key}:sendport-1"
            };

            bindingResourceDefinition1.Resources.Add(sendPortResource1);

            var sendPortFilterResource1 = new ResourceItem()
            {
                Name        = "SendPort1-Filter",
                Description = "This is sendport 1, filter expression",
                Type        = ModelConstants.ResourceFilterExpression,
                Key         = $"{sendPortResource1.Key}:sendport-1-filter"
            };

            sendPortResource1.Resources.Add(sendPortFilterResource1);

            var receivePortResource1 = new ResourceItem()
            {
                Name        = "ReceivePort1",
                Description = "This is receive port 1.",
                Type        = ModelConstants.ResourceReceivePort,
                Key         = $"{bindingResourceDefinition1.Key}:receiveport-1"
            };

            bindingResourceDefinition1.Resources.Add(receivePortResource1);

            var receiveLocation1 = new ResourceItem()
            {
                Name        = "ReceiveLocation1",
                Description = "This is receive location 1.",
                Type        = ModelConstants.ResourceReceiveLocation,
                Key         = $"{receivePortResource1.Key}:receivelocation-1"
            };

            receivePortResource1.Resources.Add(receiveLocation1);

            var distributionListResource1 = new ResourceItem
            {
                Name        = "DistributionList1",
                Description = "This is distributionlist 1.",
                Type        = ModelConstants.ResourceDistributionList,
                Key         = $"{bindingResourceDefinition1.Key}:distributionlist-1"
            };

            bindingResourceDefinition1.Resources.Add(distributionListResource1);

            var distributionListFilterResource1 = new ResourceItem
            {
                Name        = "DistributionListFilter1",
                Description = "This is distribution list filer 1.",
                Type        = ModelConstants.ResourceFilterExpression,
                Key         = $"{distributionListResource1.Key}:distributionlistfilter-1"
            };

            distributionListResource1.Resources.Add(distributionListFilterResource1);

            // Create a parsed BizTalk Application Group
            var applicationGroup = new ParsedBizTalkApplicationGroup();

            aisModel.MigrationSource.MigrationSourceModel = applicationGroup;

            // Create applications
            var application1 = new ParsedBizTalkApplication();

            application1.Application.Name = "Test App 1";
            applicationGroup.Applications.Add(application1);

            var application2 = new ParsedBizTalkApplication();

            application2.Application.Name     = "Test App 2";
            application2.Application.Bindings = new BindingFile {
                BindingInfo = new BindingInfo()
            };

            applicationGroup.Applications.Add(application2);

            var application3 = new ParsedBizTalkApplication();

            application3.Application.Name = "Test App 3";
            applicationGroup.Applications.Add(application3);
            application3.Application.Bindings = new BindingFile {
                BindingInfo = new BindingInfo()
            };

            var container = new ResourceContainer();

            container.ResourceDefinitions.Add(new ResourceDefinition());
            container.ResourceDefinitions[0].Resources.Add(new ResourceItem {
                Key = appResource1.Key
            });
            aisModel.MigrationSource.ResourceContainers.Add(container);

            // Create application definitions
            application1.Application.ApplicationDefinition = new ApplicationDefinitionFile()
            {
                ResourceContainerKey  = resourceContainer.Key,
                ResourceDefinitionKey = appResourceDefinition1.Key,
                ResourceKey           = appResource1.Key,
                ApplicationDefinition = new ApplicationDefinition()
                {
                    Properties = new List <ApplicationDefinitionProperty>()
                    {
                        new ApplicationDefinitionProperty()
                        {
                            Name = "DisplayName", Value = application1.Application.Name
                        },
                        new ApplicationDefinitionProperty()
                        {
                            Name = "ApplicationDescription", Value = application1.Application.Name + " Description"
                        }
                    }.ToArray()
                }
            };

            application2.Application.ApplicationDefinition = new ApplicationDefinitionFile()
            {
                ResourceContainerKey  = resourceContainer.Key,
                ResourceDefinitionKey = appResourceDefinition2.Key,
                ResourceKey           = appResource2.Key,
                ApplicationDefinition = new ApplicationDefinition()
                {
                    References = new List <ApplicationDefinitionReference>()
                    {
                        new ApplicationDefinitionReference()
                        {
                            Name = application3.Application.Name
                        }
                    }.ToArray(),
                    Properties = new List <ApplicationDefinitionProperty>()
                    {
                        new ApplicationDefinitionProperty()
                        {
                            Name = "DisplayName", Value = application2.Application.Name
                        },
                        new ApplicationDefinitionProperty()
                        {
                            Name = "ApplicationDescription", Value = application2.Application.Name + " Description"
                        }
                    }.ToArray()
                }
            };

            application3.Application.ApplicationDefinition = new ApplicationDefinitionFile()
            {
                ResourceContainerKey  = resourceContainer.Key,
                ResourceDefinitionKey = appResourceDefinition3.Key,
                ResourceKey           = appResource3.Key,
                ApplicationDefinition = new ApplicationDefinition()
                {
                    Properties = new List <ApplicationDefinitionProperty>()
                    {
                        new ApplicationDefinitionProperty()
                        {
                            Name = "DisplayName", Value = application3.Application.Name
                        },
                        new ApplicationDefinitionProperty()
                        {
                            Name = "ApplicationDescription", Value = application3.Application.Name + " Description"
                        }
                    }.ToArray()
                }
            };

            // Create schemas
            var documentSchema1 = new Types.Entities.Schema()
            {
                Name                  = "DocumentSchema1",
                Namespace             = "Test.Schemas",
                FullName              = "Test.Schemas.DocumentSchema1",
                XmlNamespace          = "http://schemas.test.com/DocumentSchema1",
                RootNodeName          = "Root",
                ResourceContainerKey  = "app-1-assembly-resource-key",
                ResourceDefinitionKey = schemaResourceDefinition1.Key,
                ResourceKey           = schemaResource1.Key,
                SchemaType            = BizTalkSchemaType.Document
            };

            documentSchema1.MessageDefinitions.Add(new MessageDefinition(documentSchema1.RootNodeName, documentSchema1.XmlNamespace, "Test.Schemas.DocumentSchema1", "DocumentSchema1", "document-schema-1:schema:Root"));
            documentSchema1.PromotedProperties.Add(new PromotedProperty()
            {
                PropertyType = "Test.Schemas.PropertySchema1.Property1", XPath = "some xpath"
            });
            application1.Application.Schemas.Add(documentSchema1);

            var documentSchema2 = new Types.Entities.Schema()
            {
                Name                  = "DocumentSchema2",
                Namespace             = "Test.Schemas",
                FullName              = "Test.Schemas.DocumentSchema2",
                XmlNamespace          = "http://schemas.test.com/DocumentSchema2",
                RootNodeName          = "Root",
                ResourceContainerKey  = "app-1-assembly-resource-key",
                ResourceDefinitionKey = schemaResourceDefinition2.Key,
                ResourceKey           = schemaResource2.Key,
                SchemaType            = BizTalkSchemaType.Document
            };

            documentSchema2.MessageDefinitions.Add(new MessageDefinition(documentSchema2.RootNodeName, documentSchema2.XmlNamespace, "Test.Schemas.DocumentSchema2", "DocumentSchema2", "document-schema-2:schema:Root"));
            application1.Application.Schemas.Add(documentSchema2);

            var propertySchema = new Types.Entities.Schema()
            {
                Name                  = "PropertySchema1",
                Namespace             = "Test.Schemas",
                FullName              = "Test.Schemas.PropertySchema1",
                XmlNamespace          = "http://schemas.test.com/PropertySchema1",
                RootNodeName          = "Root",
                ResourceDefinitionKey = schemaResourceDefinition3.Key,
                ResourceKey           = schemaResource3.Key,
                SchemaType            = BizTalkSchemaType.Property
            };

            propertySchema.ContextProperties.Add(new ContextProperty()
            {
                DataType = "xs:string", FullyQualifiedName = "Test.Schemas.PropertySchema1.Property1", PropertyName = schemaResource3Property1.Name, Namespace = "Test.Schemas.PropertySchema1", ResourceKey = schemaResource3Property1.Key
            });
            propertySchema.ContextProperties.Add(new ContextProperty()
            {
                DataType = "xs:int", FullyQualifiedName = "Test.Schemas.PropertySchema1.Property2", PropertyName = schemaResource3Property2.Name, Namespace = "Test.Schemas.PropertySchema1", ResourceKey = schemaResource3Property2.Key
            });
            application1.Application.Schemas.Add(propertySchema);

            // Create transforms
            var map = new Types.Entities.Transform()
            {
                Name                  = "Transform1",
                FullName              = "Test.Maps.Transform1",
                ModuleName            = "Test.Maps, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
                Namespace             = "Test.Maps",
                ResourceContainerKey  = resourceContainer.Key,
                ResourceDefinitionKey = transformResourceDefinition1.Key
            };

            map.SourceSchemaTypeNames.Add("Test.Schemas.DocumentSchema1");
            map.TargetSchemaTypeNames.Add("Test.Schemas.DocumentSchema2");
            application1.Application.Transforms.Add(map);

            // Create send ports.
            var sendPort = new SendPort
            {
                ResourceKey      = sendPortResource1.Key,
                Description      = "This is a send port description.",
                Name             = "Test.SendPorts.SendPort1",
                FilterExpression = new Types.Entities.Filters.Filter
                {
                    Group = new Types.Entities.Filters.Group[]
                    {
                        new Types.Entities.Filters.Group
                        {
                            Statement = new Types.Entities.Filters.Statement[]
                            {
                                new Types.Entities.Filters.Statement()
                            }
                        }
                    }
                }
            };

            /// Create receive ports.
            var receivePort = new ReceivePort
            {
                ResourceKey      = receivePortResource1.Key,
                Description      = receivePortResource1.Description,
                Name             = receivePortResource1.Name,
                ReceiveLocations = new ReceiveLocation[]
                {
                    new ReceiveLocation
                    {
                        ResourceKey = receiveLocation1.Key,
                        Name        = receiveLocation1.Name,
                        Description = receiveLocation1.Name
                    }
                }
            };

            // Create distribution lists.
            var distributionList = new DistributionList
            {
                ResourceKey      = distributionListResource1.Key,
                Description      = distributionListResource1.Description,
                Name             = distributionListResource1.Name,
                FilterExpression = new Types.Entities.Filters.Filter
                {
                    ResourceKey = distributionListFilterResource1.Key,
                    Group       = new Types.Entities.Filters.Group[]
                    {
                        new Types.Entities.Filters.Group()
                    }
                }
            };

            application1.Application.Bindings = new BindingFile
            {
                BindingInfo = new BindingInfo
                {
                    SendPortCollection         = new SendPort[] { sendPort },
                    ReceivePortCollection      = new ReceivePort[] { receivePort },
                    DistributionListCollection = new DistributionList[] { distributionList }
                }
            };

            var app1Msi = new ResourceContainer()
            {
                Name        = "App 1 MSI",
                Description = "App 1 MSI Description",
                Key         = "app-1-msi-resource-key",
                Type        = ModelConstants.ResourceContainerMsi
            };

            aisModel.MigrationSource.ResourceContainers.Add(app1Msi);
            var app1Cab = new ResourceContainer()
            {
                Name        = "App 1 CAB",
                Description = "App 1 CAB Description",
                Key         = $"{app1Msi.Key}:app-1-cab-resource-key",
                Type        = ModelConstants.ResourceContainerCab
            };

            app1Msi.ResourceContainers.Add(app1Cab);
            var app1Assembly = new ResourceContainer()
            {
                Name        = "App 1 Assembly",
                Description = "App 1 Assembly Description",
                Key         = $"{app1Cab.Key}:app-1-assembly-resource-key",
                Type        = ModelConstants.ResourceContainerAssembly
            };

            app1Cab.ResourceContainers.Add(app1Assembly);
            var app1Schema = new ResourceDefinition()
            {
                Name        = "Document Schema 1",
                Description = "Document Schema 1 Description",
                Key         = $"{app1Assembly.Key}:document-schema-1",
                Type        = ModelConstants.ResourceDefinitionSchema
            };

            app1Assembly.ResourceDefinitions.Add(app1Schema);
            var app1DocumentSchema = new ResourceItem()
            {
                Name        = "DocumentSchema1",
                Description = "DocumentSchema1Description",
                Key         = $"{app1Schema.Key}:app-1-schema-resource-key"
            };

            app1Schema.Resources.Add(app1DocumentSchema);
            var app1Schema2 = new ResourceDefinition()
            {
                Name        = "Document Schema 2",
                Description = "Document Schema 2 Description",
                Key         = $"{app1Assembly.Key}:document-schema-2",
                Type        = ModelConstants.ResourceDefinitionSchema
            };

            app1Assembly.ResourceDefinitions.Add(app1Schema2);
            var app1DocumentSchema2 = new ResourceItem()
            {
                Name        = "DocumentSchema2",
                Description = "DocumentSchema2Description",
                Key         = $"{app1Schema.Key}:app-1-schema-2-resource-key"
            };

            app1Schema.Resources.Add(app1DocumentSchema2);

            return(aisModel);
        }
Esempio n. 20
0
        public void ParseFailureInvalidXml(SendPortParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            var bindingResourceContainerKey  = "bindingResourceContainerKey";
            var bindingResourceDefinitionKey = "bindingResourceDefinitionKey";

            "Given a model with send port definied in the binding and an invalid filter expression"
            .x(() =>
            {
                var bindingInfo = new BindingInfo();
                var sendPorts   = new List <SendPort>
                {
                    new SendPort()
                    {
                        Filter           = "invalid xml",
                        Name             = "Send Port 1",
                        PrimaryTransport = new TransportInfo
                        {
                            TransportType = new ProtocolType
                            {
                                Name = "transportName"
                            }
                        }
                    }
                };

                bindingInfo.SendPortCollection = sendPorts.ToArray();

                var application = new ParsedBizTalkApplication();
                application.Application.Bindings = new BindingFile(bindingResourceContainerKey, bindingResourceDefinitionKey)
                {
                    BindingInfo = bindingInfo
                };

                group = new ParsedBizTalkApplicationGroup();
                group.Applications.Add(application);

                model = new AzureIntegrationServicesModel();
                model.MigrationSource.MigrationSourceModel = group;

                var bindingResourceContainer = new ResourceContainer
                {
                    Key = bindingResourceContainerKey
                };

                var bindingResourceDefinition = new ResourceDefinition
                {
                    Key  = bindingResourceDefinitionKey,
                    Type = ModelConstants.ResourceDefinitionBindings
                };

                bindingResourceContainer.ResourceDefinitions.Add(bindingResourceDefinition);
                model.MigrationSource.ResourceContainers.Add(bindingResourceContainer);

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

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

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

            "And a parser"
            .x(() => parser = new SendPortParser(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 parser should have recorded an error when processing the filter."
            .x(() =>
            {
                var sendPort = group.Applications[0].Application.Bindings.BindingInfo.SendPortCollection[0];
                sendPort.FilterExpression.Should().BeNull();
                context.Errors.Count.Should().Be(1);
            });
        }
Esempio n. 21
0
        public void ParseFailureNoBindings(PipelineDataParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = CreateGroup(Array.Empty <SendPort>());
                model.MigrationSource.MigrationSourceModel = group;
                group.Applications[0].Application.Bindings = null;     // Blank bindings forces a skip in processing.
            });

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

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

            "And a parser"
            .x(() => parser = new SendPortPipelineDataParser(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");
            });
        }
Esempio n. 22
0
        public void ParseOneSendPortAndInvalidSendData(PipelineDataParser parser, ILogger logger, List <SendPort> sendPorts, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with one send port and invalid send data XML"
            .x(() =>
            {
                model     = new AzureIntegrationServicesModel();
                sendPorts = new List <SendPort> {
                    new SendPort()
                };
                sendPorts[0].SendPipelineData = "Invalid XML";
                group = CreateGroup(sendPorts.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 SendPortPipelineDataParser(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");
            });
        }
Esempio n. 23
0
        public void ParseSuccessfulOneSendPort(PipelineDataParser parser, ILogger logger, List <SendPort> sendPorts, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with one send port"
            .x(() =>
            {
                model     = new AzureIntegrationServicesModel();
                sendPorts = new List <SendPort> {
                    new SendPort()
                };
                group = CreateGroup(sendPorts.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 SendPortPipelineDataParser(model, context, logger));

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

            "Then the code should not throw an exception"
            .x(() => e.Should().BeNull());
        }
Esempio n. 24
0
        public void ParseFailureMissingBindings(SendPortParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            var bindingResourceContainerKey  = "bindingResourceContainerKey";
            var bindingResourceDefinitionKey = "bindingResourceDefinitionKey";

            "Given a model with send port definied in the binding and no filter expression"
            .x(() =>
            {
                var bindingInfo = new BindingInfo();
                var sendPorts   = new List <SendPort>
                {
                    new SendPort()
                    {
                        Name             = "Send Port 1",
                        PrimaryTransport = new TransportInfo
                        {
                            TransportType = new ProtocolType
                            {
                                Name = "transportName"
                            }
                        }
                    }
                };

                bindingInfo.SendPortCollection = sendPorts.ToArray();

                var application = new ParsedBizTalkApplication();

                group = new ParsedBizTalkApplicationGroup();
                group.Applications.Add(application);

                model = new AzureIntegrationServicesModel();
                model.MigrationSource.MigrationSourceModel = group;

                var bindingResourceContainer = new ResourceContainer
                {
                    Key = bindingResourceContainerKey
                };

                var bindingResourceDefinition = new ResourceDefinition
                {
                    Key  = bindingResourceDefinitionKey,
                    Type = ModelConstants.ResourceDefinitionBindings
                };

                bindingResourceContainer.ResourceDefinitions.Add(bindingResourceDefinition);
                model.MigrationSource.ResourceContainers.Add(bindingResourceContainer);

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

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

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

            "And a parser"
            .x(() => parser = new SendPortParser(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 ParseSuccessfulSingleDistributionListAndNoFilter(DistributionListParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            var bindingResourceContainerKey  = "bindingResourceContainerKey";
            var bindingResourceDefinitionKey = "bindingResourceDefinitionKey";

            "Given a model with no filter on the distribution list"
            .x(() =>
            {
                var bindingInfo      = new BindingInfo();
                var distributionList = new List <DistributionList>
                {
                    new DistributionList()
                    {
                        ResourceKey = "distributionlistresourcekey",
                        Name        = "Distribution List 1",
                        Description = "Distribution List Description 1."
                    }
                };

                bindingInfo.DistributionListCollection = distributionList.ToArray();

                var application = new ParsedBizTalkApplication();
                application.Application.Bindings = new BindingFile(bindingResourceContainerKey, bindingResourceDefinitionKey)
                {
                    BindingInfo = bindingInfo
                };

                group = new ParsedBizTalkApplicationGroup();
                group.Applications.Add(application);

                model = new AzureIntegrationServicesModel();
                model.MigrationSource.MigrationSourceModel = group;

                var bindingResourceContainer = new ResourceContainer
                {
                    Key = bindingResourceContainerKey
                };

                var bindingResourceDefinition = new ResourceDefinition
                {
                    Key  = bindingResourceDefinitionKey,
                    Type = ModelConstants.ResourceDefinitionBindings
                };

                bindingResourceContainer.ResourceDefinitions.Add(bindingResourceDefinition);
                model.MigrationSource.ResourceContainers.Add(bindingResourceContainer);

                application.Application.ApplicationDefinition = new ApplicationDefinitionFile {
                    ResourceKey = "ResourceKey"
                };
                model.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Add(new ResourceItem {
                    Key = "ResourceKey"
                });
            });

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

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

            "And a parser"
            .x(() => parser = new DistributionListParser(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 filter group should be null - nothing created."
            .x(() =>
            {
                var item = group.Applications[0].Application.Bindings.BindingInfo.DistributionListCollection[0];
                item.FilterExpression.Should().BeNull();
                context.Errors.Count.Should().Be(0);
            });

            "And the resources should be set."
            .x(() =>
            {
                var appModel = (AzureIntegrationServicesModel)model;

                // Check the distribution list source has been created.
                appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Should().NotBeNullOrEmpty();
                appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Should().HaveCount(2);
                appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources[0].ResourceRelationships.Should().HaveCount(1);
                var distributionListSource = appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources[1];

                // Get the distribution list from the bindings.
                var distributionList = group.Applications[0].Application.Bindings.BindingInfo.DistributionListCollection[0];

                // Validate the distribution list source.
                distributionListSource.Name.Should().Be(distributionList.Name);
                distributionListSource.Description.Should().Be(distributionList.Description);
                distributionListSource.Type.Should().Be(ModelConstants.ResourceDistributionList);
                distributionListSource.Key.Should().Be(distributionList.ResourceKey);

                distributionListSource.Resources.Should().BeNullOrEmpty();
            });
        }
        public void ParseCorrelationTypeWithSuccess(OrchestrationCorrelationTypeParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, Exception e)
        {
            var orchestrationDefinitionName = "orchestrationDefinitionName";
            var orchestrationDefinitionKey  = "orchestrationDefinitionKey";
            var correlationTypeName         = "correlationTypeName";
            var asmContainerKey             = "asmContainerKey";

            "Given a source model with an orchestration and a correlation type"
            .x(() =>
            {
                var odxModel = new MetaModel
                {
                    Element = new Element[]
                    {
                        new Element
                        {
                            Type     = "Module",
                            Element1 = new Element[]
                            {
                                new Element
                                {
                                    Type     = "CorrelationType",
                                    Property = new ElementProperty[]
                                    {
                                        new ElementProperty {
                                            Name = "Name", Value = correlationTypeName
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                var orchestration = new Orchestration
                {
                    Name = orchestrationDefinitionName,
                    ResourceContainerKey  = asmContainerKey,
                    ResourceDefinitionKey = orchestrationDefinitionKey,
                    Model = odxModel
                };

                var parsedApplication = new ParsedBizTalkApplication
                {
                    Application = new BizTalkApplication()
                };

                parsedApplication.Application.Orchestrations.Add(orchestration);

                model     = new AzureIntegrationServicesModel();
                var group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;
                group.Applications.Add(parsedApplication);
            });

            "And one orchestration in the source report model"
            .x(() =>
            {
                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 = asmContainerKey, Name = "TestAssembly", Type = ModelConstants.ResourceContainerAssembly, ContainerLocation = @"C:\Test\Test.dll"
                };
                cabContainer.ResourceContainers.Add(asmContainer);

                var orchestrationDefinition = new ResourceDefinition()
                {
                    Key  = orchestrationDefinitionKey,
                    Name = orchestrationDefinitionName,
                    Type = ModelConstants.ResourceDefinitionOrchestration
                };
                asmContainer.ResourceDefinitions.Add(orchestrationDefinition);

                var metaModel         = ((ParsedBizTalkApplicationGroup)model.MigrationSource.MigrationSourceModel).Applications[0].Application.Orchestrations[0].Model;
                var metaModelResource = new ResourceItem()
                {
                    Key  = string.Concat(orchestrationDefinitionKey, ":", MetaModelConstants.MetaModelRootElement),
                    Name = MetaModelConstants.MetaModelRootElement,
                    Type = ModelConstants.ResourceMetaModel
                };
                metaModel.Resource             = metaModelResource;
                metaModelResource.SourceObject = metaModel;
                orchestrationDefinition.Resources.Add(metaModelResource);

                var moduleResource = new ResourceItem()
                {
                    Key  = string.Concat(metaModelResource.Key, ":", MetaModelConstants.ElementTypeModule),
                    Name = MetaModelConstants.ElementTypeModule,
                    Type = ModelConstants.ResourceModule
                };
                metaModelResource.Resources.Add(moduleResource);
            });

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

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

            "And a parser"
            .x(() => parser = new OrchestrationCorrelationTypeParser(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 context errors"
            .x(() => context.Errors.Should().HaveCount(0));

            "And the resources should be set."
            .x(() =>
            {
                // Check the correlation type resource has been created.
                var moduleResource = model.FindResourcesByType(ModelConstants.ResourceModule).SingleOrDefault();
                moduleResource.Should().NotBeNull();
                var correlationTypeResource = model.FindResourcesByType(ModelConstants.ResourceCorrelationType).SingleOrDefault();
                correlationTypeResource.Should().NotBeNull();
                var correlationType = ((ParsedBizTalkApplicationGroup)model.MigrationSource.MigrationSourceModel).Applications[0].Application.Orchestrations[0].FindCorrelationTypes().Single();

                // Validate the correlation type resource.
                correlationTypeResource.Should().NotBeNull();
                correlationTypeResource.Key.Should().Be(string.Concat(moduleResource.Key, ":", correlationTypeName));
                correlationTypeResource.Name.Should().Be(correlationTypeName);
                correlationTypeResource.Type.Should().Be(ModelConstants.ResourceCorrelationType);

                correlationType.Resource.Should().Be(correlationTypeResource);         // The pointer to the resource should be set.
                correlationTypeResource.ParentRefId.Should().Be(moduleResource.RefId); // The parent ref ID should be set.
                correlationTypeResource.SourceObject.Should().Be(correlationType);     // The resource should have a pointer to the source object.
            });
        }
        public void ParseFailureInvalidXmlForFilter(DistributionListParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            var bindingResourceContainerKey  = "bindingResourceContainerKey";
            var bindingResourceDefinitionKey = "bindingResourceDefinitionKey";

            "Given a model with invalid XML in the distribution list filter"
            .x(() =>
            {
                var bindingInfo      = new BindingInfo();
                var distributionList = new List <DistributionList>
                {
                    new DistributionList()
                    {
                        ResourceKey = "distributionlistresourcekey",
                        Name        = "Distribution List 1",
                        Description = "Distribution List Description 1.",
                        Filter      = "<invalid-xml>"
                    }
                };

                bindingInfo.DistributionListCollection = distributionList.ToArray();

                var application = new ParsedBizTalkApplication();
                application.Application.Bindings = new BindingFile(bindingResourceContainerKey, bindingResourceDefinitionKey)
                {
                    BindingInfo = bindingInfo
                };

                group = new ParsedBizTalkApplicationGroup();
                group.Applications.Add(application);

                model = new AzureIntegrationServicesModel();
                model.MigrationSource.MigrationSourceModel = group;

                var bindingResourceContainer = new ResourceContainer
                {
                    Key = bindingResourceContainerKey
                };

                var bindingResourceDefinition = new ResourceDefinition
                {
                    Key  = bindingResourceDefinitionKey,
                    Type = ModelConstants.ResourceDefinitionBindings
                };

                bindingResourceContainer.ResourceDefinitions.Add(bindingResourceDefinition);
                model.MigrationSource.ResourceContainers.Add(bindingResourceContainer);

                application.Application.ApplicationDefinition = new ApplicationDefinitionFile {
                    ResourceKey = "ResourceKey"
                };
                model.MigrationSource.ResourceContainers.Add(new ResourceContainer());
                model.MigrationSource.ResourceContainers[0].ResourceDefinitions.Add(new ResourceDefinition());
                model.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Add(new ResourceItem {
                    Key = "ResourceKey"
                });
            });

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

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

            "And a parser"
            .x(() => parser = new DistributionListParser(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 parser should have recorded an error when processing the filter."
            .x(() =>
            {
                var item = group.Applications[0].Application.Bindings.BindingInfo.DistributionListCollection[0];
                item.FilterExpression.Should().BeNull();
                context.Errors.Count.Should().Be(1);
            });
        }
Esempio n. 28
0
        public void ParseSuccessfulSingleFilterGroup(SendPortParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            var bindingResourceContainerKey  = "bindingResourceContainerKey";
            var bindingResourceDefinitionKey = "bindingResourceDefinitionKey";

            "Given a model with send port definied in the binding and filter expression"
            .x(() =>
            {
                var bindingInfo = new BindingInfo();
                var sendPorts   = new List <SendPort>
                {
                    new SendPort()
                    {
                        Name             = "Send Port 1",
                        Filter           = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Filter xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n  <Group>\n    <Statement Property=\"FILE.ReceivedFileName\" Operator=\"6\" />\n    <Statement Property=\"FILE.FileCreationTime\" Operator=\"3\" Value=\"SomeDate\" />\n    <Statement Property=\"Microsoft.BizTalk.XLANGs.BTXEngine.OriginatorSID\" Operator=\"3\" Value=\"Test\" />\n  </Group>\n  <Group>\n    <Statement Property=\"AzureBlobStorage.BlobName\" Operator=\"2\" Value=\"X\" />\n    <Statement Property=\"AzureBlobStorage.CreateTime\" Operator=\"4\" Value=\"Y\" />\n  </Group>\n  <Group>\n    <Statement Property=\"AzureBlobStorage.BlobType\" Operator=\"0\" Value=\"Z\" />\n  </Group>\n</Filter>",
                        PrimaryTransport = new TransportInfo
                        {
                            TransportType = new ProtocolType
                            {
                                Name = "transportName"
                            }
                        },
                        IsTwoWay = true
                    }
                };

                bindingInfo.SendPortCollection = sendPorts.ToArray();

                var application = new ParsedBizTalkApplication();
                application.Application.Bindings = new BindingFile(bindingResourceContainerKey, bindingResourceDefinitionKey)
                {
                    BindingInfo = bindingInfo
                };

                group = new ParsedBizTalkApplicationGroup();
                group.Applications.Add(application);

                model = new AzureIntegrationServicesModel();
                model.MigrationSource.MigrationSourceModel = group;

                var bindingResourceContainer = new ResourceContainer
                {
                    Key = bindingResourceContainerKey
                };

                var bindingResourceDefinition = new ResourceDefinition
                {
                    Key  = bindingResourceDefinitionKey,
                    Type = ModelConstants.ResourceDefinitionBindings
                };

                bindingResourceContainer.ResourceDefinitions.Add(bindingResourceDefinition);
                model.MigrationSource.ResourceContainers.Add(bindingResourceContainer);
            });

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

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

            "And a parser"
            .x(() => parser = new SendPortParser(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 filter group should be correctly parsed."
            .x(() =>
            {
                var sendPort = group.Applications[0].Application.Bindings.BindingInfo.SendPortCollection[0];
                sendPort.FilterExpression.Should().NotBeNull();
                sendPort.FilterExpression.Group.Should().NotBeNull();
                sendPort.FilterExpression.Group.Length.Should().Be(3);
                sendPort.FilterExpression.Group[0].Statement.Length.Should().Be(3);
            });

            "And the resources should be set."
            .x(() =>
            {
                var appModel = (AzureIntegrationServicesModel)model;

                // Check the send port resource has been created.
                appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Should().NotBeNullOrEmpty();
                appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources.Should().HaveCount(1);
                var sendPortResource   = appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0].Resources[0];
                var resourceDefinition = appModel.MigrationSource.ResourceContainers[0].ResourceDefinitions[0];

                // Get the send port from the bindings.
                var sendPort = group.Applications[0].Application.Bindings.BindingInfo.SendPortCollection[0];

                // Validate the send port resource.
                sendPortResource.Name.Should().Be(sendPort.Name);
                sendPortResource.Description.Should().Be(sendPort.Description);
                sendPortResource.Type.Should().Be(ModelConstants.ResourceSendPort);
                sendPortResource.Key.Should().Be(sendPort.ResourceKey);

                sendPortResource.Resources.Should().NotBeNullOrEmpty();
                sendPortResource.Resources.Should().HaveCount(1);

                sendPortResource.Properties.Should().ContainKey("Direction");
                sendPortResource.Properties["Direction"].Should().Be("Two-Way");

                sendPort.Resource.Should().Be(sendPortResource);                    // The pointer to the resource should be set.
                sendPortResource.ParentRefId.Should().Be(resourceDefinition.RefId); // The parent ref ID should be set.
                sendPortResource.SourceObject.Should().Be(sendPort);                // The resource should have a pointer to the source object.

                // Validate the filter resource.
                var filterResource = sendPortResource.Resources[0];
                filterResource.Name.Should().StartWith(sendPortResource.Name);
                var expectedFilterKey = string.Concat(sendPort.Name, ":", "filter");
                filterResource.Key.Should().Be(expectedFilterKey);
                filterResource.Name.Should().EndWith("filter expression");
                filterResource.Type.Should().Be(ModelConstants.ResourceFilterExpression);

                sendPort.FilterExpression.Resource.Should().Be(filterResource);     // The pointer to the resource should be set.
                filterResource.ParentRefId.Should().Be(sendPortResource.RefId);     // The parent ref ID should be set.
                filterResource.SourceObject.Should().Be(sendPort.FilterExpression); // The resource should have a pointer to the source object.
            });
        }
Esempio n. 29
0
        public void ParseOneSendPortAndValidSendAndReceiveData(PipelineDataParser parser, ILogger logger, List <SendPort> sendPorts, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model with one send port and valid send/receive data XML"
            .x(() =>
            {
                model     = new AzureIntegrationServicesModel();
                sendPorts = new List <SendPort> {
                    new SendPort()
                };
                sendPorts[0].ReceivePipelineData = ValidData;
                sendPorts[0].SendPipelineData    = ValidData;
                group = CreateGroup(sendPorts.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 SendPortPipelineDataParser(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 receive configuration"
            .x(() =>
            {
                sendPorts[0].ReceivePipelineCustomConfiguration.Should().NotBeNull();
                sendPorts[0].ReceivePipelineCustomConfiguration.Stages.Should().HaveCount(1);

                var rootStage = sendPorts[0].ReceivePipelineCustomConfiguration.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();
            });

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

                var rootStage = sendPorts[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();
            });
        }
Esempio n. 30
0
        public void ParseSuccessfulPropertySchemaPlusNormalSchema(PropertySchemaPropertyParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e)
        {
            "Given a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                group = new ParsedBizTalkApplicationGroup();
                model.MigrationSource.MigrationSourceModel = group;

                model.MigrationSource.ResourceContainers.Add(new ResourceContainer()
                {
                    Key = "TestContainer.Key", Name = "TestContainer"
                });
                var content1 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><xs:schema xmlns=\"http://Microsoft.AzureIntegrationMigration.BizTalk.TestApps.Schemas.PropertySchema1\" xmlns:b=\"http://schemas.microsoft.com/BizTalk/2003\" targetNamespace=\"https://Microsoft.AzureIntegrationMigration.BizTalk.TestApps.Schemas.PropertySchema1\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><xs:annotation><xs:appinfo><b:schemaInfo schema_type=\"property\" xmlns:b=\"http://schemas.microsoft.com/BizTalk/2003\" /></xs:appinfo></xs:annotation><xs:element name=\"TestStringProperty1\" type=\"xs:string\"><xs:annotation><xs:appinfo><b:fieldInfo propertyGuid=\"4efaeaed-05b9-4fe5-b05f-677b5d9e2a6b\" /></xs:appinfo></xs:annotation></xs:element><xs:element name=\"TestIntegerProperty1\" type=\"xs:int\"><xs:annotation><xs:appinfo><b:fieldInfo propertyGuid=\"bb67d7e6-103a-4567-a405-6d854bc02d5d\" /></xs:appinfo></xs:annotation></xs:element><xs:element name=\"TestBoolProperty1\" type=\"xs:boolean\"><xs:annotation><xs:appinfo><b:fieldInfo propertyGuid=\"5f6fbe77-d32b-4ff3-a9b4-e9602c7aa52f\" /></xs:appinfo></xs:annotation></xs:element></xs:schema>";
                model.MigrationSource.ResourceContainers[0].ResourceDefinitions.Add(new ResourceDefinition()
                {
                    Key = "TestSchema1.Key", Name = "TestSchema1", Type = ModelConstants.ResourceDefinitionSchema, ResourceContent = content1
                });

                var content2 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><xs:schema xmlns=\"http://Microsoft.AzureIntegrationMigration.BizTalk.TestApps.Schemas.Schema2NoPromotions\" xmlns:b=\"http://schemas.microsoft.com/BizTalk/2003\" elementFormDefault=\"qualified\" targetNamespace=\"http://Microsoft.AzureIntegrationMigration.BizTalk.TestApps.Schemas.Schema2NoPromotions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><xs:element name=\"SimpleCar\"><xs:complexType><xs:sequence><xs:element name=\"Make\" type=\"xs:string\" /><xs:element name=\"Model\" type=\"xs:string\" /><xs:element name=\"DateRegistered\" type=\"xs:date\" /><xs:element name=\"Colour\" type=\"xs:string\" /></xs:sequence></xs:complexType></xs:element></xs:schema>";
                model.MigrationSource.ResourceContainers[0].ResourceDefinitions.Add(new ResourceDefinition()
                {
                    Key = "TestSchema2.Key", Name = "TestSchema2", Type = ModelConstants.ResourceDefinitionSchema, ResourceContent = content2
                });

                group.Applications.Add(new ParsedBizTalkApplication()
                {
                    Application = new BizTalkApplication()
                });
                group.Applications[0].Application.Schemas.Add(new Schema("TestContainer.Key", "TestSchema1.Key")
                {
                    SchemaType = BizTalkSchemaType.Property,
                    Namespace  = "TestNamespace",
                    Name       = "TestPropertySchema",
                    FullName   = "TestNamespace.TestSchema"
                });
                var schema = new Schema("TestContainer", "TestSchema2.Key")
                {
                    SchemaType = BizTalkSchemaType.Unknown,
                    Namespace  = "TestNamespace",
                    Name       = "Schema",
                    FullName   = "TestNamespace.TestSchema"
                };
                group.Applications[0].Application.Schemas.Add(schema);
            });

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

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

            "And a parser"
            .x(() => parser = new PropertySchemaPropertyParser(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 property schema should be correctly parsed."
            .x(() =>
            {
                var schema = group.Applications[0].Application.Schemas[0];
                schema.SchemaType.Should().Be(BizTalkSchemaType.Property);
                schema.ContextProperties.Count.Should().Be(3);
                schema.ContextProperties[0].PropertyName.Should().Be("TestStringProperty1");
                schema.ContextProperties[0].DataType.Should().Be("xs:string");
                schema.ContextProperties[0].FullyQualifiedName.Should().Be("TestNamespace.TestStringProperty1");
                schema.ContextProperties[1].PropertyName.Should().Be("TestIntegerProperty1");
                schema.ContextProperties[1].DataType.Should().Be("xs:int");
                schema.ContextProperties[1].FullyQualifiedName.Should().Be("TestNamespace.TestIntegerProperty1");
                schema.ContextProperties[2].PropertyName.Should().Be("TestBoolProperty1");
                schema.ContextProperties[2].DataType.Should().Be("xs:boolean");
                schema.ContextProperties[2].FullyQualifiedName.Should().Be("TestNamespace.TestBoolProperty1");
            });

            "And the message schema should be identified."
            .x(() =>
            {
                var schema = group.Applications[0].Application.Schemas[1];
                schema.SchemaType.Should().Be(BizTalkSchemaType.Unknown);     // haven't parsed this one and left it unchanged
                schema.ContextProperties.Count.Should().Be(0);
            });
        }