Ejemplo n.º 1
0
        public void ConstructWithNullFileRepository(AP005SendRoutingPropertyGenerator 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 AP005SendRoutingPropertyGenerator(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"));
        }
Ejemplo n.º 2
0
        public void ConstructWithSuccess(AP005SendRoutingPropertyGenerator generator, IFileRepository fileRepository, IScenarioRouteWalker routeWalker, 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(TestHelper.BuildContext(), _mockLogger.Object));

            "When constructing"
            .x(() => e = Record.Exception(() => new AP005SendRoutingPropertyGenerator(fileRepository, routeWalker, model, context, logger)));

            "Then the constructor should NOT throw an exception"
            .x(() => e.Should().BeNull());
        }
Ejemplo n.º 3
0
        public void GenerateWithNoApplications(AP005SendRoutingPropertyGenerator 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 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());
        }
Ejemplo n.º 4
0
        public void GenerateFailsWhenMissingConfig(AP005SendRoutingPropertyGenerator generator, IFileRepository fileRepository, IScenarioRouteWalker routeWalker, ILogger logger, AzureIntegrationServicesModel model, Application application, MigrationContext context, Exception e)
        {
            var     generatedFileName          = string.Empty;
            JObject generatedJson              = null;
            var     resourcemapkey             = "resourcemapkey";
            var     scenarioName               = "scenarioName";
            var     activatingIntermediaryName = "activatingIntermediaryName";

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

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

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

                fileRepository = _mockFileRepository.Object;
            });

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                var mockRouteWalker = new Mock <IScenarioRouteWalker>();

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

                routeWalker = mockRouteWalker.Object;
            });

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

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

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

            "And there should be one context error"
            .x(() =>
            {
                context.Errors.Should().NotBeNullOrEmpty();
                context.Errors.Should().HaveCount(1);
                context.Errors[0].Message.Should().Contain(ModelConstants.ResourceTypeRoutingProperties);
                context.Errors[0].Message.Should().Contain(activatingIntermediaryName);
            });
        }