public void TypeIdentityConstraint_ValidMatchingExportDef_ShouldMatch() { var contractName = "MyContract"; var typeIdentity = AttributedModelServices.GetTypeIdentity(typeof(ConstraintServicesTests)); var metadata = new Dictionary <string, object>(); metadata.Add(CompositionConstants.ExportTypeIdentityMetadataName, typeIdentity); var exportDefinition = new ExportDefinition(contractName, metadata); var constraint = ConstraintServices.CreateConstraint(contractName, typeIdentity, null, CreationPolicy.Any); var predicate = constraint.Compile(); Assert.True(predicate(exportDefinition)); }
[ActiveIssue("https://github.com/dotnet/corefx/issues/25498", TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. public void InAdditionToCatalogTest() { var container = ContainerFactory.CreateWithDefaultAttributedCatalog(); IDictionary <string, object> multMetadata = new Dictionary <string, object>(); multMetadata["Var1"] = "mult"; multMetadata[CompositionConstants.ExportTypeIdentityMetadataName] = AttributedModelServices.GetTypeIdentity(typeof(Func <int, int, int>)); var basicValue = ExportFactory.Create("Add", multMetadata, (() => (Func <int, int, int>) delegate(int a, int b) { return(a * b); })); CompositionBatch batch = new CompositionBatch(); batch.AddExport(basicValue); container.Compose(batch); var exports = container.GetExports <Func <int, int, int>, ITrans_ExportableTest>("Add"); Assert.Equal(3, exports.Count()); foreach (var export in exports) { if (export.Metadata.Var1 == "mult") { Assert.Equal(2, export.Value(1, 2)); } else if (export.Metadata.Var1 == "add") { Assert.Equal(3, export.Value(1, 2)); } else if (export.Metadata.Var1 == "sub") { Assert.Equal(-1, export.Value(1, 2)); } else { throw new NotImplementedException(); } } }
public MicroExport(string contractName, Type contractType, IDictionary <string, object> metadata, params object[] exportedValues) { this.ContractName = contractName; this.ExportedValues = exportedValues; if (contractType != null) { string typeIdentity = AttributedModelServices.GetTypeIdentity(contractType); if (metadata == null) { metadata = new Dictionary <string, object>(); } object val; if (!metadata.TryGetValue(CompositionConstants.ExportTypeIdentityMetadataName, out val)) { metadata.Add(CompositionConstants.ExportTypeIdentityMetadataName, AttributedModelServices.GetTypeIdentity(contractType)); } } this.Metadata = metadata; }
public void InAdditionToCatalogTest() { var container = ContainerFactory.CreateWithDefaultAttributedCatalog(); IDictionary <string, object> multMetadata = new Dictionary <string, object>(); multMetadata["Var1"] = "mult"; multMetadata[CompositionConstants.ExportTypeIdentityMetadataName] = AttributedModelServices.GetTypeIdentity(typeof(Func <int, int, int>)); var basicValue = ExportFactory.Create("Add", multMetadata, (() => (Func <int, int, int>) delegate(int a, int b) { return(a * b); })); CompositionBatch batch = new CompositionBatch(); batch.AddExport(basicValue); container.Compose(batch); var exports = container.GetExports <Func <int, int, int>, IExportableTest>("Add"); Assert.AreEqual(3, exports.Count(), "There should be 3 entries for 'Add'"); foreach (var export in exports) { if (export.Metadata.Var1 == "mult") { Assert.AreEqual(2, export.Value(1, 2), "1 * 2 == 2"); } else if (export.Metadata.Var1 == "add") { Assert.AreEqual(3, export.Value(1, 2), "1 + 2 == 3"); } else if (export.Metadata.Var1 == "sub") { Assert.AreEqual(-1, export.Value(1, 2), "1 - 2 == -1"); } else { Assert.Fail("Unexpected value"); } } }
public static string GetContractName(Type type) { Requires.NotNull(type, nameof(type)); return(AttributedModelServices.GetTypeIdentity(type)); }
[ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. public void ICompositionElementDisplayName_ShouldIncludeDerivedCatalogTypeNameAndTypeFullNames() { var expectations = Expectations.GetAttributedTypes(); foreach (var e in expectations) { var catalog = (ICompositionElement) new DerivedTypeCatalog(e); string expected = string.Format(SR.TypeCatalog_DisplayNameFormat, typeof(DerivedTypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e)); Assert.Equal(expected, catalog.DisplayName); } }
public static string GetContractName(Type type) { return(AttributedModelServices.GetTypeIdentity(type)); }
public void ICompositionElementDisplayName_SingleTypeAsTypesArgument_ShouldIncludeCatalogTypeNameAndTypeFullName() { var expectations = Expectations.GetAttributedTypes(); foreach (var e in expectations) { var catalog = (ICompositionElement)CreateTypeCatalog(e); string expected = string.Format(Strings.TypeCatalog_DisplayNameFormat, typeof(TypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e)); Assert.AreEqual(expected, catalog.DisplayName); } }