public void ConstructWithSuccess(DP004ApplicationDependencyAnalyzer analyzer, ILogger logger, IApplicationModel model, MigrationContext context, Exception e) { "Given an analyzer" .x(() => analyzer.Should().BeNull()); "And a model" .x(() => model = new AzureIntegrationServicesModel()); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "When constructing" .x(() => e = Record.Exception(() => new DP004ApplicationDependencyAnalyzer(model, context, logger))); "Then the constructor should NOT throw an exception" .x(() => e.Should().BeNull()); }
public void ConstructWithNullLogger(DP004ApplicationDependencyAnalyzer analyzer, ILogger logger, IApplicationModel model, MigrationContext context, Exception e) { "Given an analyzer" .x(() => analyzer.Should().BeNull()); "And a model" .x(() => model = new AzureIntegrationServicesModel()); "And a context" .x(() => context = TestHelper.BuildContext()); "And null logger" .x(() => logger.Should().BeNull()); "When constructing with a null logger" .x(() => e = Record.Exception(() => new DP004ApplicationDependencyAnalyzer(model, context, logger))); "Then the constructor should throw an exception" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("logger")); }
public void ConstructWithNullContext(IBizTalkParser parser, ILogger logger, IApplicationModel model, MigrationContext context, Exception e) { "Given a parser" .x(() => parser.Should().BeNull()); "And a logger" .x(() => logger = new Mock <ILogger>().Object); "And a model" .x(() => model = new AzureIntegrationServicesModel()); "And a null context" .x(() => context.Should().BeNull()); "When constructing with null context" .x(() => e = Record.Exception(() => new DocumentSchemaParser(model, context, logger))); "Then the parser constructor should throw an exception" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("context")); }
public void ConstructWithNullContext(AP002SystemApplicationAnalyzer analyzer, ILogger logger, IApplicationModel model, MigrationContext context, Exception e) { "Given an analyzer" .x(() => analyzer.Should().BeNull()); "And a model" .x(() => model = new AzureIntegrationServicesModel()); "And null context" .x(() => context.Should().BeNull()); "And a logger" .x(() => logger = _mockLogger.Object); "When constructing with a null context" .x(() => e = Record.Exception(() => new AP002SystemApplicationAnalyzer(model, context, logger))); "Then the constructor should throw an exception" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("context")); }
public void ReportHtmlGenerationNoContainers(HtmlReportFormatter reporter, AzureIntegrationServicesModel model, MigrationContext context, IRunState state, IReportWriter writer, ILogger logger, Exception e) { "Given a model" .x(() => { model = TestHelper.BuildModel(); model.MigrationSource.ResourceContainers.Clear(); //removes any resource containers. }); "And run state" .x(() => state = TestHelper.BuildRunState(model)); "And a context" .x(() => context = TestHelper.BuildContext()); "And a writer" .x(() => writer = _mockWriter.Object); "And a logger" .x(() => logger = _mockLogger.Object); "And an reporter" .x(() => reporter = new HtmlReportFormatter(model, context, state, writer, logger)); "When executing the report formatter" .x(() => e = Record.Exception(() => reporter.Report())); "Then there should be no exception" .x(() => e.Should().BeNull()); "The report node should have a source application" .x(() => { _mockWriter.Invocations.Count.Should().Be(4); _mockWriter.Invocations[0].Arguments.Count.Should().Be(2); _mockWriter.Invocations[0].Arguments[0].Should().Be(context.ReportFilePath); _mockWriter.Invocations[0].Arguments[1].Should().NotBeNull(); var html = (string)_mockWriter.Invocations[0].Arguments[1]; html.Should().Contain("No Input BizTalk Applications"); }); }
public void CreateMessageBoxFailsWithNoSystemApplication(MB002MessageBoxAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e) { "Given an analyzer" .x(() => analyzer.Should().BeNull()); "And a model with a message bus" .x(() => { model = new AzureIntegrationServicesModel(); model.MigrationTarget.MessageBus = new ApplicationModel.Target.MessageBus { Name = "messageBusName", Key = "MessageBus" }; }); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And an analyzer" .x(() => analyzer = new MB002MessageBoxAnalyzer(model, context, logger)); "When analyzing" .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false)); "Then there should be no exception" .x(() => e.Should().BeNull()); "And and the context contains an error" .x(() => { context.Errors.Should().NotBeNullOrEmpty(); context.Errors.Should().HaveCount(1); context.Errors[0].Message.Should().NotBeNullOrEmpty(); context.Errors[0].Message.Should().Contain("MessageBus:SystemApplication"); }); }
public void GetValueTypedModelWithSuccess(AzureIntegrationServicesModel model, int sourceModel, Exception e) { "Given a model" .x(() => { model = _model; model.MigrationSource.MigrationSourceModel = 12; }); "When getting the source model" .x(() => e = Record.Exception(() => sourceModel = model.GetSourceModel <int>())); "Then getting the source model should succeed" .x(() => e.Should().BeNull()); "And the source model contains the expected integer value" .x(() => { sourceModel.Should().Be(12); }); }
public void FindChannelResourceWithSuccess(AzureIntegrationServicesModel model, string templateKey, TargetResourceTemplate resource, Exception e) { "Given a model" .x(() => model = _model); "And a template key" .x(() => templateKey = "topicChannelAzureServiceBusStandard"); "When finding the resource template" .x(() => e = Record.Exception(() => resource = CustomLiquidFunctions.FindResourceTemplate(model, templateKey))); "Then the find should succeed" .x(() => e.Should().BeNull()); "And the target resource should be the expected value from the model" .x(() => { resource.Should().NotBeNull(); resource.TemplateKey.Should().Be("topicChannelAzureServiceBusStandard"); }); }
public void ParseWithOneApplicationAndNoPipelines(BizTalkPipelineParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e) { "Given a model with one application and no pipelines" .x(() => { model = new AzureIntegrationServicesModel(); group = new ParsedBizTalkApplicationGroup(); model.MigrationSource.MigrationSourceModel = group; group.Applications.Add(new ParsedBizTalkApplication() { Application = new BizTalkApplication { ApplicationDefinition = new ApplicationDefinitionFile { ResourceKey = "ResourceKey" } } }); }); "And a logger" .x(() => logger = new Mock <ILogger>().Object); "And a context" .x(() => context = new MigrationContext()); "And a BizTalk Pipeline Parser" .x(() => parser = new BizTalkPipelineParser(model, context, logger)); "When parsing" .x(() => e = Record.Exception(() => parser.Parse())); "Then the parser should not throw an exception" .x(() => e.Should().BeNull()); "And the error count should be 0" .x(() => { context.Errors.Should().BeNullOrEmpty(); }); }
public void ParseFailureNoBindings(PipelineDataParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e) { "Given a model" .x(() => { model = new AzureIntegrationServicesModel(); group = CreateGroup(Array.Empty <SendPort>()); model.MigrationSource.MigrationSourceModel = group; group.Applications[0].Application.Bindings = null; // Blank bindings forces a skip in processing. }); "And a logger" .x(() => logger = _mockLogger.Object); "And a context" .x(() => context = new MigrationContext()); "And a parser" .x(() => parser = new SendPortPipelineDataParser(model, context, logger)); "When parsing" .x(() => e = Record.Exception(() => parser.Parse())); "And the model should be parsed with a warning." .x(() => { // There should be no exception logged - this is a handled scenario. context.Errors.Count.Should().Be(0); // The application definition cannot be read and so the name should be default var group = (ParsedBizTalkApplicationGroup)model.MigrationSource.MigrationSourceModel; group.Applications[0].Application.Name.Should().Be("(Unknown)"); // An error should be logged var invocation = _mockLogger.Invocations.Where(i => i.Arguments[0].ToString() == "Warning").FirstOrDefault(); invocation.Should().NotBeNull(); invocation.Arguments[2].ToString().Should().Contain("Unable to find the binding info resource"); }); }
public void RenderSnippetAsyncWithSuccess(ISnippetRenderer renderer, AzureIntegrationServicesModel model, ProcessManager processManager, TargetResourceTemplate resourceTemplate, TargetResourceSnippet resourceSnippet, WorkflowObject workflowObject, string snippetContent, string renderedContent, Exception e) { "Given a snippet renderer" .x(() => renderer = new LiquidSnippetRenderer(_mockLogger.Object)); "And a model" .x(() => model = _model); "And a process manager" .x(() => { var messagingObject = model.FindMessagingObject("ContosoMessageBus:AppA:FtpTransformWorkflow"); messagingObject.messagingObject.Should().NotBeNull().And.BeOfType(typeof(ProcessManager)); processManager = (ProcessManager)messagingObject.messagingObject; resourceTemplate = processManager.Resources.First(); resourceSnippet = processManager.Snippets.First(); }); "And a workflow object" .x(() => { workflowObject = processManager.WorkflowModel.Activities.First(); }); "And a snippet content" .x(() => snippetContent = _snippetContent); "When rendering the snippet" .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderSnippetAsync(snippetContent, model, processManager, resourceTemplate, resourceSnippet, workflowObject))); "Then the render should succeed" .x(() => e.Should().BeNull()); "And the rendered content should have expected values from the model" .x(() => { renderedContent.Should().NotBeNull().And.ContainAny($"StepName:_{workflowObject.Name.Replace(" ", "_", StringComparison.InvariantCulture)}").And.NotContainAny("{{").And.NotContainAny("}}"); }); }
public void ParseOneReceivePortAndInvalidSendData(PipelineDataParser parser, ILogger logger, List <ReceivePort> receivePorts, MigrationContext context, AzureIntegrationServicesModel model, ParsedBizTalkApplicationGroup group, Exception e) { "Given a model with one receive port invalid send data XML" .x(() => { model = new AzureIntegrationServicesModel(); receivePorts = new List <ReceivePort> { new ReceivePort() { Name = "Test Port" } }; receivePorts[0].SendPipelineData = "Invalid XML"; group = CreateGroup(receivePorts.ToArray()); model.MigrationSource.MigrationSourceModel = group; }); "And a logger" .x(() => logger = _mockLogger.Object); "And a context" .x(() => context = new MigrationContext()); "And a parser" .x(() => parser = new ReceivePortPipelineDataParser(model, context, logger)); "When parsing" .x(() => e = Record.Exception(() => parser.Parse())); "Then the code should not throw an exception" .x(() => e.Should().BeNull()); "And there should be one error" .x(() => { context.Errors.Should().HaveCount(1); context.Errors[0].Message.Should().Contain("Send"); }); }
/// <summary> /// Parses the send pipeline data stored as XML in the bindings. /// </summary> /// <param name="model">The model.</param> /// <param name="context">The migration context.</param> protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context) { var group = model.GetSourceModel <ParsedBizTalkApplicationGroup>(); if (group?.Applications == null) { _logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(SendPortPipelineDataParser)); } else { _logger.LogDebug(TraceMessages.RunningParser, nameof(SendPortPipelineDataParser)); foreach (var application in group.Applications) { // Defensive check if (application.Application.Bindings == null) { _logger.LogWarning(WarningMessages.BindingInfoNotFound, application.Application.Name); continue; } _logger.LogDebug(TraceMessages.ParsingBizTalkSendPipelineDataInApplication, application.Application.Name); if (application.Application.Bindings.BindingInfo.SendPortCollection != null) { foreach (var sendPort in application.Application.Bindings.BindingInfo.SendPortCollection) { _logger.LogDebug(TraceMessages.ParsingBizTalkSendPortPipelineDataForSendPort, sendPort.Name); sendPort.SendPipelineCustomConfiguration = ParsePipelineData(application, sendPort.Name, sendPort.SendPipelineData, PipelineDirection.Send, context.Errors); sendPort.ReceivePipelineCustomConfiguration = ParsePipelineData(application, sendPort.Name, sendPort.ReceivePipelineData, PipelineDirection.Receive, context.Errors); } } } _logger.LogDebug(TraceMessages.CompletedParser, nameof(SendPortPipelineDataParser)); } }
public void ConstructWithSuccess(SC001DocumentSchemaGenerator generator, IFileRepository fileRepository, ILogger logger, IApplicationModel model, MigrationContext context, Exception e) { "Given an generator" .x(() => generator.Should().BeNull()); "And a file repository" .x(() => fileRepository = _mockFileRepository.Object); "And a model" .x(() => model = new AzureIntegrationServicesModel()); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "When constructing" .x(() => e = Record.Exception(() => new SC001DocumentSchemaGenerator(fileRepository, model, context, logger))); "Then the constructor should NOT throw an exception" .x(() => e.Should().BeNull()); }
public void ConstructWithNullFileRepository(SC001DocumentSchemaGenerator generator, IFileRepository fileRepository, ILogger logger, IApplicationModel model, MigrationContext context, Exception e) { "Given an generator" .x(() => generator.Should().BeNull()); "And a null file repository" .x(() => fileRepository.Should().BeNull()); "And a model" .x(() => model = new AzureIntegrationServicesModel()); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "When constructing with a null file repository" .x(() => e = Record.Exception(() => new SC001DocumentSchemaGenerator(fileRepository, model, context, logger))); "Then the constructor should throw an exception" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("fileRepository")); }
public void ParseIsSkippedIfModelIsMissing(DistributionListParser parser, ILogger logger, MigrationContext context, AzureIntegrationServicesModel model, Exception e) { "Given a model" .x(() => { model = new AzureIntegrationServicesModel(); }); "And a logger" .x(() => logger = _mockLogger.Object); "And a context" .x(() => context = new MigrationContext()); "And a parser" .x(() => parser = new DistributionListParser(model, context, logger)); "When parsing" .x(() => e = Record.Exception(() => parser.Parse())); "Then the code should not throw an exception" .x(() => e.Should().BeNull()); }
public void DP001RuleSkippedIfModelIsEmpty(DP002TransformDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e) { "Given an source model" .x(() => model = new AzureIntegrationServicesModel()); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And an analyzer" .x(() => analyzer = new DP002TransformDependencyAnalyzer(model, context, logger)); "When analyzing" .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false)); "Then there should be no exception" .x(() => e.Should().BeNull()); "And there should be no context errors" .x(() => context.Errors.Should().HaveCount(0)); }
public void RenderTemplateAsyncWithSuccess(ITemplateRenderer renderer, AzureIntegrationServicesModel model, string templateContent, string renderedContent, Exception e) { "Given a template renderer" .x(() => renderer = new LiquidTemplateRenderer(_mockLogger.Object)); "And a model" .x(() => model = _model); "And a template content" .x(() => templateContent = _templateContent); "When rendering the template" .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderTemplateAsync(templateContent, model))); "Then the render should succeed" .x(() => e.Should().BeNull()); "And the rendered content should have expected values from the model" .x(() => { renderedContent.Should().NotBeNull().And.ContainAny("test template for environment: dev").And.NotContainAny("{{").And.NotContainAny("}}"); }); }
public void RenderTemplateAsyncWithModelNullError(ISnippetRenderer renderer, AzureIntegrationServicesModel model, ProcessManager processManager, TargetResourceTemplate resourceTemplate, TargetResourceSnippet resourceSnippet, WorkflowObject workflowObject, string snippetContent, string renderedContent, Exception e) { "Given a snippet renderer" .x(() => renderer = new LiquidSnippetRenderer(_mockLogger.Object)); "And a null model" .x(() => model.Should().BeNull()); "And a process manager" .x(() => { var messagingObject = _model.FindMessagingObject("ContosoMessageBus:AppA:FtpTransformWorkflow"); messagingObject.messagingObject.Should().NotBeNull().And.BeOfType(typeof(ProcessManager)); processManager = (ProcessManager)messagingObject.messagingObject; resourceTemplate = processManager.Resources.First(); resourceSnippet = processManager.Snippets.First(); }); "And a workflow object" .x(() => { workflowObject = processManager.WorkflowModel.Activities.First(); }); "And a snippet content" .x(() => snippetContent = _snippetContent); "When rendering the template" .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderSnippetAsync(snippetContent, model, processManager, resourceTemplate, resourceSnippet, workflowObject))); "Then the render should error" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("model")); "And the rendered content should not have a value" .x(() => renderedContent.Should().BeNull()); }
public void Setup() { "Given a new mock logger" .x(() => { _mockLogger = new Mock <ILogger>(); _mockLogger.Setup(l => l.IsEnabled(It.IsAny <LogLevel>())).Returns(true); }); "Given a model" .x(() => _model = TestHelper.GetModel()); "Given a new cancellation token source" .x(() => _source = new CancellationTokenSource()); "Given scenario config paths" .x(() => { var dirInfo = new DirectoryInfo(OkMultiConfigPath); Directory.Exists(dirInfo.FullName).Should().BeTrue(OkMultiConfigPath + " should exist"); }); "Given temp output path for rendered templates" .x(() => { _tempOutputTemplatePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(_tempOutputTemplatePath); }) .Teardown(() => { if (Directory.Exists(_tempOutputTemplatePath)) { Directory.Delete(_tempOutputTemplatePath, true); } }); }
public void ConstructWithSuccess(IBizTalkParser parser, ILogger logger, IApplicationModel model, MigrationContext context, Exception e) { "Given a parser" .x(() => parser.Should().BeNull()); "And a logger" .x(() => logger = _mockLogger.Object); "And a model" .x(() => model = new AzureIntegrationServicesModel()); "And a context" .x(() => context = new MigrationContext()); "When constructing" .x(() => e = Record.Exception(() => parser = new DistributionListParser(model, context, logger))); "Then the parser constructor should succeed" .x(() => { e.Should().BeNull(); parser.Should().NotBeNull(); }); }
public void ReportHtmlGenerationHappyPath(HtmlReportFormatter reporter, AzureIntegrationServicesModel model, MigrationContext context, IRunState state, IReportWriter writer, ILogger logger, Exception e) { "Given a model" .x(() => model = TestHelper.BuildModel()); "And run state" .x(() => state = TestHelper.BuildRunState(model)); "And a context" .x(() => context = TestHelper.BuildContext()); "And a writer" .x(() => writer = _mockWriter.Object); "And a logger" .x(() => logger = _mockLogger.Object); "And an reporter" .x(() => reporter = new HtmlReportFormatter(model, context, state, writer, logger)); "When executing the report formatter" .x(() => e = Record.Exception(() => reporter.Report())); "Then there should be no exception" .x(() => e.Should().BeNull()); "The report node should have a source application" .x(() => { _mockWriter.Invocations.Count.Should().Be(5); _mockWriter.Invocations[0].Arguments.Count.Should().Be(2); _mockWriter.Invocations[0].Arguments[0].Should().Be(context.ReportFilePath); _mockWriter.Invocations[0].Arguments[1].Should().NotBeNull(); _mockWriter.Invocations[0].Arguments[1].Should().NotBeEquivalentTo(string.Empty); }); }
public void GenerateWithNoApplications(AP006ReceiveRoutingPropertyGenerator generator, IFileRepository fileRepository, IScenarioRouteWalker routeWalker, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e) { "Given an generator" .x(() => generator.Should().BeNull()); "And a file repository" .x(() => fileRepository = _mockFileRepository.Object); "And a model" .x(() => { model = new AzureIntegrationServicesModel(); model.MigrationTarget.MessageBus = new MessageBus(); }); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And a route walker" .x(() => routeWalker = new Mock <IScenarioRouteWalker>().Object); "And a generator" .x(() => generator = new AP006ReceiveRoutingPropertyGenerator(fileRepository, routeWalker, model, context, logger)); "When converting" .x(async() => e = await Record.ExceptionAsync(async() => await generator.ConvertAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false)); "Then the code should not throw an exception" .x(() => e.Should().BeNull()); "And there should be no context errors" .x(() => context.Errors.Should().BeNullOrEmpty()); }
public void CreateMessageBusWithSuccess(MB001MessageBusAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e) { "Given an analyzer" .x(() => analyzer.Should().BeNull()); "And a model" .x(() => model = new AzureIntegrationServicesModel()); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And an analyzer" .x(() => analyzer = new MB001MessageBusAnalyzer(model, context, logger)); "When analyzing" .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false)); "Then there should be no exception" .x(() => e.Should().BeNull()); "And the message bus will have been created" .x(() => { model.Should().NotBeNull(); model.MigrationTarget.Should().NotBeNull(); model.MigrationTarget.MessageBus.Should().NotBeNull(); model.MigrationTarget.MessageBus.Key.Should().Be("MessageBus"); model.MigrationTarget.MessageBus.ResourceMapKey.Should().Be("messageBus"); model.MigrationTarget.MessageBus.Description.Should().NotBeNullOrEmpty(); model.MigrationTarget.MessageBus.Name.Should().NotBeNullOrEmpty(); model.MigrationTarget.MessageBus.Rating.Should().Be(ApplicationModel.Report.ConversionRating.FullConversion); }); }
public void RenderSnippetAsyncWithMissingMessagingObjectWithWarning(ISnippetRenderer renderer, AzureIntegrationServicesModel model, ProcessManager processManager, ProcessManager missingProcessManager, TargetResourceTemplate resourceTemplate, TargetResourceSnippet resourceSnippet, WorkflowObject workflowObject, string snippetContent, string renderedContent, Exception e) { "Given a snippet renderer" .x(() => renderer = new LiquidSnippetRenderer(_mockLogger.Object)); "And a model" .x(() => model = _model); "And a missing process manager" .x(() => { missingProcessManager = new ProcessManager("MissingProcessManager") { Key = "MissingProcessManager" }; }); "And a workflow object" .x(() => { var messagingObject = model.FindMessagingObject("ContosoMessageBus:AppA:FtpTransformWorkflow"); messagingObject.messagingObject.Should().NotBeNull().And.BeOfType(typeof(ProcessManager)); processManager = (ProcessManager)messagingObject.messagingObject; resourceTemplate = processManager.Resources.First(); resourceSnippet = processManager.Snippets.First(); workflowObject = processManager.WorkflowModel.Activities.First(); }); "And a snippet content" .x(() => snippetContent = _missingProcessManagerSnippet); "When rendering the snippet" .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderSnippetAsync(snippetContent, model, missingProcessManager, resourceTemplate, resourceSnippet, workflowObject))); "Then the render should succeed" .x(() => e.Should().BeNull()); "And the rendered content should not have expected values from the model" .x(() => { renderedContent.Should().NotBeNull().And.Be("").And.NotContainAny("{{").And.NotContainAny("}}"); // Verify warning was raised _mockLogger.Verify(l => l.Log( It.Is <LogLevel>(l => l == LogLevel.Warning), It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => v.ToString().Contains("does not appear in the target model", StringComparison.CurrentCultureIgnoreCase)), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once); }); }
/// <summary> /// Implements the internal logic of the parser. /// </summary> /// <param name="model">The model.</param> /// <param name="context">The migration context.</param> protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context) { // Get the applications from the source model. var parsedApplications = model.GetSourceModel <ParsedBizTalkApplicationGroup>()?.Applications; if (parsedApplications == null) { _logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(DocumentSchemaParser)); } else { _logger.LogDebug(TraceMessages.RunningParser, nameof(DocumentSchemaParser)); // Iterate through the applications and then through the parsed schemas. foreach (var application in parsedApplications) { var applicationResource = model.FindResourceByKey(application.Application?.ApplicationDefinition?.ResourceKey); foreach (var schema in application.Application.Schemas.Where(s => s.SchemaType == BizTalkSchemaType.Document)) { _logger.LogDebug(TraceMessages.ParsingBizTalkDocumentSchema, schema.Name); // Find resource definition var resourceDefinition = model.FindResourceDefinitionByKey(schema.ResourceDefinitionKey, ModelConstants.ResourceDefinitionSchema); if (resourceDefinition != null) { var schemaResource = new ResourceItem() { Name = schema.Name, Description = schema.XmlNamespace, Type = ModelConstants.ResourceDocumentSchema, Key = schema.ResourceKey, ParentRefId = resourceDefinition.RefId, Rating = ConversionRating.NotSupported }; schema.Resource = schemaResource; // Maintain pointer to the resource. schemaResource.SourceObject = schema; // Maintain backward pointer. schemaResource.Properties.Add(ResourceItemProperties.XmlNamespaceProperty, schema.XmlNamespace); schemaResource.Properties.Add(ResourceItemProperties.DotnetTypeNameProperty, schema.FullName); schemaResource.Properties.Add(ResourceItemProperties.NumberOfRootNodesProperty, schema.MessageDefinitions.Count.ToString(CultureInfo.CurrentCulture)); schemaResource.Properties.Add(ResourceItemProperties.IsEnvelopeProperty, schema.IsEnvelope.ToString()); if (schema.IsEnvelope) { schemaResource.Properties.Add(ResourceItemProperties.BodyXPathProperty, schema.BodyXPath); } // Add the message definitions. foreach (var messageDefinition in schema.MessageDefinitions) { _logger.LogDebug(TraceMessages.ParsingMessageTypeDefinition, messageDefinition.MessageType); var messageDefResource = new ResourceItem() { Name = messageDefinition.RootElementName, Description = messageDefinition.MessageType, Type = ModelConstants.ResourceMessageType, Key = messageDefinition.ResourceKey, ParentRefId = schemaResource.RefId, Rating = ConversionRating.NotSupported }; messageDefinition.Resource = messageDefResource; // Maintain pointer to the resource. messageDefResource.SourceObject = messageDefinition; // Maintain backward pointer. messageDefResource.Properties.Add(ResourceItemProperties.RootNodeNameProperty, messageDefinition.RootElementName); messageDefResource.Properties.Add(ResourceItemProperties.XmlNamespaceProperty, messageDefinition.XmlNamespace); schemaResource.Resources.Add(messageDefResource); } resourceDefinition.Resources.Add(schemaResource); if (applicationResource != null) { applicationResource.AddRelationship(new ResourceRelationship(schemaResource.RefId, ResourceRelationshipType.Child)); schemaResource.AddRelationship(new ResourceRelationship(applicationResource.RefId, ResourceRelationshipType.Parent)); } else { var error = string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceDefinition, ModelConstants.ResourceApplication, application.Application?.ApplicationDefinition?.ResourceKey); _logger.LogError(error); context.Errors.Add(new ErrorMessage(error)); } } else { _logger.LogError(ErrorMessages.UnableToFindResourceDefinition, ModelConstants.ResourceDefinitionSchema, schema.ResourceDefinitionKey); context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceDefinition, ModelConstants.ResourceDefinitionSchema, schema.ResourceDefinitionKey))); } } } _logger.LogDebug(TraceMessages.CompletedParser, nameof(DocumentSchemaParser)); } }
public void DP002ResolveSchemaDependenciesWithNoTransformResourceDefinitionWithErrors(DP002TransformDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e) { var invalidKey = "invalidkey"; "Given a source model" .x(() => model = TestHelper.CreateDefaultModelForAnalyzing()); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And an analyzer" .x(() => analyzer = new DP002TransformDependencyAnalyzer(model, context, logger)); "And transform resource definition has incorrect key" .x(() => { var transform = model.GetSourceModel <ParsedBizTalkApplicationGroup>().Applications[0].Application.Transforms[0]; transform.Resource = null; transform.ResourceKey = invalidKey; }); "When analyzing" .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false)); "Then there should be no exception" .x(() => e.Should().BeNull()); "And there should be an error in the migration context" .x(() => context.Errors.Should().HaveCount(1)); "And report node should not have the expected relationships created" .x(() => { context.Errors.Should().HaveCount(1); context.Errors[0].Message.Should().Contain(invalidKey); }); }
public void DP002ResolveSchemaDependenciesWithNoSchemaResourcesWithErrors(DP002TransformDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e) { var invalidKey = "invalidkey"; "Given a source model" .x(() => { model = TestHelper.CreateDefaultModelForAnalyzing(); // Corrupt the keys for the schemas. var parsedApplicationGroup = model.GetSourceModel <ParsedBizTalkApplicationGroup>(); var schemas = parsedApplicationGroup.Applications.Where(a => a.Application.Schemas != null).SelectMany(a => a.Application.Schemas); foreach (var schema in schemas) { schema.ResourceKey = string.Concat(invalidKey, Guid.NewGuid()); schema.Resource = null; } }); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And an analyzer" .x(() => analyzer = new DP002TransformDependencyAnalyzer(model, context, logger)); "When analyzing" .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false)); "Then there should be no exception" .x(() => e.Should().BeNull()); "And there should be 2 context errors" .x(() => { context.Errors.Should().HaveCount(4); context.Errors[0].Message.Should().Contain(invalidKey); context.Errors[1].Message.Should().Contain(invalidKey); context.Errors[2].Message.Should().Contain(invalidKey); context.Errors[3].Message.Should().Contain(invalidKey); }); }
public void DP002ResolveSchemaDependenciesWithWarnings(DP002TransformDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e) { "Given a source model" .x(() => { model = TestHelper.CreateDefaultModelForAnalyzing(); foreach (var application in model.GetSourceModel <ParsedBizTalkApplicationGroup>().Applications) { application.Application.Schemas.Clear(); } }); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And an analyzer" .x(() => analyzer = new DP002TransformDependencyAnalyzer(model, context, logger)); "When analyzing" .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false)); "Then there should be no exception" .x(() => e.Should().BeNull()); "And there should be no context errors" .x(() => context.Errors.Should().HaveCount(0)); "And report resource node should have warnings" .x(() => { // Get the maps var group = model.GetSourceModel <ParsedBizTalkApplicationGroup>(); var map1 = group.Applications[0].Application.Transforms[0]; map1.Should().NotBeNull(); map1.Name.Should().Be("Transform1"); map1.Resource.ReportMessages.Should().HaveCount(2); map1.Resource.ResourceRelationships.Should().HaveCount(2); var map2 = group.Applications[0].Application.Transforms[1]; map2.Should().NotBeNull(); map2.Name.Should().Be("Transform2"); map2.Resource.ReportMessages.Should().HaveCount(2); map2.Resource.ResourceRelationships.Should().HaveCount(2); }); }
public void DP002ResolveSchemaAndNoPortDependenciesWithSuccess(DP002TransformDependencyAnalyzer analyzer, ILogger logger, AzureIntegrationServicesModel model, MigrationContext context, Exception e) { "Given a source model" .x(() => { model = TestHelper.CreateDefaultModelForAnalyzing(); foreach (var application in model.GetSourceModel <ParsedBizTalkApplicationGroup>().Applications) { if (application.Application.Bindings.BindingInfo.ReceivePortCollection != null) { foreach (var receivePort in application.Application.Bindings.BindingInfo.ReceivePortCollection) { receivePort.Transforms = null; receivePort.OutboundTransforms = null; } } if (application.Application.Bindings.BindingInfo.SendPortCollection != null) { foreach (var sendPort in application.Application.Bindings.BindingInfo.SendPortCollection) { sendPort.Transforms = null; sendPort.InboundTransforms = null; } } } }); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And an analyzer" .x(() => analyzer = new DP002TransformDependencyAnalyzer(model, context, logger)); "When analyzing" .x(async() => e = await Record.ExceptionAsync(async() => await analyzer.AnalyzeAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false)); "Then there should be no exception" .x(() => e.Should().BeNull()); "And there should be no context errors" .x(() => context.Errors.Should().HaveCount(0)); "And report resource node should have the expected relationships created" .x(() => { // Get the map var group = model.GetSourceModel <ParsedBizTalkApplicationGroup>(); var map = group.Applications[0].Application.Transforms[0]; // Test the relationships var schemas = group.Applications[0].Application.Schemas.Where(s => s.SchemaType == BizTalkSchemaType.Document).ToList(); schemas.Should().NotBeNull(); schemas.Should().HaveCountGreaterOrEqualTo(2); map.Resource.ResourceRelationships[0].ResourceRelationshipType.Should().Be(ResourceRelationshipType.ReferencedBy); map.Resource.ResourceRelationships[0].ResourceRefId.Should().Be(schemas[0].Resource.RefId); map.Resource.ResourceRelationships[1].ResourceRelationshipType.Should().Be(ResourceRelationshipType.ReferencesTo); map.Resource.ResourceRelationships[1].ResourceRefId.Should().Be(schemas[1].Resource.RefId); }); }