public void CacheWriterProduction_IsSuccessfullyReadByCacheReader_2()
        {
            var writer   = new StringWriter();
            var metadata = new Dictionary <string, object>();

            metadata["mykey"]    = "simple text";
            metadata["v"]        = 100;
            metadata["identity"] = typeof(DefinitionsCacheWriterTestCase);

            DefinitionsCacheWriter.write_manifest(writer,
                                                  new[] { new ExportDefinition("contractName", metadata) },
                                                  new ImportDefinition[0]);

            var cache = DefinitionsCacheReader.build_manifest(
                new StringReader(writer.GetStringBuilder().ToString()),
                "path",
                new StubBindingContext(typeof(DefinitionsCacheWriterTestCase)), BundleName);

            cache.Exports.Count().Should().Be(1);
            cache.Imports.Count().Should().Be(0);
            var def = cache.Exports.ElementAt(0);

            def.ContractName.Should().Be("contractName");
            var emetadata = def.Metadata;

            emetadata.Count.Should().Be(4);
            emetadata["mykey"].Should().Be("simple text");
            emetadata["v"].Should().Be(100);
            emetadata["identity"].Should().Be(typeof(DefinitionsCacheWriterTestCase));
        }
示例#2
0
        public void BuildManifest_ForEmptyFile_Succeeds()
        {
            using (var fs = new FileStream(Path.Combine(_folder, "manifest-generated1.xml"), FileMode.Open))
            {
                var definitions = DefinitionsCacheReader.build_manifest(new StreamReader(fs), _folder, new StubBindingContext(), BundleName);

                definitions.Exports.Should().BeEmpty();
                definitions.Imports.Should().BeEmpty();
            }
        }
示例#3
0
        public void BuildManifest_TypeAsMetadataEntry_UsesBindingContext()
        {
            using (var fs = new FileStream(Path.Combine(_folder, "manifest-generated4.xml"), FileMode.Open))
            {
                var definitions = DefinitionsCacheReader.build_manifest(new StreamReader(fs), _folder, new StubBindingContext(typeof(DummyDisposable)), BundleName);

                definitions.Exports.Should().HaveCount(1);
                definitions.Imports.Should().BeEmpty();

                var exportDef = definitions.Exports.ElementAt(0);
                exportDef.Metadata["key1"].Should().Be(typeof(DummyDisposable));
            }
        }
示例#4
0
        public void BuildManifest_ForImport_Succeeds()
        {
            using (var fs = new FileStream(Path.Combine(_folder, "manifest-generated5.xml"), FileMode.Open))
            {
                var definitions = DefinitionsCacheReader.build_manifest(new StreamReader(fs), _folder, new StubBindingContext(), BundleName);

                definitions.Exports.Should().BeEmpty();
                definitions.Imports.Should().HaveCount(1);

                var importDef = definitions.Imports.ElementAt(0);
                importDef.ContractName.Should().Equals("SomeName");
                importDef.Metadata.Count.Should().Be(1);
            }
        }
        public void CacheWriterProduction_IsSuccessfullyReadByCacheReader_1()
        {
            var writer = new StringWriter();

            DefinitionsCacheWriter.write_manifest(writer,
                                                  new ExportDefinition[0],
                                                  new[] { new ContractBasedImportDefinition("Name",
                                                                                            "typeIdentity", Enumerable.Empty <KeyValuePair <string, Type> >(), ImportCardinality.ZeroOrOne, true, false, CreationPolicy.Any) });

            var cache = DefinitionsCacheReader.build_manifest(
                new StringReader(writer.GetStringBuilder().ToString()),
                "path",
                new StubBindingContext(), BundleName);

            cache.Exports.Count().Should().Be(0);
            cache.Imports.Count().Should().Be(1);
            var importDef = cache.Imports.ElementAt(0) as ContractBasedImportDefinition;

            importDef.ContractName.Should().Be("Name");
            importDef.Cardinality.Should().Be(ImportCardinality.ZeroOrOne);
        }