/// <summary> /// Creates orchestration entries for any orchestrations found in the given <see cref="AssemblyDefinition"/> and adds them to the given <see cref="ParsedBizTalkApplication"/>. /// </summary> /// <param name="assembly"><see cref="AssemblyDefinition"/> in which to look for orchestrations.</param> /// <param name="application"><see cref="ParsedBizTalkApplication"/> to add orchestration entities to.</param> /// <param name="container">The resource container for the definitions.</param> private void LoadOrchestrations(AssemblyDefinition assembly, ParsedBizTalkApplication application, ResourceContainer container) { // Check if we have any types that inherit from BTXService in the types defined in the assembly var orchTypes = assembly.MainModule.Types.Where(ty => ty.BaseType != null && ty.BaseType.FullName == "Microsoft.BizTalk.XLANGs.BTXEngine.BTXService").ToList(); foreach (var orchType in orchTypes) { // Get orchestration content var orchContent = orchType.Fields.Where(f => f.Name == "_symODXML").Single().Constant.ToString().Replace("\n", string.Empty); // Add definition to resource container var resourceName = orchType.Name; var resourceKey = string.Concat(container.Name, ":", resourceName); container.ResourceDefinitions.Add(new ResourceDefinition() { Key = resourceKey, Name = resourceName, Type = ModelConstants.ResourceDefinitionOrchestration, ResourceContent = orchContent }); // Add orchestration to model var orch = new Orchestration(container.Key, resourceKey) { FullName = orchType.FullName, ModuleName = assembly.FullName, Name = orchType.Name, Namespace = orchType.Namespace }; application.Application.Orchestrations.Add(orch); _logger.LogDebug(TraceMessages.DiscoveredTheOrchestration, resourceKey); } }
/// <summary> /// Creates pipeline entries for any pipelines found in the given <see cref="AssemblyDefinition"/> and adds them to the given <see cref="ParsedBizTalkApplication"/>. /// </summary> /// <param name="assembly"><see cref="AssemblyDefinition"/> in which to look for pipelines.</param> /// <param name="application"><see cref="ParsedBizTalkApplication"/> to add pipelines entities to.</param> /// <param name="container">The resource container for the definitions.</param> private void LoadSendPipelines(AssemblyDefinition assembly, ParsedBizTalkApplication application, ResourceContainer container) { // Check if we have any types that inherit from Pipeline in the types defined in the assembly var pipelineTypes = assembly.MainModule.Types.Where(ty => ty.BaseType != null && ty.BaseType.FullName == "Microsoft.BizTalk.PipelineOM.SendPipeline").ToList(); foreach (var pipelineType in pipelineTypes) { // Get pipeline content var pipelineContent = pipelineType.Fields.Where(f => f.Name == "_strPipeline").Single().Constant.ToString(); // Add definition to resource container var resourceName = pipelineType.Name; var resourceKey = string.Concat(container.Name, ":", resourceName); container.ResourceDefinitions.Add(new ResourceDefinition() { Key = resourceKey, Name = resourceName, Type = ModelConstants.ResourceDefinitionSendPipeline, ResourceContent = pipelineContent }); // And send pipeline to model var pipeline = new Pipeline(container.Key, resourceKey) { FullName = pipelineType.FullName, ModuleName = assembly.FullName, Name = pipelineType.Name, Namespace = pipelineType.Namespace, Direction = PipelineDirection.Send }; application.Application.Pipelines.Add(pipeline); _logger.LogDebug(TraceMessages.DiscoveredTheSendPipeline, resourceKey); } }
/// <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); }
/// <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 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); }
protected Root ParsePipelineData(ParsedBizTalkApplication application, string sendPortName, string pipelineData, PipelineDirection direction, List <IErrorMessage> errors) { Root pipelineConfiguration = null; try { // Only parse if there is data. if (!string.IsNullOrEmpty(pipelineData)) { _logger.LogDebug(TraceMessages.ParsingBizTalkSendPortPipelineData, sendPortName); pipelineConfiguration = Root.FromXml(pipelineData); _logger.LogDebug(TraceMessages.ParsedBizTalkSendPortPipelineData, sendPortName); } } catch (Exception ex) { var message = FormatErrorMessage(direction, sendPortName, application.Application.Name, ex.Message); errors.Add(new ErrorMessage(message)); } return(pipelineConfiguration); }
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 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. }); }
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"); }); }
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. }); }
/// <summary> /// Creates transform enitites for any transforms found in the given <see cref="AssemblyDefinition"/> and adds them to the given <see cref="ParsedBizTalkApplication"/>. /// </summary> /// <param name="assembly"><see cref="AssemblyDefinition"/> in which to look for transforms.</param> /// <param name="application"><see cref="ParsedBizTalkApplication"/> to add transform entities to.</param> /// <param name="container">The resource container for the definitions.</param> private void LoadTransforms(AssemblyDefinition assembly, ParsedBizTalkApplication application, ResourceContainer container) { // Check if we have any types that inherit from TransformBase in the types defined in the assembly var transformTypes = assembly.MainModule.Types.Where(ty => ty.BaseType != null && ty.BaseType.FullName == "Microsoft.XLANGs.BaseTypes.TransformBase").ToList(); foreach (var transformType in transformTypes) { // Get transform content var transformContent = transformType.Fields.Where(f => f.Name == "_strMap").Single().Constant.ToString(); // Add definition to resource container var resourceName = transformType.Name; var resourceKey = string.Concat(container.Name, ":", resourceName); container.ResourceDefinitions.Add(new ResourceDefinition() { Key = resourceKey, Name = resourceName, Type = ModelConstants.ResourceDefinitionMap, ResourceContent = transformContent }); // Add transform to model var transform = new Transform(container.Key, resourceKey) { FullName = transformType.FullName, ModuleName = assembly.FullName, Name = transformType.Name, Namespace = transformType.Namespace }; // Add schemas var i = 0; bool sourceDone, targetDone; sourceDone = targetDone = false; for (;;) { // Check source schema if (!sourceDone) { var sourceSchemaName = string.Format(CultureInfo.InvariantCulture, "_strSrcSchemasList{0}", i); var sourceSchema = GetFieldConstantValue(transformType, sourceSchemaName); if (!string.IsNullOrWhiteSpace(sourceSchema)) { transform.SourceSchemaTypeNames.Add(sourceSchema); } else { sourceDone = true; } } // Check target schema if (!targetDone) { var targetSchemaName = string.Format(CultureInfo.InvariantCulture, "_strTrgSchemasList{0}", i); var targetSchema = GetFieldConstantValue(transformType, targetSchemaName); if (!string.IsNullOrWhiteSpace(targetSchema)) { transform.TargetSchemaTypeNames.Add(targetSchema); } else { targetDone = true; } } // Done? if (sourceDone && targetDone) { break; } else { i++; } } application.Application.Transforms.Add(transform); _logger.LogDebug(TraceMessages.DiscoveredTheTransform, resourceKey); } }
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(); }); }
/// <summary> /// Creates a default object model for analyzing and building a report. /// </summary> /// <returns></returns> public static AzureIntegrationServicesModel CreateDefaultModelForAnalyzing() { 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 = "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" }; 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 schema 1.", Type = ModelConstants.ResourceMessageType, Key = "document-schema-1:schema:Root", 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" }; resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition2); var schemaResource2 = new ResourceItem() { Name = "DocumentSchema2", Description = "This is document schema 2.", Type = ModelConstants.ResourceDocumentSchema, Key = "document-schema-2:schema", ParentRefId = schemaResourceDefinition2.RefId }; schemaResourceDefinition2.Resources.Add(schemaResource2); var messageResource2 = new ResourceItem() { Name = "Message2", Description = "This is message schema 2.", Type = ModelConstants.ResourceMessageType, Key = "document-schema-2:schema:Root", 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" }; resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition3); var schemaResource3 = new ResourceItem() { Name = "PropertySchema1", Description = "This is property schema 1 resource.", 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 schema 3.", Type = ModelConstants.ResourceMessageType, Key = "document-schema-3:schema:Root", ParentRefId = schemaResource3.RefId }; schemaResource3.Resources.Add(messageResource3); var schemaResourceDefinition4 = new ResourceDefinition() { Name = "EnvelopeSchema1", Description = "This is envelope schema 1.", Type = ModelConstants.ResourceDefinitionSchema, Key = "envelope-schema-1" }; resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition4); var schemaResource4 = new ResourceItem() { Name = "EnvelopeSchema1", Description = "This is envelope schema 1.", Type = ModelConstants.ResourceDocumentSchema, Key = "envelope-schema-1:schema", ParentRefId = schemaResourceDefinition1.RefId }; schemaResourceDefinition4.Resources.Add(schemaResource4); var messageResource4 = new ResourceItem() { Name = "Envelope1", Description = "This is envelope schema 1.", Type = ModelConstants.ResourceMessageType, Key = "envelope-schema-1:schema:Envelope", ParentRefId = schemaResource4.RefId }; schemaResource4.Resources.Add(messageResource4); var contextProperty1 = new ResourceItem() { Name = "Property1", Description = "This is property 2", Key = "property-schema-1:schema:Property1", Type = ModelConstants.ResourcePropertySchema }; schemaResource3.Resources.Add(contextProperty1); var contextProperty2 = new ResourceItem() { Name = "Property2", Description = "This is property 2", Key = "property-schema-1:schema:Property2", Type = ModelConstants.ResourcePropertySchema }; schemaResource3.Resources.Add(contextProperty2); var transformResourceDefinition1 = new ResourceDefinition() { Name = "Transform1", Description = "This is transform 1.", Type = ModelConstants.ResourceDefinitionMap, Key = "transform-1" }; resourceContainer.ResourceDefinitions.Add(transformResourceDefinition1); var transformResourceDefinition2 = new ResourceDefinition() { Name = "Transform2", Description = "This is transform 2.", Type = ModelConstants.ResourceDefinitionMap, Key = "transform-2" }; resourceContainer.ResourceDefinitions.Add(transformResourceDefinition2); var transformResource1 = new ResourceItem() { Name = "Transform1", Description = "This is the transform 1, resource", Type = ModelConstants.ResourceMap, Key = "transform-1-resource" }; transformResourceDefinition1.Resources.Add(transformResource1); schemaResource1.ResourceRelationships.Add(new ResourceRelationship { ResourceRelationshipType = ResourceRelationshipType.ReferencedBy, ResourceRefId = transformResource1.RefId, }); var transformResource2 = new ResourceItem() { Name = "Transform2", Description = "This is the transform 2, resource", Type = ModelConstants.ResourceMap, Key = "transform-2-resource" }; transformResourceDefinition2.Resources.Add(transformResource2); var bindingResourceDefinition1 = new ResourceDefinition() { Name = "Binding1", Description = "This is binding 1.", Type = ModelConstants.ResourceDefinitionBindings, Key = "binding-1" }; resourceContainer.ResourceDefinitions.Add(bindingResourceDefinition1); var sendPortResource1 = new ResourceItem() { Name = "Test.SendPorts.SendPort1", Description = "This is sendport 1.", Type = ModelConstants.ResourceSendPort, 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 = "sendport-1-filter" }; sendPortResource1.Resources.Add(sendPortFilterResource1); var receivePortResource1 = new ResourceItem() { Name = "ReceivePort1", Description = "This is receive port 1.", Type = ModelConstants.ResourceReceivePort, Key = "receiveport-1" }; bindingResourceDefinition1.Resources.Add(receivePortResource1); var receiveLocation1 = new ResourceItem() { Name = "ReceiveLocation1", Description = "This is receive location 1.", Type = ModelConstants.ResourceReceiveLocation, Key = "receivelocation-1" }; receivePortResource1.Resources.Add(receiveLocation1); var distributionListResource1 = new ResourceItem { Name = "DistributionList1", Description = "This is distributionlist 1.", Type = ModelConstants.ResourceDistributionList, Key = "distributionlist-1" }; bindingResourceDefinition1.Resources.Add(distributionListResource1); var distributionListFilterResource1 = new ResourceItem { Name = "DistributionListFilter1", Description = "This is distribution list filer 1.", Type = ModelConstants.ResourceFilterExpression, 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() }; // Create application definitions application1.Application.ApplicationDefinition = new ApplicationDefinitionFile() { ResourceContainerKey = resourceContainer.Key, ResourceDefinitionKey = appResourceDefinition1.Key, ResourceKey = appResource1.Key, Resource = appResource1, 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, Resource = appResource2, 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, Resource = appResource3, 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, Resource = schemaResource1, SchemaType = BizTalkSchemaType.Document }; var messageDefinition1 = new MessageDefinition(documentSchema1.RootNodeName, documentSchema1.XmlNamespace, "Test.Schemas.DocumentSchema1", "DocumentSchema1", messageResource1.Key); messageResource1.SourceObject = messageDefinition1; documentSchema1.MessageDefinitions.Add(messageDefinition1); documentSchema1.PromotedProperties.Add(new PromotedProperty() { PropertyType = "Test.Schemas.PropertySchema1.Property1", XPath = "some xpath 1" }); messageDefinition1.PromotedProperties.Add(new PromotedProperty() { PropertyType = "Test.Schemas.PropertySchema1.Property1", XPath = "some xpath 1" }); 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, Resource = schemaResource2, SchemaType = BizTalkSchemaType.Document }; var messageDefinition2 = new MessageDefinition(documentSchema2.RootNodeName, documentSchema2.XmlNamespace, "Test.Schemas.DocumentSchema2", "DocumentSchema2", messageResource2.Key); messageResource2.SourceObject = messageDefinition2; documentSchema2.MessageDefinitions.Add(messageDefinition2); 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, Resource = schemaResource3, SchemaType = BizTalkSchemaType.Property }; propertySchema.ContextProperties.Add(new ContextProperty() { DataType = "xs:string", FullyQualifiedName = "Test.Schemas.PropertySchema1.Property1", PropertyName = contextProperty1.Name, Namespace = "Test.Schemas.PropertySchema1", ResourceKey = contextProperty1.Key, Resource = contextProperty1 }); propertySchema.ContextProperties.Add(new ContextProperty() { DataType = "xs:int", FullyQualifiedName = "Test.Schemas.PropertySchema1.Property2", PropertyName = contextProperty2.Name, Namespace = "Test.Schemas.PropertySchema1", ResourceKey = contextProperty2.Key, Resource = contextProperty2 }); application1.Application.Schemas.Add(propertySchema); var envelopeSchema1 = new Types.Entities.Schema() { Name = "EnvelopeSchema1", Namespace = "Test.Schemas", FullName = "Test.Schemas.EnvelopeSchema1", XmlNamespace = "http://schemas.test.com/EnvelopeSchema1", RootNodeName = "Envelope", IsEnvelope = true, BodyXPath = "/*[local-name()='Envelope' and namespace-uri()='http://schemas.test.com/EnvelopeSchema1']/*[local-name()='Body' and namespace-uri()='http://schemas.test.com/EnvelopeSchema1']", ResourceDefinitionKey = schemaResourceDefinition4.Key, ResourceKey = schemaResource4.Key, Resource = schemaResource4, SchemaType = BizTalkSchemaType.Document }; var messageDefinition3 = new MessageDefinition(envelopeSchema1.RootNodeName, envelopeSchema1.XmlNamespace, "Test.Schemas.EnvelopeSchema1", "EnvelopeSchema1", messageResource4.Key); messageResource4.SourceObject = messageDefinition3; envelopeSchema1.MessageDefinitions.Add(messageDefinition2); application1.Application.Schemas.Add(envelopeSchema1); // Create transforms var map1 = 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, ResourceKey = transformResource1.Key, Resource = transformResource1 }; map1.SourceSchemaTypeNames.Add("Test.Schemas.DocumentSchema1"); map1.TargetSchemaTypeNames.Add("Test.Schemas.DocumentSchema2"); transformResource1.SourceObject = map1; application1.Application.Transforms.Add(map1); var map2 = new Types.Entities.Transform() { Name = "Transform2", FullName = "Test.Maps.Transform2", ModuleName = "Test.Maps, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", Namespace = "Test.Maps", ResourceContainerKey = resourceContainer.Key, ResourceDefinitionKey = transformResourceDefinition1.Key, ResourceKey = transformResource2.Key, Resource = transformResource2 }; map2.SourceSchemaTypeNames.Add("Test.Schemas.DocumentSchema2"); map2.TargetSchemaTypeNames.Add("Test.Schemas.DocumentSchema1"); transformResource2.SourceObject = map2; application1.Application.Transforms.Add(map2); // Create send ports. var sendPort = new SendPort { ResourceKey = sendPortResource1.Key, Resource = sendPortResource1, Description = "This is a send port description.", Name = "Test.SendPorts.SendPort1", PrimaryTransport = new TransportInfo { TransportType = new ProtocolType { Name = "FTP" }, TransportTypeData = "<CustomProps><AdapterConfig vt=\"8\"><Config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><uri>ftp://127.0.0.1:22/%MessageID%.xml</uri><serverAddress>127.0.0.1</serverAddress><serverPort>22</serverPort><ftpServerType>Detect</ftpServerType><targetFolder /><targetFileName>%MessageID%.xml</targetFileName><representationType>binary</representationType><allocateStorage>False</allocateStorage><appendIfExists>False</appendIfExists><connectionLimit>0</connectionLimit><passiveMode>False</passiveMode><firewallType>NoFirewall</firewallType><firewallPort>22</firewallPort><useSsl>False</useSsl><useDataProtection>True</useDataProtection><ftpsConnMode>Explicit</ftpsConnMode></Config></AdapterConfig></CustomProps>", }, 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() } } } }, Transforms = new Types.Entities.Bindings.Transform[1] { new Types.Entities.Bindings.Transform() { FullName = map2.FullName, AssemblyQualifiedName = $"{map2.Name}, {map2.ModuleName}" } }, InboundTransforms = new Types.Entities.Bindings.Transform[1] { new Types.Entities.Bindings.Transform() { FullName = map1.FullName, AssemblyQualifiedName = $"{map1.Name}, {map1.ModuleName}" } } }; sendPortResource1.SourceObject = sendPort; /// Create receive ports. var receivePort = new ReceivePort { ResourceKey = receivePortResource1.Key, Resource = receivePortResource1, Description = receivePortResource1.Description, Name = receivePortResource1.Name, ReceiveLocations = new ReceiveLocation[] { new ReceiveLocation { ResourceKey = receiveLocation1.Key, Name = receiveLocation1.Name, Description = receiveLocation1.Name, ReceiveLocationTransportType = new ProtocolType { Name = "FTP", }, ReceiveLocationTransportTypeData = "<CustomProps><AdapterConfig vt=\"8\"><Config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><uri>ftp://127.0.0.1:21/*.*</uri><serverAddress>127.0.0.1</serverAddress><serverPort>21</serverPort><userName>btsuser</userName><password>******</password><ftpServerType>Detect</ftpServerType><fileMask>*.*</fileMask><targetFolder /><representationType>binary</representationType><receiveDataTimeout>90000</receiveDataTimeout><maximumBatchSize>0</maximumBatchSize><maximumNumberOfFiles>0</maximumNumberOfFiles><passiveMode>False</passiveMode><useNLST>False</useNLST><firewallType>NoFirewall</firewallType><firewallPort>21</firewallPort><pollingUnitOfMeasure>Seconds</pollingUnitOfMeasure><pollingInterval>60</pollingInterval><redownloadInterval>-1</redownloadInterval><errorThreshold>10</errorThreshold><maxFileSize>100</maxFileSize><useSsl>False</useSsl><useDataProtection>True</useDataProtection><ftpsConnMode>Explicit</ftpsConnMode><deleteAfterDownload>True</deleteAfterDownload><enableTimeComparison>False</enableTimeComparison></Config></AdapterConfig></CustomProps>" } }, Transforms = new Types.Entities.Bindings.Transform[1] { new Types.Entities.Bindings.Transform() { FullName = map1.FullName, AssemblyQualifiedName = $"{map1.Name}, {map1.ModuleName}" } }, OutboundTransforms = new Types.Entities.Bindings.Transform[1] { new Types.Entities.Bindings.Transform() { FullName = map2.FullName, AssemblyQualifiedName = $"{map2.Name}, {map2.ModuleName}" } } }; // Create distribution lists. var distributionList = new DistributionList { ResourceKey = distributionListResource1.Key, Resource = distributionListResource1, 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() } }, SendPorts = new SendPortRef[] { new SendPortRef() { Name = sendPort.Name } } }; distributionListResource1.SourceObject = distributionList; application1.Application.Bindings = new BindingFile { BindingInfo = new BindingInfo { SendPortCollection = new SendPort[] { sendPort }, ReceivePortCollection = new ReceivePort[] { receivePort }, DistributionListCollection = new DistributionList[] { distributionList } } }; return(aisModel); }
/// <summary> /// Creates schema enitites for any schemas found in the given <see cref="AssemblyDefinition"/> and adds them to the given <see cref="ParsedBizTalkApplication"/>. /// </summary> /// <param name="assemblyDefinition"><see cref="AssemblyDefinition"/> in which to look for schemas.</param> /// <param name="application"><see cref="ParsedBizTalkApplication"/> to add schema entities to.</param> /// <param name="container">The resource container for the definitions.</param> private void LoadSchemas(AssemblyDefinition assemblyDefinition, ParsedBizTalkApplication application, ResourceContainer container) { // Check if we have any schema attributes in the types defined in the assembly var schemaTypes = assemblyDefinition.MainModule.Types.Where(ty => ty.BaseType != null && ty.BaseType.FullName == SchemaBaseType).ToList(); _logger.LogDebug(TraceMessages.DiscoveringTheSchemasInResourceContainer, container.Key); foreach (var schemaType in schemaTypes) { // Get schema content var schemaContent = schemaType.Fields.Where(f => f.Name == "_strSchema").Single().Constant.ToString(); // Add definition to resource container var resourceName = schemaType.Name; var resourceDefinitionKey = string.Concat(container.Key, ":", resourceName); container.ResourceDefinitions.Add(new ResourceDefinition() { Key = resourceDefinitionKey, Name = resourceName, Type = ModelConstants.ResourceDefinitionSchema, ResourceContent = schemaContent }); // Add schema object to model var schema = new Schema(container.Key, resourceDefinitionKey) { Name = schemaType.Name, FullName = schemaType.FullName, ModuleName = assemblyDefinition.FullName, Namespace = schemaType.Namespace, SchemaType = HasCustomAttribute(schemaType, SchemaAttributeType) ? BizTalkSchemaType.Document : BizTalkSchemaType.Unknown, IsEnvelope = HasCustomAttribute(schemaType, BodyXPathAttributeType) ? true : false, ResourceKey = resourceDefinitionKey + ":schema", BodyXPath = GetCustomAttributeConstructorValue(schemaType, BodyXPathAttributeType, 0), XmlNamespace = GetCustomAttributeConstructorValue(schemaType, SchemaAttributeType, 0), RootNodeName = GetCustomAttributeConstructorValue(schemaType, SchemaAttributeType, 1) }; // Property schemas are recognised by this annotation in the XML. if (schemaContent.Contains("<b:schemaInfo schema_type=\"property\" xmlns:b=\"http://schemas.microsoft.com/BizTalk/2003\" />")) { schema.SchemaType = BizTalkSchemaType.Property; } application.Application.Schemas.Add(schema); _logger.LogDebug(TraceMessages.DiscoveredTheSchema, schema.FullName); // Get the promoted properties and distinguished fields for the schema. schema.PromotedProperties.AddRange(ExtractPromotedProperties(schemaType)); ExtractDistinguishedFields(schemaType, schema); // If the schema defines a root node and namespace then create a message definition. if (!string.IsNullOrEmpty(GetCustomAttributeConstructorValue(schemaType, SchemaAttributeType, 1))) { // Create the message definition. var messageDefinition = CreateMessageDefinition(schemaType.FullName, schemaType.Name, schemaType, schema.ResourceKey); // Add the message definitions to the parent schema. schema.MessageDefinitions.Add(messageDefinition); } // Multiple root nodes in a schema manifest themselves as nested types. Create a separate schema object for each of these. if (schemaType.HasNestedTypes) { var nestedTypes = schemaType.NestedTypes.Where(ty => ty.BaseType != null && ty.BaseType.FullName == SchemaBaseType).ToList(); foreach (var nestedType in nestedTypes) { var messageName = $"{schemaType.Name}.{nestedType.Name}"; // Create the message definition. var messageDefinition = CreateMessageDefinition(nestedType.FullName, messageName, nestedType, schema.ResourceKey); // Multi-root schemas, dont have the custom attribute set at the root class, its on the nested types. // Check to see if it should be set for the nested type. if (schema.SchemaType != BizTalkSchemaType.Document && HasCustomAttribute(nestedType, SchemaAttributeType)) { schema.SchemaType = BizTalkSchemaType.Document; } // Add the message definitions to the parent schema. schema.MessageDefinitions.Add(messageDefinition); } schema.XmlNamespace = GetCustomAttributeConstructorValue(nestedTypes.First(), SchemaAttributeType, 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 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); }); }
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"); }); }
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 ParseFailsWhenPipelineResourceIsMissing(PipelineComponentParser parser, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e) { var receivePiplineDefinitionName = "receivePiplineDefinitionName "; var receivePipelineDefinitionKey = "receivePipelineDefinitionKey"; var receivePipelineDefinitionDescription = "receivePipelineDescription"; var receivePipelineResourceKey = "receivePipelineResourceKey"; var receivePipelineComponentName = "receivePipelineComponentName"; var receivePipelineComponentDescription = "receivePipelineComponentDescription"; "Given a source model with a receive pipeline and component" .x(() => { var pipelineComponentDocument = new Document { Stages = new DocumentStage[] { new DocumentStage { Components = new DocumentStageComponent[] { new DocumentStageComponent { ComponentName = receivePipelineComponentName, Description = receivePipelineComponentDescription } } } } }; var receivePipeline = new Pipeline { Name = receivePiplineDefinitionName, ResourceDefinitionKey = receivePipelineDefinitionKey, Direction = PipelineDirection.Receive, Description = receivePipelineDefinitionDescription, Document = pipelineComponentDocument, ResourceKey = receivePipelineResourceKey }; var parsedApplication = new ParsedBizTalkApplication { Application = new BizTalkApplication() }; parsedApplication.Application.Pipelines.Add(receivePipeline); var aisModel = new AzureIntegrationServicesModel(); var group = new ParsedBizTalkApplicationGroup(); aisModel.MigrationSource.MigrationSourceModel = group; group.Applications.Add(parsedApplication); model = aisModel; }); "And no receive pipeline resource in the source model" .x(() => { var msiReportContainer = new ResourceContainer { Type = ModelConstants.ResourceContainerMsi, Key = "msiContainerKey", Name = "msiContainerName" }; var cabReportContainer = new ResourceContainer { Type = ModelConstants.ResourceContainerCab, Key = "cabContainerKey", Name = "cabContainerName" }; var assemblyReportContainer = new ResourceContainer { Type = ModelConstants.ResourceContainerAssembly, Key = "assemblyContainerKey", Name = "assemblyContainerName" }; var receivePipelineReportDefinition = new ResourceDefinition { Type = ModelConstants.ResourceDefinitionOrchestration, Key = receivePipelineDefinitionKey, Name = receivePiplineDefinitionName }; assemblyReportContainer.ResourceDefinitions.Add(receivePipelineReportDefinition); cabReportContainer.ResourceContainers.Add(assemblyReportContainer); msiReportContainer.ResourceContainers.Add(cabReportContainer); model.MigrationSource.ResourceContainers.Add(msiReportContainer); }); "And a logger" .x(() => logger = new Mock <ILogger>().Object); "And a context" .x(() => context = new MigrationContext()); "And a parser" .x(() => parser = new PipelineComponentParser(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 context error" .x(() => { context.Errors.Should().NotBeNullOrEmpty(); context.Errors.Should().HaveCount(1); context.Errors[0].Message.Should().Contain(receivePipelineResourceKey); context.Errors[0].Message.Should().Contain(ModelConstants.ResourceReceivePipeline); }); }
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 ParseSuccessfulSingleSendPipelineComponent(PipelineComponentParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, Exception e) { var sendPiplineDefinitionName = "sendPiplineDefinitionName "; var sendPipelineDefinitionKey = "sendPipelineDefinitionKey"; var sendPipelineDefinitionDescription = "sendPipelineDescription"; var sendPipelineResourceKey = "sendPipelineResourceKey"; var sendPipelineResourceName = "sendPipelineResourceName"; var sendPipelineComponentName = "sendPipelineComponentName"; var sendPipelineComponentDescription = "sendPipelineComponentDescription"; "Given a source model with a send pipeline and component" .x(() => { var pipelineComponentDocument = new Document { Stages = new DocumentStage[] { new DocumentStage { Components = new DocumentStageComponent[1] { new DocumentStageComponent { ComponentName = sendPipelineComponentName, Description = sendPipelineComponentDescription } } } } }; var sendPipeline = new Pipeline { Name = sendPiplineDefinitionName, ResourceDefinitionKey = sendPipelineDefinitionKey, Direction = PipelineDirection.Send, Description = sendPipelineDefinitionDescription, Document = pipelineComponentDocument, ResourceKey = sendPipelineResourceKey }; var parsedApplication = new ParsedBizTalkApplication { Application = new BizTalkApplication() }; parsedApplication.Application.Pipelines.Add(sendPipeline); var aisModel = new AzureIntegrationServicesModel(); var group = new ParsedBizTalkApplicationGroup(); aisModel.MigrationSource.MigrationSourceModel = group; group.Applications.Add(parsedApplication); model = aisModel; }); "And one send pipeline resource in the source model" .x(() => { var msiReportContainer = new ResourceContainer { Type = ModelConstants.ResourceContainerMsi, Key = "msiContainerKey", Name = "msiContainerName" }; var cabReportContainer = new ResourceContainer { Type = ModelConstants.ResourceContainerCab, Key = "cabContainerKey", Name = "cabContainerName" }; var assemblyReportContainer = new ResourceContainer { Type = ModelConstants.ResourceContainerAssembly, Key = "assemblyContainerKey", Name = "assemblyContainerName" }; var sendPipelineReportDefinition = new ResourceDefinition { Type = ModelConstants.ResourceDefinitionOrchestration, Key = sendPipelineDefinitionKey, Name = sendPiplineDefinitionName }; var sendPipelineResource = new ResourceItem { Type = ModelConstants.ResourceSendPipeline, Name = sendPipelineResourceName, Key = sendPipelineResourceKey }; sendPipelineReportDefinition.Resources.Add(sendPipelineResource); assemblyReportContainer.ResourceDefinitions.Add(sendPipelineReportDefinition); cabReportContainer.ResourceContainers.Add(assemblyReportContainer); msiReportContainer.ResourceContainers.Add(cabReportContainer); model.MigrationSource.ResourceContainers.Add(msiReportContainer); }); "And a logger" .x(() => logger = new Mock <ILogger>().Object); "And a context" .x(() => context = new MigrationContext()); "And a parser" .x(() => parser = new PipelineComponentParser(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 source model should have a pipeline component under the send pipeline resource in the source report" .x(() => { model.Should().NotBeNull(); model.MigrationSource.Should().NotBeNull(); model.MigrationSource.ResourceContainers[0].Should().NotBeNull(); model.MigrationSource.ResourceContainers[0].ResourceContainers[0].Should().NotBeNull(); model.MigrationSource.ResourceContainers[0].ResourceContainers[0].ResourceContainers[0].Should().NotBeNull(); model.MigrationSource.ResourceContainers[0].ResourceContainers[0].ResourceContainers[0].ResourceDefinitions.Should().NotBeNull(); model.MigrationSource.ResourceContainers[0].ResourceContainers[0].ResourceContainers[0].ResourceDefinitions.Should().HaveCount(1); var sendPipeline = ((ParsedBizTalkApplicationGroup)model.MigrationSource.MigrationSourceModel).Applications[0].Application.Pipelines[0]; var sendPipelineDefinition = model.MigrationSource.ResourceContainers[0].ResourceContainers[0].ResourceContainers[0].ResourceDefinitions[0]; sendPipelineDefinition.Resources.Should().NotBeNull(); sendPipelineDefinition.Resources.Should().HaveCount(1); // Validate the send pipeline. var sendPipelineResource = sendPipelineDefinition.Resources[0]; sendPipelineResource.Resources.Should().NotBeNull(); sendPipelineResource.Resources.Should().HaveCount(1); // Validate the pipeline components. var pipelineComponentResource = sendPipelineResource.Resources[0]; pipelineComponentResource.Type.Should().Be(ModelConstants.ResourcePipelineComponent); pipelineComponentResource.Name.Should().Be(sendPipelineComponentName); pipelineComponentResource.Description.Should().Be(sendPipelineComponentDescription); pipelineComponentResource.Key.Should().Be(string.Concat(sendPipelineResource.Key, ":", pipelineComponentResource.Name)); sendPipeline.Document.Stages[0].Components[0].Resource.Should().Be(pipelineComponentResource); // The pointer to the resource should be set. pipelineComponentResource.ParentRefId.Should().Be(sendPipelineResource.RefId); // The parent ref ID should be set. var stageComponents = Document.FindStageComponents(sendPipeline.Document); pipelineComponentResource.SourceObject.Should().Be(stageComponents.First()); // 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); }); }
/// <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); }
/// <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); }
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); }); }