Ejemplo n.º 1
0
        private MessagingObject CreateSendEndpoint(string endpointKeyPrefix, SendPort sendPort)
        {
            AdapterEndpoint endpointAdapter;

            // Is this a static or dynamic send port (that is, has a transport been set)?
            if (sendPort.IsStatic)
            {
                _logger.LogDebug(TraceMessages.CreatingSendEndpointAdapter, RuleName, sendPort.PrimaryTransport.TransportType.Name, sendPort.Name);

                // TODO: Use primary transport only, but need to think about how to handle backup transport

                // Create an endpoint adapter (assume request-reply or send, but some adapters may be fire and forget which will be changed later by a specific rule)
                endpointAdapter = new AdapterEndpoint(sendPort.Name, sendPort.PrimaryTransport.TransportType.Name);

                // Set step name as a property on the endpoint
                endpointAdapter.Properties.Add(ModelConstants.ScenarioStepName, $"{sendPort.PrimaryTransport.TransportType.Name.ToLowerInvariant()}SendAdapter");
            }
            else
            {
                _logger.LogDebug(TraceMessages.CreatingDynamicSendEndpointAdapter, RuleName, sendPort.Name);

                // Create an endpoint adapter (assume request-reply or send, but some adapters may be fire and forget which will be changed later by a specific rule)
                endpointAdapter = new AdapterEndpoint(sendPort.Name, MigrationTargetResources.DynamicSendPortDefaultProtocol);

                // Set step name as a property on the endpoint
                endpointAdapter.Properties.Add(ModelConstants.ScenarioStepName, $"{MigrationTargetResources.DynamicSendPortDefaultProtocol.ToLowerInvariant()}SendAdapter");

                // TODO: Handle dynamic send port - need to figure out how to find the actual procotol from an orchestration
            }

            // Set common property values
            endpointAdapter.Activator   = false;
            endpointAdapter.Description = sendPort.Description;
            endpointAdapter.Key         = $"{endpointKeyPrefix}:{ModelConstants.AdapterEndpointLeafKey}";
            endpointAdapter.MessageDeliveryGuarantee = MessageDeliveryGuarantee.AtLeastOnce;
            endpointAdapter.MessageExchangePattern   = sendPort.IsTwoWay ? MessageExchangePattern.RequestReply : MessageExchangePattern.Send;

            // Set BizTalk specific configuration properties
            var configurationEntries = new Dictionary <string, object>()
            {
                { ModelConstants.IsTwoWay, sendPort.IsTwoWay }
            };

            // Add configuration properties
            endpointAdapter.Properties.Add(ModelConstants.ConfigurationEntry, configurationEntries);

            // Set BizTalk specific routing properties
            var routingProperties = new Dictionary <string, object>()
            {
                { ModelConstants.BizTalkSpName, ModelConstants.BizTalkSpName },
                { ModelConstants.BizTalkSpId, ModelConstants.BizTalkSpId }
            };

            // Add routing properties if two-way
            if (sendPort.IsTwoWay)
            {
                // Set BizTalk specific routing properties
                routingProperties.Add(ModelConstants.BizTalkAckReceivePortName, ModelConstants.BizTalkAckReceivePortName);
                routingProperties.Add(ModelConstants.BizTalkAckReceivePortId, ModelConstants.BizTalkAckReceivePortId);
                routingProperties.Add(ModelConstants.BizTalkAckSendPortName, ModelConstants.BizTalkAckSendPortName);
                routingProperties.Add(ModelConstants.BizTalkAckSendPortId, ModelConstants.BizTalkAckSendPortId);
                routingProperties.Add(ModelConstants.BizTalkAckInboundTransportLocation, ModelConstants.BizTalkAckInboundTransportLocation);
                routingProperties.Add(ModelConstants.BizTalkAckOutboundTransportLocation, ModelConstants.BizTalkAckOutboundTransportLocation);
                routingProperties.Add(ModelConstants.BizTalkAckFailureCategory, ModelConstants.BizTalkAckFailureCategory);
                routingProperties.Add(ModelConstants.BizTalkAckFailureCode, ModelConstants.BizTalkAckFailureCode);
                routingProperties.Add(ModelConstants.BizTalkAckId, ModelConstants.BizTalkAckId);
                routingProperties.Add(ModelConstants.BizTalkAckType, ModelConstants.BizTalkAckType);
            }

            // Add routing properties
            endpointAdapter.Properties.Add(ModelConstants.RoutingProperties, routingProperties);

            // TODO: Add schema references from source application

            // By default, this isn't convertible unless overridden by a specific rule
            endpointAdapter.Rating = ConversionRating.NoAutomaticConversion;

            return(endpointAdapter);
        }
