public void ConstructWithSuccess(AP001ReceiveRoutingSlipGenerator generator, IScenarioRouteWalker routeWalker, 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); "And a route walker" .x(() => routeWalker = new ScenarioRouteWalker(context, logger)); "When constructing" .x(() => e = Record.Exception(() => new AP001ReceiveRoutingSlipGenerator(fileRepository, routeWalker, model, context, logger))); "Then the constructor should NOT throw an exception" .x(() => e.Should().BeNull()); }
/// <summary> /// Creates a new instance of a <see cref="AP003ReceiveConfigurationEntryGenerator"/> class. /// </summary> /// <param name="fileRepository">The file repository.</param> /// <param name="routeWalker">The scenario route walker.</param> /// <param name="model">The model.</param> /// <param name="context">The context.</param> /// <param name="logger">A logger.</param> public AP003ReceiveConfigurationEntryGenerator(IFileRepository fileRepository, IScenarioRouteWalker routeWalker, IApplicationModel model, MigrationContext context, ILogger logger) : base(nameof(AP003ReceiveConfigurationEntryGenerator), model, context, logger) { // Validate and set the member. _fileRepository = fileRepository ?? throw new ArgumentNullException(nameof(fileRepository)); _routeWalker = routeWalker ?? throw new ArgumentNullException(nameof(routeWalker)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public void ConstructWithNullFileRepository(AP003ReceiveConfigurationEntryGenerator generator, IFileRepository fileRepository, IScenarioRouteWalker routeWalker, 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); "And a route walker" .x(() => routeWalker = new ScenarioRouteWalker(TestHelper.BuildContext(), _mockLogger.Object)); "When constructing with a null file repository" .x(() => e = Record.Exception(() => new AP003ReceiveConfigurationEntryGenerator(fileRepository, routeWalker, 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 GenerateFailsWhenMissingConfig(AP006ReceiveRoutingPropertyGenerator generator, IFileRepository fileRepository, IScenarioRouteWalker routeWalker, ILogger logger, AzureIntegrationServicesModel model, Application application, MigrationContext context, Exception e) { var generatedFileName = string.Empty; JToken generatedJson = null; var resourcemapkey = "resourcemapkey"; var scenarioName = "scenarioName"; var activatingEndpointName = "activatingEndpointName "; var routingProperties = new List <(string PropertyName, string PropertyValue)> { ("propertyOneName", "propertyOneValue"), ("propertyTwoName", "propertyTwoValue") }; "Given an generator" .x(() => generator.Should().BeNull()); "And a file repository" .x(() => { _mockFileRepository.Setup(f => f.WriteJsonFile( It.IsAny <string>(), It.IsAny <JToken>() )) .Callback <string, JToken>( (p1, p2) => { generatedFileName = p1; generatedJson = p2; }); fileRepository = _mockFileRepository.Object; }); "And an application" .x(() => { var activatingEndpoint = new AdapterEndpoint { Activator = true, ResourceMapKey = resourcemapkey, Name = activatingEndpointName }; var routingProperties1 = new Dictionary <string, object>(); var activatingEndpointRoutingProperties = routingProperties[0]; routingProperties1[activatingEndpointRoutingProperties.PropertyName] = activatingEndpointRoutingProperties.PropertyValue; activatingEndpoint.Properties[ModelConstants.ScenarioName] = scenarioName; activatingEndpoint.Properties[ModelConstants.RoutingProperties] = routingProperties1; activatingEndpoint.Resources.Add( new TargetResourceTemplate { ResourceType = "WrongResourceType", OutputPath = "outputpath" }); var firstIntermediary = new GenericFilter { Name = "firstIntermediaryName" }; var secondIntermediary = new GenericFilter { Name = "secondIntermediaryName" }; var routingProperties2 = new Dictionary <string, object>(); var secondIntermediaryRoutingProperties = routingProperties[1]; routingProperties2[secondIntermediaryRoutingProperties.PropertyName] = secondIntermediaryRoutingProperties.PropertyValue; secondIntermediary.Properties[ModelConstants.RoutingProperties] = routingProperties2; application = new Application(); application.Endpoints.Add(activatingEndpoint); application.Intermediaries.Add(firstIntermediary); application.Intermediaries.Add(secondIntermediary); }); "And a model" .x(() => { model = new AzureIntegrationServicesModel(); model.MigrationTarget.MessageBus = new MessageBus(); model.MigrationTarget.MessageBus.Applications.Add(application); }); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And a route walker" .x(() => { var route = new List <(MessagingObject RoutingObject, Channel InputChannel)>(); foreach (var intermediary in application.Intermediaries) { route.Add((intermediary, null)); } foreach (var endpoint in application.Endpoints) { route.Add((endpoint, null)); } var mockRouteWalker = new Mock <IScenarioRouteWalker>(); mockRouteWalker.Setup(w => w.WalkReceiveRoute( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Endpoint>(), It.IsAny <IEnumerable <Intermediary> >(), It.IsAny <IEnumerable <Channel> >() )).Returns(route); routeWalker = mockRouteWalker.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 one context error" .x(() => { context.Errors.Should().NotBeNullOrEmpty(); context.Errors.Should().HaveCount(1); context.Errors[0].Message.Should().Contain(ModelConstants.ResourceTypeRoutingProperties); context.Errors[0].Message.Should().Contain(activatingEndpointName); }); }
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 GenerateWithSuccess(AP005SendRoutingPropertyGenerator generator, IFileRepository fileRepository, IScenarioRouteWalker routeWalker, ILogger logger, AzureIntegrationServicesModel model, Application application, MigrationContext context, Exception e) { var generatedFileName = string.Empty; JObject generatedJson = null; var resourcemapkey = "resourcemapkey"; var scenarioName = "scenarioName"; var routingProperties = new List <(string PropertyName, string PropertyValue)> { ("propertyOneName", "propertyOneValue"), ("propertyTwoName", "propertyTwoValue") }; "Given an generator" .x(() => generator.Should().BeNull()); "And a file repository" .x(() => { _mockFileRepository.Setup(f => f.WriteJsonFile( It.IsAny <string>(), It.IsAny <JObject>() )) .Callback <string, JObject>( (p1, p2) => { generatedFileName = p1; generatedJson = p2; }); fileRepository = _mockFileRepository.Object; }); "And an application" .x(() => { var activatingIntermediary = new MessageSubscriber { Activator = true, ResourceMapKey = resourcemapkey, Name = "ActivatingIntermediary" }; var routingProperties1 = new Dictionary <string, object>(); var intermediaryRoutingProperties = routingProperties[0]; routingProperties1[intermediaryRoutingProperties.PropertyName] = intermediaryRoutingProperties.PropertyValue; activatingIntermediary.Properties[ModelConstants.ScenarioName] = scenarioName; activatingIntermediary.Properties[ModelConstants.RoutingProperties] = routingProperties1; activatingIntermediary.Resources.Add( new TargetResourceTemplate { ResourceType = ModelConstants.ResourceTypeRoutingProperties, OutputPath = "outputpath" }); var secondIntermediary = new GenericFilter { Name = "SecondIntermediary" }; var endpoint = new AdapterEndpoint { Name = "Endpoint" }; var routingProperties2 = new Dictionary <string, object>(); var endpointRoutingProperties = routingProperties[1]; routingProperties2[endpointRoutingProperties.PropertyName] = endpointRoutingProperties.PropertyValue; endpoint.Properties[ModelConstants.RoutingProperties] = routingProperties2; application = new Application(); application.Intermediaries.Add(activatingIntermediary); application.Intermediaries.Add(secondIntermediary); application.Endpoints.Add(endpoint); }); "And a model" .x(() => { model = new AzureIntegrationServicesModel(); model.MigrationTarget.MessageBus = new MessageBus(); model.MigrationTarget.MessageBus.Applications.Add(application); }); "And a context" .x(() => context = TestHelper.BuildContext()); "And a logger" .x(() => logger = _mockLogger.Object); "And a route walker" .x(() => { var route = new List <(MessagingObject RoutingObject, Channel InputChannel)>(); foreach (var intermediary in application.Intermediaries) { route.Add((intermediary, null)); } foreach (var endpoint in application.Endpoints) { route.Add((endpoint, null)); } var mockRouteWalker = new Mock <IScenarioRouteWalker>(); mockRouteWalker.Setup(w => w.WalkSendRoute( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Intermediary>(), It.IsAny <IEnumerable <Intermediary> >(), It.IsAny <IEnumerable <Channel> >(), It.IsAny <IEnumerable <Endpoint> >() )).Returns(route); routeWalker = mockRouteWalker.Object; }); "And a generator" .x(() => generator = new AP005SendRoutingPropertyGenerator(fileRepository, routeWalker, model, context, logger)); "When converting" .x(async() => e = await Record.ExceptionAsync(async() => await generator.ConvertAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false)); "Then the code should not throw an exception" .x(() => e.Should().BeNull()); "And there should be no context errors" .x(() => context.Errors.Should().BeNullOrEmpty()); "And the file should be generated" .x(() => { _mockFileRepository.Verify(f => f.WriteJsonFile( It.IsAny <string>(), It.IsAny <JObject>()), Times.Once); generatedJson.Should().NotBeNull(); generatedJson["routingProperties"].Should().NotBeNull(); generatedJson["routingProperties"][0].Should().NotBeNull(); generatedJson["routingProperties"][0]["propertyName"].Should().NotBeNull(); var propertyOneName = (string)generatedJson.SelectToken("routingProperties[0].propertyName"); propertyOneName.Should().NotBeNullOrWhiteSpace(); propertyOneName.Should().Be(routingProperties[0].PropertyName); var propertyOneValue = (string)generatedJson.SelectToken("routingProperties[0].propertyValue"); propertyOneValue.Should().NotBeNullOrWhiteSpace(); propertyOneValue.Should().Be(routingProperties[0].PropertyValue); var propertyOneType = (string)generatedJson.SelectToken("routingProperties[0].propertyType"); propertyOneType.Should().NotBeNullOrWhiteSpace(); propertyOneType.Should().Be("property"); generatedJson["routingProperties"][1].Should().NotBeNull(); generatedJson["routingProperties"][1]["propertyName"].Should().NotBeNull(); var propertyTwoName = (string)generatedJson.SelectToken("routingProperties[1].propertyName"); propertyTwoName.Should().NotBeNullOrWhiteSpace(); propertyTwoName.Should().Be(routingProperties[1].PropertyName); var propertyTwoValue = (string)generatedJson.SelectToken("routingProperties[1].propertyValue"); propertyTwoValue.Should().NotBeNullOrWhiteSpace(); propertyTwoValue.Should().Be(routingProperties[1].PropertyValue); var propertyTwoType = (string)generatedJson.SelectToken("routingProperties[1].propertyType"); propertyTwoType.Should().NotBeNullOrWhiteSpace(); propertyTwoType.Should().Be("property"); }); }