예제 #1
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));
        }
예제 #2
0
        public void WhenSubClassReturnsNullProcessorThenThrows()
        {
            var dataSource = Any.DataSource();

            var sut = new StubDataSource
            {
                ProcessorToReturn = null,
            };

            sut.SetApplicationEnvironment(applicationEnvironment);

            Assert.ThrowsException <InvalidOperationException>(
                () => sut.CreateProcessor(dataSource, Any.ProcessorEnvironment(), ProcessorOptions.Default));
        }
예제 #3
0
        public void CreateProcessorWithManyDataSourcesCallsSubClass()
        {
            var dataSource  = Any.DataSource();
            var dataSources = new[] { dataSource, };
            var env         = Any.ProcessorEnvironment();
            var options     = ProcessorOptions.Default;

            var sut = new StubDataSource();

            sut.SetApplicationEnvironment(applicationEnvironment);
            var result = sut.CreateProcessor(dataSources, env, options);

            Assert.AreEqual(1, sut.CreateProcessorCoreCalls.Count);
            Assert.AreEqual(dataSources, sut.CreateProcessorCoreCalls[0].Item1);
            Assert.AreEqual(env, sut.CreateProcessorCoreCalls[0].Item2);
            Assert.AreEqual(options, sut.CreateProcessorCoreCalls[0].Item3);
        }
예제 #4
0
        public void NoTablesInAssemblyLeavesEmptyProperties()
        {
            var assembly = new FakeAssembly
            {
                TypesToReturn = new[]
                {
                    typeof(DateTime),
                }
            };

            StubDataSource.Assembly = assembly;

            var sut = new StubDataSource();

            sut.SetApplicationEnvironment(applicationEnvironment);

            Assert.IsFalse(sut.DataTables.Any());
            Assert.IsFalse(sut.MetadataTables.Any());
        }
예제 #5
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);
        }
예제 #6
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);
        }