Ejemplo n.º 2
0
        private MessagingObject CreateReceiveEndpoint(string endpointKeyPrefix, ResourceItem sourceApplication, Application targetApplication, ReceivePort receivePort, ReceiveLocation receiveLocation)
#pragma warning restore CA1801
        {
            _logger.LogDebug(TraceMessages.CreatingReceiveEndpointAdapter, RuleName, receiveLocation.ReceiveLocationTransportType.Name, receiveLocation.Name);

            // Create an endpoint adapter (assume receive-response or receive, but some adapters may be accept which will be changed later by a specific rule)
            var endpointAdapter = new AdapterEndpoint(receiveLocation.Name, receiveLocation.ReceiveLocationTransportType.Name)
            {
                Activator   = true,
                Description = receiveLocation.Description,
                Key         = $"{endpointKeyPrefix}:{ModelConstants.AdapterEndpointLeafKey}",
                MessageDeliveryGuarantee = MessageDeliveryGuarantee.AtLeastOnce,
                MessageExchangePattern   = receivePort.IsTwoWay ? MessageExchangePattern.ReceiveResponse : MessageExchangePattern.Receive
            };

            // TODO: Add schema references from source application

            // By default, this isn't convertible unless overridden by a specific rule
            endpointAdapter.Rating = ConversionRating.NoAutomaticConversion;

            // Set scenario and step name as properties on the endpoint
            var scenarioName = $"{targetApplication.Name.FormatKey()}.{receivePort.Name.FormatKey()}.{receiveLocation.Name.FormatKey()}";

            endpointAdapter.Properties.Add(ModelConstants.ScenarioName, scenarioName);
            endpointAdapter.Properties.Add(ModelConstants.ScenarioStepName, $"{receiveLocation.ReceiveLocationTransportType.Name.ToLowerInvariant()}ReceiveAdapter");

            // Set BizTalk specific configuration properties
            var configurationEntries = new Dictionary <string, object>()
            {
                { ModelConstants.IsTwoWay, receivePort.IsTwoWay },
                { ModelConstants.BizTalkReceivePortName, receivePort.Name },
                { ModelConstants.BizTalkReceivePortId, $"{targetApplication.Name.FormatKey()}.{receivePort.Name.FormatKey()}" },
                { ModelConstants.BizTalkInboundTransportType, receiveLocation.ReceiveLocationTransportType.Name },
                { ModelConstants.BizTalkInboundTransportLocation, receiveLocation.Address },
                { ModelConstants.FailedMessageRouting, true }
            };

            // Is it a two-way port?
            if (receivePort.IsTwoWay)
            {
                configurationEntries.Add(ModelConstants.ResponseTimeout, 20);
            }

            // Add configuration properties
            endpointAdapter.Properties.Add(ModelConstants.ConfigurationEntry, configurationEntries);

            // Set BizTalk specific routing properties
            var routingProperties = new Dictionary <string, object>()
            {
                { ModelConstants.BizTalkReceivePortName, ModelConstants.BizTalkReceivePortName },
                { ModelConstants.BizTalkReceivePortId, ModelConstants.BizTalkReceivePortId },
                { ModelConstants.BizTalkInboundTransportType, ModelConstants.BizTalkInboundTransportType },
                { ModelConstants.BizTalkInboundTransportLocation, ModelConstants.BizTalkInboundTransportLocation }
            };

            // Add routing properties
            endpointAdapter.Properties.Add(ModelConstants.RoutingProperties, routingProperties);

            // Add response topic subscription
            if (receivePort.IsTwoWay)
            {
                CreateEndpointFilter(endpointAdapter, receivePort);
            }

            return(endpointAdapter);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a populated model to use for the tests.
        /// </summary>
        /// <returns>A model instance.</returns>
        public static AzureIntegrationServicesModel GetModel()
        {
            var model = new AzureIntegrationServicesModel();

            model.MigrationTarget.TargetEnvironment     = AzureIntegrationServicesTargetEnvironment.Consumption;
            model.MigrationTarget.DeploymentEnvironment = "dev";
            model.MigrationTarget.AzureSubscriptionId   = "azure-subs-id";
            model.MigrationTarget.AzurePrimaryRegion    = "UK South";
            model.MigrationTarget.AzureSecondaryRegion  = "UK West";

            // Add a message bus
            model.MigrationTarget.MessageBus = new MessageBus()
            {
                Name           = "ContosoMessageBus",
                Key            = "ContosoMessageBus",
                ResourceMapKey = "messageBus"
            };

            // Add an application
            var systemApp = new Application()
            {
                Name = "System",
                Key  = "ContosoMessageBus:System"
            };

            model.MigrationTarget.MessageBus.Applications.Add(systemApp);

            var app = new Application()
            {
                Name           = "AppA",
                Key            = "ContosoMessageBus:AppA",
                ResourceMapKey = "application"
            };

            model.MigrationTarget.MessageBus.Applications.Add(app);

            // Add an application message
            var appMessage = new DocumentMessage()
            {
                Name           = "PurchaseOrderFlatFile",
                Key            = "ContosoMessageBus:AppA:PurchaseOrderFlatFile",
                ContentType    = MessageContentType.Xml,
                ResourceMapKey = "applicationMessage"
            };

            app.Messages.Add(appMessage);

            // Add a message box
            var messageBox = new TopicChannel()
            {
                Name           = "MessageBox",
                Key            = "ContosoMessageBus:System:MessageBox",
                ResourceMapKey = "messageBox"
            };

            systemApp.Channels.Add(messageBox);

            // Add a message agent
            var messageAgent = new ContentBasedRouter()
            {
                Name           = "MessageAgent",
                Key            = "ContosoMessageBus:System:MessageAgent",
                ResourceMapKey = "messageAgent"
            };

            systemApp.Intermediaries.Add(messageAgent);

            // Add a process manager
            var processManager = new ProcessManager()
            {
                Name           = "FtpTransformWorkflow",
                Key            = "ContosoMessageBus:AppA:FtpTransformWorkflow",
                ResourceMapKey = "processManager"
            };

            processManager.WorkflowModel = GetWorkflowModel();
            app.Intermediaries.Add(processManager);

            // Add workflow model to process manager
            // Add an FTP endpoint
            var ftpReceive = new AdapterEndpoint()
            {
                Name           = "FtpReceive",
                Key            = "ContosoMessageBus:System:FtpReceive",
                ResourceMapKey = "ftpReceive"
            };

            systemApp.Endpoints.Add(ftpReceive);

            return(model);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Copies the source model to the target model.
        /// </summary>
        /// <param name="model">The model containing the source and target.</param>
        public static void CopySourceToTarget(AzureIntegrationServicesModel model, bool includeFtpReceive = false, bool includeFtpSend = false)
        {
            model = model ?? throw new ArgumentNullException(nameof(model));

            model.MigrationTarget.MessageBus = new ApplicationModel.Target.MessageBus
            {
                Name           = "nameMessageBus",
                Key            = ModelConstants.MessageBusLeafKey,
                ResourceMapKey = "resourceMapKeyMessageBus",
            };

            foreach (var application in model.GetSourceModel <ParsedBizTalkApplicationGroup>().Applications)
            {
                var targetApplication = new ApplicationModel.Target.Application
                {
                    Name           = application.Application.Name,
                    Key            = $"{model.MigrationTarget.MessageBus.Key}:{application.Application.Name.FormatKey()}",
                    ResourceMapKey = "application",
                };

                var schemaMessages = from schema in application.Application.Schemas
                                     from messageDefintion in schema.MessageDefinitions
                                     where schema.SchemaType == BizTalkSchemaType.Document
                                     select new { Schema = schema, MessageDefinition = messageDefintion };

                foreach (var schemaMessage in schemaMessages)
                {
                    var resourceMapKey = $"applicationMessage{application.Application.Name}{schemaMessage.MessageDefinition.LocalName}";

                    targetApplication.Messages.Add(new DocumentMessage
                    {
                        Name          = schemaMessage.MessageDefinition.LocalName,
                        MessageSchema = new MessageSchema
                        {
                            ResourceKeyRef = schemaMessage.MessageDefinition.ResourceKey,
                            Name           = schemaMessage.Schema.Name
                        },
                        Key            = $"{targetApplication.Key}:{schemaMessage.MessageDefinition.LocalName}",
                        ContentType    = MessageContentType.Xml,
                        ResourceMapKey = resourceMapKey,
                        Description    = "Schema description"
                    });
                }

                if (includeFtpReceive)
                {
                    var ftpReceiveAdapter = new AdapterEndpoint()
                    {
                        Name                   = "FTP Receive Adapter",
                        Description            = "Test FTP receive adapter",
                        Key                    = $"{targetApplication.Key}:ReceivePort1:ReceiveLocation1:{ModelConstants.AdapterEndpointLeafKey}",
                        Activator              = true,
                        AdapterProtocol        = "FTP",
                        MessageExchangePattern = MessageExchangePattern.Accept
                    };

                    ftpReceiveAdapter.Properties.Add(ModelConstants.ScenarioName, $"{targetApplication.Name}:ReceivePort1:ReceiveLocation1");
                    targetApplication.Endpoints.Add(ftpReceiveAdapter);
                }

                if (includeFtpSend)
                {
                    var ftpSendAdapter = new AdapterEndpoint()
                    {
                        Name                   = "FTP Send Adapter",
                        Description            = "Test Send receive adapter",
                        Key                    = $"{targetApplication.Key}:Test.SendPorts.SendPort1:{ModelConstants.AdapterEndpointLeafKey}",
                        Activator              = true,
                        AdapterProtocol        = "FTP",
                        MessageExchangePattern = MessageExchangePattern.Send
                    };

                    ftpSendAdapter.Properties.Add(ModelConstants.ScenarioName, $"{targetApplication.Name}:Test.SendPorts.SendPort1");
                    targetApplication.Endpoints.Add(ftpSendAdapter);
                }

                model.MigrationTarget.MessageBus.Applications.Add(targetApplication);
            }
        }
Ejemplo n.º 5
0
        public void GenerateFailsWhenMissingConfig(AP005SendRoutingPropertyGenerator generator, IFileRepository fileRepository, IScenarioRouteWalker routeWalker, ILogger logger, AzureIntegrationServicesModel model, Application application, MigrationContext context, Exception e)
        {
            var     generatedFileName          = string.Empty;
            JObject generatedJson              = null;
            var     resourcemapkey             = "resourcemapkey";
            var     scenarioName               = "scenarioName";
            var     activatingIntermediaryName = "activatingIntermediaryName";

            var routingProperties = new List <(string PropertyName, string PropertyValue)>
            {
                ("propertyOneName", "propertyOneValue"),
                ("propertyTwoName", "propertyTwoValue")
            };

            "Given an generator"
            .x(() => generator.Should().BeNull());

            "And a file repository"
            .x(() =>
            {
                _mockFileRepository.Setup(f => f.WriteJsonFile(
                                              It.IsAny <string>(),
                                              It.IsAny <JObject>()
                                              ))
                .Callback <string, JObject>(
                    (p1, p2) =>
                {
                    generatedFileName = p1;
                    generatedJson     = p2;
                });

                fileRepository = _mockFileRepository.Object;
            });

            "And an application"
            .x(() =>
            {
                var activatingIntermediary = new MessageSubscriber
                {
                    Activator      = true,
                    ResourceMapKey = resourcemapkey,
                    Name           = activatingIntermediaryName
                };

                var routingProperties1            = new Dictionary <string, object>();
                var intermediaryRoutingProperties = routingProperties[0];
                routingProperties1[intermediaryRoutingProperties.PropertyName] = intermediaryRoutingProperties.PropertyValue;

                activatingIntermediary.Properties[ModelConstants.ScenarioName]      = scenarioName;
                activatingIntermediary.Properties[ModelConstants.RoutingProperties] = routingProperties1;

                activatingIntermediary.Resources.Add(
                    new TargetResourceTemplate
                {
                    ResourceType = "WrongResourceType",
                    OutputPath   = "outputpath"
                });

                var secondIntermediary = new GenericFilter
                {
                    Name = "SecondIntermediary"
                };

                var endpoint = new AdapterEndpoint
                {
                    Name = "Endpoint"
                };

                var routingProperties2        = new Dictionary <string, object>();
                var endpointRoutingProperties = routingProperties[1];
                routingProperties2[endpointRoutingProperties.PropertyName] = endpointRoutingProperties.PropertyValue;
                endpoint.Properties[ModelConstants.RoutingProperties]      = routingProperties2;

                application = new Application();
                application.Intermediaries.Add(activatingIntermediary);
                application.Intermediaries.Add(secondIntermediary);
                application.Endpoints.Add(endpoint);
            });

            "And a model"
            .x(() =>
            {
                model = new AzureIntegrationServicesModel();
                model.MigrationTarget.MessageBus = new MessageBus();
                model.MigrationTarget.MessageBus.Applications.Add(application);
            });

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

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

            "And a route walker"
            .x(() =>
            {
                var route = new List <(MessagingObject RoutingObject, Channel InputChannel)>();

                foreach (var intermediary in application.Intermediaries)
                {
                    route.Add((intermediary, null));
                }

                foreach (var endpoint in application.Endpoints)
                {
                    route.Add((endpoint, null));
                }

                var mockRouteWalker = new Mock <IScenarioRouteWalker>();

                mockRouteWalker.Setup(w => w.WalkSendRoute(
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <Intermediary>(),
                                          It.IsAny <IEnumerable <Intermediary> >(),
                                          It.IsAny <IEnumerable <Channel> >(),
                                          It.IsAny <IEnumerable <Endpoint> >()
                                          )).Returns(route);

                routeWalker = mockRouteWalker.Object;
            });

            "And a generator"
            .x(() => generator = new AP005SendRoutingPropertyGenerator(fileRepository, routeWalker, model, context, logger));

            "When converting"
            .x(async() => e = await Record.ExceptionAsync(async() => await generator.ConvertAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false));

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

            "And there should be one context error"
            .x(() =>
            {
                context.Errors.Should().NotBeNullOrEmpty();
                context.Errors.Should().HaveCount(1);
                context.Errors[0].Message.Should().Contain(ModelConstants.ResourceTypeRoutingProperties);
                context.Errors[0].Message.Should().Contain(activatingIntermediaryName);
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a default object model for converting.
        /// </summary>
        /// <returns></returns>
        public static AzureIntegrationServicesModel CreateDefaultModelForConverting()
        {
            var model = 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"
            };

            model.MigrationSource.ResourceContainers.Add(resourceContainer);

            var appResourceDefinition1 = new ResourceDefinition()
            {
                Name        = "App 1 Resource Definition",
                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         = "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         = "app-2",
                Description = "App 2 Description",
                Type        = ModelConstants.ResourceDefinitionApplicationDefinition
            };

            resourceContainer.ResourceDefinitions.Add(appResourceDefinition2);

            var appResource2 = new ResourceItem
            {
                Name        = "App 2 Resource Definition Application",
                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         = "app-3",
                Description = "App 3 Description",
                Type        = ModelConstants.ResourceDefinitionApplicationDefinition
            };

            resourceContainer.ResourceDefinitions.Add(appResourceDefinition3);

            var appResource3 = new ResourceItem
            {
                Name        = "App 3 Resource Definition Application",
                Key         = "app-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             = "document-schema-1",
                ResourceContent = "<some xml>"
            };

            resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition1);

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

            schemaResourceDefinition1.Resources.Add(schemaResource1);

            var messageResource1 = new ResourceItem()
            {
                Name        = "Message1",
                Description = "This is message 1.",
                Type        = ModelConstants.ResourceMessageType,
                Key         = "document-schema-1:schema1:message1",
                ParentRefId = schemaResource1.RefId
            };

            schemaResource1.Resources.Add(messageResource1);

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

            resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition2);

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

            schemaResourceDefinition2.Resources.Add(schemaResource2);

            var messageResource2 = new ResourceItem()
            {
                Name        = "Message2",
                Description = "This is message 2.",
                Type        = ModelConstants.ResourceMessageType,
                Key         = "document-schema-2:schema2:message2",
                ParentRefId = schemaResource2.RefId
            };

            schemaResource2.Resources.Add(messageResource2);

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

            resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition3);

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

            schemaResourceDefinition3.Resources.Add(schemaResource3);

            var messageResource3 = new ResourceItem()
            {
                Name        = "Message3",
                Description = "This is message 3.",
                Type        = ModelConstants.ResourceMessageType,
                Key         = "document-schema-3:schema3:message3",
                ParentRefId = schemaResource3.RefId
            };

            schemaResource3.Resources.Add(messageResource3);

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

            schemaResourceDefinition3.Resources.Add(schemaResource3Property1);

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

            schemaResourceDefinition3.Resources.Add(schemaResource3Property2);

            var transformResourceDefinition1 = new ResourceDefinition()
            {
                Name            = "Transform1",
                Description     = "This is transform 1.",
                Type            = ModelConstants.ResourceDefinitionMap,
                Key             = "transform-1",
                ParentRefId     = resourceContainer.RefId,
                ResourceContent = "<some xml>"
            };

            resourceContainer.ResourceDefinitions.Add(transformResourceDefinition1);

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

            transformResourceDefinition1.Resources.Add(transformResource1);

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

            resourceContainer.ResourceDefinitions.Add(bindingResourceDefinition1);

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

            bindingResourceDefinition1.Resources.Add(sendPortResource1);

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

            sendPortResource1.Resources.Add(sendPortFilterResource1);

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

            bindingResourceDefinition1.Resources.Add(receivePortResource1);

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

            receivePortResource1.Resources.Add(receiveLocation1);

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

            bindingResourceDefinition1.Resources.Add(distributionListResource1);

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

            distributionListResource1.Resources.Add(distributionListFilterResource1);

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

            model.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()
            };

            // 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",
                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",
                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 }
                }
            };

            // Target model
            model.MigrationTarget.TargetEnvironment     = AzureIntegrationServicesTargetEnvironment.Consumption;
            model.MigrationTarget.DeploymentEnvironment = "dev";
            model.MigrationTarget.AzureSubscriptionId   = "azure-subs-id";
            model.MigrationTarget.AzurePrimaryRegion    = "UK South";
            model.MigrationTarget.AzureSecondaryRegion  = "UK West";

            // Add a message bus
            model.MigrationTarget.MessageBus = new MessageBus()
            {
                Name           = "ContosoMessageBus",
                Key            = "ContosoMessageBus",
                ResourceMapKey = "messageBus",
            };
            var messageBusResourceTemplate = new TargetResourceTemplate()
            {
                OutputPath = "output"
            };

            messageBusResourceTemplate.ResourceTemplateFiles.Add("path/to/file.json.liquid");
            messageBusResourceTemplate.ResourceTemplateFiles.Add("path/to/file2.json");
            model.MigrationTarget.MessageBus.Resources.Add(messageBusResourceTemplate);

            // Add an application
            var systemApp = new Application()
            {
                Name = "System",
                Key  = "ContosoMessageBus:System"
            };

            model.MigrationTarget.MessageBus.Applications.Add(systemApp);

            var app = new Application()
            {
                Name           = "AppA",
                Key            = "ContosoMessageBus:AppA",
                ResourceMapKey = "application"
            };

            model.MigrationTarget.MessageBus.Applications.Add(app);

            // Add an application message
            var appMessage = new DocumentMessage()
            {
                Name          = "PurchaseOrderFlatFile",
                MessageSchema = new MessageSchema
                {
                    ResourceKeyRef = messageResource1.Key,
                    Name           = messageResource2.Name
                },
                Key            = "ContosoMessageBus:AppA:PurchaseOrderFlatFile",
                ContentType    = MessageContentType.Xml,
                ResourceMapKey = "applicationMessage"
            };

            app.Messages.Add(appMessage);

            var appMessageResource1 = new TargetResourceTemplate()
            {
                OutputPath   = "OutputPath",
                ResourceType = ModelConstants.ResourceTypeXml
            };

            appMessage.Resources.Add(appMessageResource1);

            var transform = new MessageTransform
            {
                Name           = "MessageTransform",
                ResourceKeyRef = "transform-1-resource",
            };

            appMessage.MessageTransforms.Add(transform);

            var appMessageResource2 = new TargetResourceTemplate()
            {
                OutputPath   = "OutputPath",
                ResourceType = ModelConstants.ResourceTypeXslt
            };

            appMessage.Resources.Add(appMessageResource2);

            // Add a message box
            var messageBox = new TopicChannel()
            {
                Name           = "MessageBox",
                Key            = "ContosoMessageBus:System:MessageBox",
                ResourceMapKey = "messageBox"
            };

            systemApp.Channels.Add(messageBox);

            // Add a message agent
            var messageAgent = new ContentBasedRouter()
            {
                Name           = "MessageAgent",
                Key            = "ContosoMessageBus:System:MessageAgent",
                ResourceMapKey = "messageAgent"
            };

            systemApp.Intermediaries.Add(messageAgent);

            // Add an FTP endpoint
            var ftpReceive = new AdapterEndpoint()
            {
                Name           = "FtpReceive",
                Key            = "ContosoMessageBus:System:FtpReceive",
                ResourceMapKey = "ftpReceive"
            };

            systemApp.Endpoints.Add(ftpReceive);

            return(model);
        }