Example #1
0
        public void ConstructorTest2()
        {
            var table1 = new TestTableExtensionReference(false)
            {
                TableDescriptor = new TableDescriptor(
                    Guid.Parse("{ADE569AF-4460-4DCC-A7C8-9748737AE592}"),
                    "Table1",
                    "Table1 Description",
                    "General",
                    false,
                    TableLayoutStyle.GraphAndTable,
                    new[] { Source1Cooker1Path }),
                BuildTableAction = (tableBuilder, dataRetrieval) => {},
                availability     = DataExtensionAvailability.MissingRequirement,
            };

            var testRepo = new TestDataExtensionRepository();

            testRepo.tablesById.Add(table1.TableDescriptor.Guid, table1);

            var tableSelector = new TableExtensionSelector(testRepo);

            Assert.AreEqual(tableSelector.Tables.Count, 0);
            Assert.AreEqual(tableSelector.TableCategories.Count, 0);
        }
Example #2
0
        public void ConstructorTest3()
        {
            var table1 = new TestTableExtensionReference(false)
            {
                TableDescriptor = new TableDescriptor(
                    Guid.Parse("{ADE569AF-4460-4DCC-A7C8-9748737AE592}"),
                    "Table1",
                    "Table1 Description",
                    "General",
                    false,
                    TableLayoutStyle.GraphAndTable,
                    new[] { Source1Cooker1Path }),
                BuildTableAction = (tableBuilder, dataRetrieval) => { },
                availability     = DataExtensionAvailability.Available,
            };

            var table2 = new TestTableExtensionReference(false)
            {
                TableDescriptor = new TableDescriptor(
                    Guid.Parse("{42F33CCB-D1D4-48CD-BAF0-853A508C638D}"),
                    "Table2",
                    "Table1 Description",
                    "Specific",
                    false,
                    TableLayoutStyle.GraphAndTable,
                    new[] { Source1Cooker1Path }),
                BuildTableAction = (tableBuilder, dataRetrieval) => { },
                availability     = DataExtensionAvailability.Available,
            };

            var table3 = new TestTableExtensionReference(false)
            {
                TableDescriptor = new TableDescriptor(
                    Guid.Parse("{3A613426-6550-49AA-89F0-C6BBB6039EB4}"),
                    "Table3",
                    "Table1 Description",
                    "General",
                    false,
                    TableLayoutStyle.GraphAndTable,
                    new[] { Source1Cooker1Path }),
                BuildTableAction = (tableBuilder, dataRetrieval) => { },
                availability     = DataExtensionAvailability.Available,
            };

            var testRepo = new TestDataExtensionRepository();

            testRepo.tablesById.Add(table1.TableDescriptor.Guid, table1);
            testRepo.tablesById.Add(table2.TableDescriptor.Guid, table2);
            testRepo.tablesById.Add(table3.TableDescriptor.Guid, table3);

            var tableSelector = new TableExtensionSelector(testRepo);

            Assert.AreEqual(tableSelector.Tables.Count, 3);
            Assert.AreEqual(tableSelector.TableCategories.Count, 2);
            Assert.IsTrue(tableSelector.TableCategories.Contains(table2.TableDescriptor.Category));
            Assert.IsTrue(tableSelector.TableCategories.Contains(table1.TableDescriptor.Category));
        }
Example #3
0
        public void GetSourceDataCookersForTablesTest1()
        {
            var requiredDataCookers = new List <DataCookerPath>
            {
                Source1Cooker1Path,
            };

            var table1 = new TestTableExtensionReference
            {
                TableDescriptor = new TableDescriptor(
                    Guid.Parse("{ADE569AF-4460-4DCC-A7C8-9748737AE592}"),
                    "Table1",
                    "Table1 Description",
                    "General",
                    false,
                    TableLayoutStyle.GraphAndTable,
                    requiredDataCookers),
                BuildTableAction = (tableBuilder, dataRetrieval) => { },
            };

            var testRepo = new TestDataExtensionRepository();

            testRepo.tablesById.Add(table1.TableDescriptor.Guid, table1);

            AddRequiredDataExtensions(table1, testRepo);

            var tableSelector = new TableExtensionSelector(testRepo);

            Assert.AreEqual(tableSelector.Tables.Count, 1);

            var requiredSourceDataCookers = tableSelector.GetSourceDataCookersForTables(new [] { table1.TableDescriptor.Guid });

            Assert.AreEqual(requiredSourceDataCookers.Count, 1);

            var sourceId = requiredDataCookers[0].SourceParserId;

            Assert.IsTrue(requiredSourceDataCookers.ContainsKey(sourceId));
            Assert.AreEqual(requiredSourceDataCookers[sourceId].Count(), 1);
        }
        /// <summary>
        ///     This enables all required source data cookers for each specified table. Doing so will ensure that the
        ///     table has the required data to build.
        /// </summary>
        /// <param name="self">
        ///     The data extension repository.
        /// </param>
        /// <param name="processors">
        ///     The source processors that are available to generate data.
        /// </param>
        /// <param name="enabledTables">
        ///     Table references that the caller is interested in building.
        /// </param>
        /// <returns>
        ///     The set of custom data processors that have data cookers enabled in order to build the requested set
        ///     of tables.
        /// </returns>
        public static ISet <ICustomDataProcessorWithSourceParser> EnableSourceDataCookersForTables(
            this IDataExtensionRepository self,
            IEnumerable <ICustomDataProcessorWithSourceParser> processors,
            HashSet <ITableExtensionReference> enabledTables)
        {
            Guard.NotNull(self, nameof(self));
            Guard.NotNull(processors, nameof(processors));
            Guard.NotNull(enabledTables, nameof(enabledTables));

            var customProcessors = new HashSet <ICustomDataProcessorWithSourceParser>();

            var availableTableExtensions     = new TableExtensionSelector(self);
            var requiredReferencesBySourceId = availableTableExtensions.GetSourceDataCookersForTables(enabledTables);

            foreach (var processor in processors)
            {
                if (requiredReferencesBySourceId.TryGetValue(
                        processor.SourceParserId,
                        out var requiredCookerReferences))
                {
                    if (!requiredCookerReferences.Any())
                    {
                        continue;
                    }

                    customProcessors.Add(processor);

                    foreach (var cookerReference in requiredCookerReferences)
                    {
                        processor.EnableCooker(cookerReference);
                    }
                }
            }

            return(customProcessors);
        }