public void ConstructWithNullFileRepository(AP006ReceiveRoutingPropertyGenerator 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 AP006ReceiveRoutingPropertyGenerator(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 ConstructWithSuccess(AP006ReceiveRoutingPropertyGenerator 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 AP006ReceiveRoutingPropertyGenerator(fileRepository, routeWalker, model, context, logger)));

            "Then the constructor should NOT throw an exception"
            .x(() => e.Should().BeNull());
        }
        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 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);
            });
        }