Exemplo n.º 1
0
        public void Constructor2_FuncReturningAStringAsExportedValueGetter_ShouldBeReturnedByGetExportedValue()
        {
            var definition = ExportDefinitionFactory.Create();

            var export = new Export(definition, () => "Value");

            Assert.AreEqual("Value", export.Value);
        }
Exemplo n.º 2
0
        public void Constructor2_DefinitionAsDefinitionArgument_ShouldSetDefinitionProperty()
        {
            var definition = ExportDefinitionFactory.Create();

            var export = new Export(definition, () => null);

            Assert.AreSame(definition, export.Definition);
        }
Exemplo n.º 3
0
        public void Constructor2_FuncReturningNullAsExportedValueGetter_ShouldBeReturnedByGetExportedValue()
        {
            var definition = ExportDefinitionFactory.Create();

            var export = new Export(definition, () => null);

            Assert.IsNull(export.Value);
        }
Exemplo n.º 4
0
        public void Constructor2_NullAsExportedValueGetterArgument_ShouldThrowArgumentNull()
        {
            var definition = ExportDefinitionFactory.Create();

            ExceptionAssert.ThrowsArgument <ArgumentNullException>("exportedValueGetter", () =>
            {
                new Export(definition, (Func <object>)null);
            });
        }
        public void GetExportedValue_WrongDefinitionAsDefinitionArgument_ShouldThrowArgument()
        {
            var part       = CreateDefaultPart();
            var definition = ExportDefinitionFactory.Create();

            Assert.Throws <ArgumentException>("definition", () =>
            {
                part.GetExportedValue(definition);
            });
        }
Exemplo n.º 6
0
        public void Metadata_DerivedExportDefinition_ShouldReturnDefinitionMetadata()
        {
            var expectations = Expectations.GetMetadata();

            foreach (var e in expectations)
            {
                var definition = ExportDefinitionFactory.Create("ContractName", e);

                var export = new DerivedExport(definition);

                EnumerableAssert.AreEqual(e, export.Metadata);
            }
        }
Exemplo n.º 7
0
        public void AddPart_ReturnedComposablePart_WrongDefinitionAsDefinitionArgumentToGetExportedValue_ShouldThrowArgument()
        {
            CompositionBatch batch = new CompositionBatch();

            var part       = batch.AddPart(new Int32Importer());
            var definition = ExportDefinitionFactory.Create();

            Assert.Equal(1, batch.PartsToAdd.Count);

            Assert.Throws <ArgumentException>("definition", () =>
            {
                part.GetExportedValue(definition);
            });
        }
Exemplo n.º 8
0
        public void AddExportedValueOfT_ReturnedComposablePart_WrongDefinitionAsDefinitionArgumentToGetExportedValue_ShouldThrowArgument()
        {
            CompositionBatch batch = new CompositionBatch();

            var part       = batch.AddExportedValue <string>("Value");
            var definition = ExportDefinitionFactory.Create();

            Assert.AreEqual(1, batch.PartsToAdd.Count);

            ExceptionAssert.ThrowsArgument <ArgumentException>("definition", () =>
            {
                part.GetExportedValue(definition);
            });
        }
Exemplo n.º 9
0
        public ImportingComposablePart(string exportContractName, ImportCardinality cardinality, bool isRecomposable, params string[] contractNames)
        {
            if (exportContractName != null)
            {
                var definition = ExportDefinitionFactory.Create(exportContractName);

                _exportDefinitions.Add(definition);
            }

            foreach (string contractName in contractNames)
            {
                var definition = ImportDefinitionFactory.Create(contractName,
                                                                cardinality,
                                                                isRecomposable,
                                                                false);

                _importDefinitions.Add(definition);
            }
        }