public void TryCreateTypeFromNonConcreteTypeFails()
        {
            var result = TableDescriptorFactory.TryCreate(typeof(AbstractType), serializer, out TableDescriptor descriptor);

            Assert.IsFalse(result);
            Assert.IsNull(descriptor);
        }
        public void TryCreateFromTypeWithoutTableAttributeFails()
        {
            var result = TableDescriptorFactory.TryCreate(typeof(DateTime), serializer, out TableDescriptor descriptor);

            Assert.IsFalse(result);
            Assert.IsNull(descriptor);
        }
        public void TryCreateFromNullFails()
        {
            var result = TableDescriptorFactory.TryCreate(null, serializer, out TableDescriptor descriptor);

            Assert.IsFalse(result);
            Assert.IsNull(descriptor);
        }
コード例 #4
0
        public void BothTableTypesInInAssemblyPopulatesCorrectly()
        {
            var assembly = new FakeAssembly
            {
                TypesToReturn = new[]
                {
                    typeof(DateTime),
                    typeof(StubDataTableOne),
                    typeof(StubDataTableTwo),
                    typeof(StubDataTableThree),
                    typeof(StubMetadataTableOne),
                    typeof(StubMetadataTableTwo),
                    typeof(Exception),
                }
            };

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor1));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor2));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableThree),
                    serializer,
                    out TableDescriptor expectedDescriptor3));

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor4));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor5));

            StubDataSource.Assembly = assembly;

            var sut = new StubDataSource();

            sut.SetApplicationEnvironment(applicationEnvironment);

            Assert.AreEqual(3, sut.DataTables.Count());
            Assert.IsTrue(sut.DataTables.Contains(expectedDescriptor1));
            Assert.IsTrue(sut.DataTables.Contains(expectedDescriptor2));
            Assert.IsTrue(sut.DataTables.Contains(expectedDescriptor3));

            Assert.AreEqual(2, sut.MetadataTables.Count());
            Assert.IsTrue(sut.MetadataTables.Contains(expectedDescriptor4));
            Assert.IsTrue(sut.MetadataTables.Contains(expectedDescriptor5));
        }
        public void TryCreateFromSubtypeOfTableAttributeCreates()
        {
            var result = TableDescriptorFactory.TryCreate
                             (typeof(TableWithSubAttribute),
                             serializer,
                             out TableDescriptor descriptor);

            Assert.IsTrue(result);
            Assert.IsNotNull(descriptor);

            AssertAttributeTranslated(TableWithSubAttribute.Descriptor, descriptor);
        }
        public void TryCreateFromTypeWithPrebuiltTableConfig()
        {
            var result = TableDescriptorFactory.TryCreate
                             (typeof(TableWithPrebuiltConfiguration),
                             serializer,
                             out TableDescriptor descriptor);

            Assert.IsTrue(result);
            Assert.IsNotNull(descriptor);

            Assert.IsNotNull(descriptor.PrebuiltTableConfigurations);
        }
        public void TryCreateFromTypeWithAttributeAndInterfaceCreates()
        {
            var result = TableDescriptorFactory.TryCreate
                             (typeof(TableWithNoColumns),
                             serializer,
                             out TableDescriptor descriptor);

            Assert.IsTrue(result);
            Assert.IsNotNull(descriptor);

            AssertAttributeTranslated(TableWithNoColumns.TableDescriptor, descriptor);
        }
コード例 #8
0
        internal static bool TryCreateReference(
            Type candidateType,
            bool allowInternalTables,
            out ITableExtensionReference reference)
        {
            Guard.NotNull(candidateType, nameof(candidateType));

            reference = null;

            if (TableDescriptorFactory.TryCreate(
                    candidateType,
                    tableConfigSerializer,
                    out var isInternalTable,
                    out var tableDescriptor,
                    out var tableBuildAction,
                    out var tableIsDataAvailableFunc))
            {
                if (isInternalTable)
                {
                    if (!allowInternalTables)
                    {
                        return(false);
                    }

                    Debug.Assert(tableBuildAction != null);
                }

                var tableReference = new TableExtensionReference(
                    candidateType,
                    tableDescriptor,
                    tableBuildAction,
                    tableIsDataAvailableFunc);

                tableReference.IsInternalTable = isInternalTable;

                reference = tableReference;
            }

            return(reference != null);
        }
コード例 #9
0
        public void WhenAdditionalTableProviderProvidedThenAdditionalTablesAdded()
        {
            var assembly = new FakeAssembly
            {
                TypesToReturn = new[]
                {
                    typeof(DateTime),
                    typeof(StubDataTableOne),
                    typeof(StubMetadataTableOne),
                    typeof(Exception),
                }
            };

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor1));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor2));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableThree),
                    serializer,
                    out TableDescriptor expectedDescriptor3));

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor4));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor5));

            StubDataSource.Assembly = assembly;

            bool descriptor2BuildWasCalled = false;
            bool descriptor3BuildWasCalled = false;
            bool descriptor5BuildWasCalled = false;

            var additionalTables = new Dictionary <TableDescriptor, Action <ITableBuilder, IDataExtensionRetrieval> >
            {
                { expectedDescriptor2, (tableBuilder, cookedData) => { descriptor2BuildWasCalled = true; } },
                { expectedDescriptor3, (tableBuilder, cookedData) => { descriptor3BuildWasCalled = true; } },
                { expectedDescriptor5, (tableBuilder, cookedData) => { descriptor5BuildWasCalled = true; } },
            };

            var sut = new StubDataSource(() => additionalTables);

            sut.SetApplicationEnvironment(applicationEnvironment);

            Assert.AreEqual(5, sut.AllTablesExposed.Count);

            // call the build action of each of our tables
            foreach (var kvp in sut.AllTablesExposed)
            {
                kvp.Value.Invoke(null, null);
            }

            Assert.IsTrue(StubDataTableOne.BuildTableWasCalled);
            Assert.IsTrue(descriptor2BuildWasCalled);
            Assert.IsTrue(descriptor3BuildWasCalled);
            Assert.IsTrue(StubMetadataTableOne.BuildTableWasCalled);
            Assert.IsTrue(descriptor5BuildWasCalled);
        }
コード例 #10
0
        public void AllTablesIsUnionOfDataAndMetadata()
        {
            var assembly = new FakeAssembly
            {
                TypesToReturn = new[]
                {
                    typeof(DateTime),
                    typeof(StubDataTableOne),
                    typeof(StubDataTableTwo),
                    typeof(StubDataTableThree),
                    typeof(StubMetadataTableOne),
                    typeof(StubMetadataTableTwo),
                    typeof(Exception),
                }
            };

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor1));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor2));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableThree),
                    serializer,
                    out TableDescriptor expectedDescriptor3));

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor4));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor5));

            StubDataSource.Assembly = assembly;

            var sut = new StubDataSource();

            sut.SetApplicationEnvironment(applicationEnvironment);

            Assert.AreEqual(5, sut.AllTablesExposed.Count);

            // call the build action of each of our tables
            foreach (var kvp in sut.AllTablesExposed)
            {
                kvp.Value.Invoke(null, null);
            }

            Assert.IsTrue(StubDataTableOne.BuildTableWasCalled);
            Assert.IsTrue(StubDataTableTwo.BuildTableWasCalled);
            Assert.IsTrue(StubDataTableThree.BuildTableWasCalled);
            Assert.IsTrue(StubMetadataTableOne.BuildTableWasCalled);
            Assert.IsTrue(StubMetadataTableTwo.BuildTableWasCalled);
        }