예제 #1
0
        public void AcceptsWithNonmatchingImportAndExport()
        {
            var types = new List <TypeDefinition>();
            var createTypeIdentity = IdentityFactory(types, new Dictionary <Type, TypeIdentity>());

            var repository = new Mock <ISatisfyPluginRequests>();
            {
                repository.Setup(r => r.IdentityByName(It.IsAny <string>()))
                .Returns <string>(n => types.Where(t => t.Identity.AssemblyQualifiedName.Equals(n)).Select(t => t.Identity).FirstOrDefault());
                repository.Setup(r => r.TypeByIdentity(It.IsAny <TypeIdentity>()))
                .Returns <TypeIdentity>(id => types.Where(t => t.Identity.Equals(id)).FirstOrDefault());
                repository.Setup(r => r.IsSubTypeOf(It.IsAny <TypeIdentity>(), It.IsAny <TypeIdentity>()))
                .Returns <TypeIdentity, TypeIdentity>((parent, child) => IsSubTypeOf(types, parent, child));
            }

            var importEngine = new PartImportEngine(repository.Object);

            var importDefinition = PropertyBasedImportDefinition.CreateDefinition(
                "A",
                createTypeIdentity(typeof(string)),
                ImportCardinality.ExactlyOne,
                true,
                CreationPolicy.NonShared,
                typeof(string).GetProperty("Length"),
                createTypeIdentity);
            var exportDefinition = MethodBasedExportDefinition.CreateDefinition(
                "A",
                typeof(string).GetMethod("Equals", new[] { typeof(string), typeof(string) }),
                createTypeIdentity);

            Assert.IsFalse(importEngine.Accepts(importDefinition, exportDefinition));
        }
예제 #2
0
        public void AcceptsWithExportTypeMatchesImportType()
        {
            var types = new List<TypeDefinition>();
            var createTypeIdentity = IdentityFactory(types, new Dictionary<Type, TypeIdentity>());

            var repository = new Mock<ISatisfyPluginRequests>();
            {
                repository.Setup(r => r.IdentityByName(It.IsAny<string>()))
                    .Returns<string>(n => types.Where(t => t.Identity.AssemblyQualifiedName.Equals(n)).Select(t => t.Identity).FirstOrDefault());
                repository.Setup(r => r.TypeByIdentity(It.IsAny<TypeIdentity>()))
                    .Returns<TypeIdentity>(id => types.Where(t => t.Identity.Equals(id)).FirstOrDefault());
                repository.Setup(r => r.IsSubTypeOf(It.IsAny<TypeIdentity>(), It.IsAny<TypeIdentity>()))
                    .Returns<TypeIdentity, TypeIdentity>((parent, child) => IsSubTypeOf(types, parent, child));
            }

            var importEngine = new PartImportEngine(repository.Object);

            var importDefinition = PropertyBasedImportDefinition.CreateDefinition(
                "A",
                createTypeIdentity(typeof(int)),
                ImportCardinality.ExactlyOne,
                true,
                CreationPolicy.NonShared,
                typeof(string).GetProperty("Length"),
                createTypeIdentity);
            var exportDefinition = PropertyBasedExportDefinition.CreateDefinition(
                "A",
                typeof(string).GetProperty("Length"),
                createTypeIdentity);

            Assert.IsTrue(importEngine.Accepts(importDefinition, exportDefinition));
        }