public void Setup()
        {
            // Copy config file into Plugins folder
            string configName    = "config.json";
            string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (directoryName == null)
            {
                Assert.Fail("Could not load config.json to execute tests");
            }

            if (!Directory.Exists(Path.Combine(directoryName, "Plugins")))
            {
                Directory.CreateDirectory(Path.Combine(directoryName, "Plugins"));
            }

            if (!Directory.Exists(Path.Combine(directoryName, "Plugins", "HierarchicalDataConverter")))
            {
                Directory.CreateDirectory(Path.Combine(directoryName, "Plugins", "HierarchicalDataConverter"));
            }

            string configFileLocation    = Path.Combine(directoryName, configName);
            string configFileNewLocation = Path.Combine(directoryName, "Plugins", "HierarchicalDataConverter", configName);

            File.Copy(configFileLocation, configFileNewLocation, true);

            var serviceClientMock = new Mock <IMetadataServiceClient>();
            var processingContextWrapperFactoryMock = new Mock <IProcessingContextWrapperFactory>();
            var loggingRepositoryMock = new Mock <ILoggingRepository>();
            var converter             = new HierarchicalDataTransformer(serviceClientMock.Object, processingContextWrapperFactoryMock.Object, loggingRepositoryMock.Object);

            this.privateMethodRunner = new PrivateObject(converter);
        }
        public void GrandparentParentChild()
        {
            Binding[] bindings = new Binding[]
            {
                this.GetNestedBindingLevel0Source(),
                this.GetNestedBindingLevel1Source(),
                this.GetNestedBindingLevel2Source()
            };
            Field[] entity0Fields = this.GetEntity0Fields();
            Field[] entity1Fields = this.GetEntity1Fields();
            Field[] entity2Fields = this.GetEntity2Fields();

            var serviceClientMock = new Mock <IMetadataServiceClient>();

            serviceClientMock.Setup(mock => mock.GetBindingsForDataMartAsync(It.IsAny <int>())).Returns(Task.FromResult(bindings));

            serviceClientMock.Setup(mock => mock.GetEntityFieldsAsync(It.Is <Entity>(entity => entity.Id == 0))).Returns(Task.FromResult(entity0Fields));
            serviceClientMock.Setup(mock => mock.GetEntityFieldsAsync(It.Is <Entity>(entity => entity.Id == 1))).Returns(Task.FromResult(entity1Fields));
            serviceClientMock.Setup(mock => mock.GetEntityFieldsAsync(It.Is <Entity>(entity => entity.Id == 2))).Returns(Task.FromResult(entity2Fields));

            serviceClientMock.Setup(mock => mock.GetEntityAsync(0)).Returns(Task.FromResult(this.GetLevel0SourceEntity()));
            serviceClientMock.Setup(mock => mock.GetEntityAsync(1)).Returns(Task.FromResult(this.GetLevel1SourceEntity()));
            serviceClientMock.Setup(mock => mock.GetEntityAsync(2)).Returns(Task.FromResult(this.GetLevel2SourceEntity()));

            var processingContextWrapperFactoryMock = new Mock <IProcessingContextWrapperFactory>();
            var processingContextWrapperMock        = new Mock <IProcessingContextWrapper>();

            processingContextWrapperFactoryMock.Setup(mock => mock.CreateProcessingContextWrapper()).Returns(processingContextWrapperMock.Object);
            processingContextWrapperMock.Setup(mock => mock.GetIncrementalValue(It.IsAny <IncrementalConfiguration>())).Returns(new IncrementalValue {
                LastMaxIncrementalDate = DateTime.Now
            });

            var loggingRepositoryMock = new Mock <ILoggingRepository>();

            var converter           = new HierarchicalDataTransformer(serviceClientMock.Object, processingContextWrapperFactoryMock.Object, loggingRepositoryMock.Object);
            var privateMethodRunner = new PrivateObject(converter);

            object[] args = new object[] { this.GetNestedBindingLevel0Source(), new BindingExecution(), this.GetNestedDestinationEntity() };

            var jobData = ((Task <JobData>)privateMethodRunner.Invoke("GetJobData", args)).Result;

            Assert.AreEqual(3, jobData.DataSources.Count());
            var firstSource = (TopLevelDataSource)jobData.TopLevelDataSource;

            Assert.AreEqual("[MyDatabaseName].[Level0TableName].[Level0Entity]", firstSource.TableOrView);
            Assert.AreEqual(2, firstSource.SqlEntityColumnMappings.Count());
            Assert.AreEqual("id0", firstSource.SqlEntityColumnMappings.First().Name);
            Assert.AreEqual("Level0FieldToBeAdded", firstSource.SqlEntityColumnMappings.Last().Name);
            Assert.AreEqual("$", firstSource.Path);

            var secondSource = (DataSource)jobData.DataSources.ElementAt(1);

            Assert.AreEqual("[MyDatabaseName].[Level1TableName].[Level1Entity]", secondSource.TableOrView);
            Assert.AreEqual(3, secondSource.SqlEntityColumnMappings.Count());
            Assert.AreEqual("id1", secondSource.SqlEntityColumnMappings.First().Name);
            Assert.AreEqual("id0", secondSource.SqlEntityColumnMappings.ElementAt(1).Name);
            Assert.AreEqual("Level1FieldToBeAdded", secondSource.SqlEntityColumnMappings.Last().Name);
            Assert.AreEqual("$.Level1Entity", secondSource.Path);

            var thirdSource = (DataSource)jobData.DataSources.ElementAt(2);

            Assert.AreEqual("[MyDatabaseName].[Level2TableName].[Level2Entity]", thirdSource.TableOrView);
            Assert.AreEqual(4, thirdSource.SqlEntityColumnMappings.Count());
            Assert.AreEqual("id2", thirdSource.SqlEntityColumnMappings.First().Name);
            Assert.AreEqual("id0", thirdSource.SqlEntityColumnMappings.ElementAt(1).Name);
            Assert.AreEqual("id1", thirdSource.SqlEntityColumnMappings.ElementAt(2).Name);
            Assert.AreEqual("Level2FieldToBeAdded", thirdSource.SqlEntityColumnMappings.Last().Name);
            Assert.AreEqual("$.Level1Entity.Level2Entity", thirdSource.Path);

            Assert.AreEqual(2, thirdSource.Relationships.Count());
            Assert.AreEqual("[MyDatabaseName].[Level2TableName].[Level2Entity]", thirdSource.Relationships.First().Destination.Entity);
            Assert.AreEqual("'id0'", thirdSource.Relationships.First().Destination.Key);
            Assert.AreEqual("[MyDatabaseName].[Level0TableName].[Level0Entity]", thirdSource.Relationships.First().Source.Entity);
            Assert.AreEqual("'id0'", thirdSource.Relationships.First().Source.Key);
            Assert.AreEqual("[MyDatabaseName].[Level2TableName].[Level2Entity]", thirdSource.Relationships.Last().Destination.Entity);
            Assert.AreEqual("'id1'", thirdSource.Relationships.Last().Destination.Key);
            Assert.AreEqual("[MyDatabaseName].[Level1TableName].[Level1Entity]", thirdSource.Relationships.Last().Source.Entity);
            Assert.AreEqual("'id1'", thirdSource.Relationships.Last().Source.Key);

            Assert.AreEqual(1, secondSource.Relationships.Count());
            Assert.AreEqual("[MyDatabaseName].[Level1TableName].[Level1Entity]", secondSource.Relationships.First().Destination.Entity);
            Assert.AreEqual("'id0'", secondSource.Relationships.First().Destination.Key);
            Assert.AreEqual("[MyDatabaseName].[Level0TableName].[Level0Entity]", secondSource.Relationships.First().Source.Entity);
            Assert.AreEqual("'id0'", secondSource.Relationships.First().Destination.Key);

            Assert.AreEqual(0, firstSource.Relationships.Count());
        }