Exemple #1
0
        public void SharedAssemblies_Methods()
        {
            string projectPath = null;
            string outputPath  = null;

            TestHelper.GetProjectPaths(string.Empty, out projectPath, out outputPath);
            string        clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath);
            List <string> assemblies        = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true);

            ConsoleLogger    logger = new ConsoleLogger();
            SharedAssemblies sa     = new SharedAssemblies(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger);

            MethodBase sharedMethod = sa.GetSharedMethod(typeof(TestValidator).AssemblyQualifiedName, "IsValid", new string[] { typeof(TestEntity).AssemblyQualifiedName, typeof(ValidationContext).AssemblyQualifiedName });

            Assert.IsNotNull(sharedMethod, "Expected TestValidator.IsValid to be shared");
            Assert.IsTrue(sharedMethod.DeclaringType.Assembly.Location.Contains("ClientClassLib"), "Expected to find method in client class lib");

            sharedMethod = sa.GetSharedMethod(typeof(TestEntity).AssemblyQualifiedName, "ServerAndClientMethod", Array.Empty <string>());
            Assert.IsNotNull(sharedMethod, "Expected TestEntity.ServerAndClientMethod to be shared");
            Assert.IsTrue(sharedMethod.DeclaringType.Assembly.Location.Contains("ClientClassLib"), "Expected to find method in client class lib");

            sharedMethod = sa.GetSharedMethod(typeof(TestValidator).AssemblyQualifiedName, "ServertMethod", Array.Empty <string>());
            Assert.IsNull(sharedMethod, "Expected TestValidator.ServerMethod not to be shared");

            TestHelper.AssertNoErrorsOrWarnings(logger);
        }
Exemple #2
0
        public void SharedAssemblies_Logs_Message_BadImageFormat_Assembly()
        {
            // Create fake DLL with bad image 
            var assemblyFileName = Path.Combine(Path.GetTempPath(), (Guid.NewGuid().ToString() + ".dll"));
            File.WriteAllText(assemblyFileName, "neener neener neener");

            var logger = new ConsoleLogger();
            var sa = new SharedAssemblies(new[] { assemblyFileName }, Enumerable.Empty<string>(), logger);

            Type sharedType = sa.GetSharedType(typeof(TestEntity).AssemblyQualifiedName);
            Assert.IsNull(sharedType, "Should not have detected any shared type.");

            string errorMessage = null;
            try
            {
                Assembly.ReflectionOnlyLoadFrom(assemblyFileName);
            }
            catch (BadImageFormatException bife)
            {
                errorMessage = bife.Message;
            }
            finally
            {
                File.Delete(assemblyFileName);
            }
            string message = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Assembly_Load_Error, assemblyFileName, errorMessage);
            TestHelper.AssertContainsMessages(logger, message);
        }
Exemple #3
0
        public void SharedAssemblies_Types()
        {
            string projectPath = null;
            string outputPath  = null;

            TestHelper.GetProjectPaths(string.Empty, out projectPath, out outputPath);
            string        clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath);
            List <string> assemblies        = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true);

            ConsoleLogger    logger = new ConsoleLogger();
            SharedAssemblies sa     = new SharedAssemblies(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger);

            Type sharedType = sa.GetSharedType(typeof(TestEntity).AssemblyQualifiedName);

            Assert.IsNotNull(sharedType, "Expected TestEntity type to be shared");
            Assert.IsTrue(sharedType.Assembly.Location.Contains("ClientClassLib"), "Expected to find type in client class lib");

            sharedType = sa.GetSharedType(typeof(TestValidator).AssemblyQualifiedName);
            Assert.IsNotNull(sharedType, "Expected TestValidator type to be shared");
            Assert.IsTrue(sharedType.Assembly.Location.Contains("ClientClassLib"), "Expected to find type in client class lib");

            sharedType = sa.GetSharedType(typeof(DomainService).AssemblyQualifiedName);
            Assert.IsNull(sharedType, "Expected DomainService type not to be shared");

            sharedType = sa.GetSharedType(typeof(TestValidatorServer).AssemblyQualifiedName);
            Assert.IsNull(sharedType, "Expected TestValidatorServer type not to be shared");

            TestHelper.AssertNoErrorsOrWarnings(logger);
        }
        protected override Assembly Load(AssemblyName assemblyName)
        {
            if (SharedAssemblies.Contains(assemblyName.Name))
            {
                return(DefaultLoadContext.LoadFromAssemblyName(assemblyName));
            }
            string assemblyPath = DependencyResolver.ResolveAssemblyToPath(assemblyName);

            return(assemblyPath != null?LoadFromAssemblyPath(assemblyPath) : null);
        }
Exemple #5
0
        public void SharedAssemblies_Matches_MsCorLib()
        {
            Type[] sharedTypes = new Type[] {
                typeof(Int32),
                typeof(string),
                typeof(Decimal),
            };

            Type[] nonSharedTypes = new Type[] {
                typeof(SerializableAttribute),
                typeof(System.Xml.Linq.XElement)
            };

            MethodBase[] sharedMethods = new MethodBase[] {
                typeof(string).GetMethod("CopyTo"),
            };

            string projectPath, outputPath;

            TestHelper.GetProjectPaths("SAT", out projectPath, out outputPath);
            string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath);
            List<string> assemblies = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true);

            var logger = new ConsoleLogger();
            var sa = new SharedAssemblies(assemblies, Enumerable.Empty<string>(), logger);

            foreach (Type t in sharedTypes)
            {
                Type sharedType = sa.GetSharedType(t.AssemblyQualifiedName);
                Assert.IsNotNull(sharedType, "Expected type " + t.Name + " to be considered shared.");
            }

            foreach (MethodBase m in sharedMethods)
            {
                string[] parameterTypes = m.GetParameters().Select<ParameterInfo, string>(p => p.ParameterType.AssemblyQualifiedName).ToArray();
                MethodBase sharedMethod = sa.GetSharedMethod(m.DeclaringType.AssemblyQualifiedName, m.Name, parameterTypes);
                Assert.IsNotNull(sharedMethod, "Expected method " + m.DeclaringType.Name + "." + m.Name + " to be considered shared.");
            }

            foreach (Type t in nonSharedTypes)
            {
                Type sType = sa.GetSharedType(t.AssemblyQualifiedName);
                Assert.IsNull(sType, "Expected type " + t.Name + " to be considered *not* shared.");
            }

        }
Exemple #6
0
        public void SharedAssemblies_Logs_Message_NonExistent_Assembly()
        {
            var logger = new ConsoleLogger();
            var file = "DoesNotExist.dll";
            var sa = new SharedAssemblies(new[] { file }, Enumerable.Empty<string>(), logger);

            Type sharedType = sa.GetSharedType(typeof(TestEntity).AssemblyQualifiedName);
            Assert.IsNull(sharedType, "Should not have detected any shared type.");

            string errorMessage = null;
            try{
                Assembly.ReflectionOnlyLoadFrom(file);
            }
            catch (FileNotFoundException fnfe)
            {
                errorMessage = fnfe.Message;
            }
            string message = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Assembly_Load_Error, file, errorMessage);
            TestHelper.AssertContainsMessages(logger, message);
        }
Exemple #7
0
        private static string GetSharedPropertyLocation(SharedAssemblies sa, string fullName, string propertyName)
        {
            var key = CodeMemberKey.CreatePropertyKey(fullName, propertyName);

            return(sa.GetSharedAssemblyPath(key));
        }
Exemple #8
0
 private static string GetSharedPropertyLocation(SharedAssemblies sa, Type type, string propertyName)
 {
     return(GetSharedPropertyLocation(sa, type.FullName, propertyName));
 }
Exemple #9
0
        private static string GetSharedMethodLocation(SharedAssemblies sa, Type type, string methodName, Type[] parameterTypes)
        {
            var key = CodeMemberKey.CreateMethodKey(type.AssemblyQualifiedName, methodName, parameterTypes.Select(t => t.AssemblyQualifiedName).ToArray());

            return(sa.GetSharedAssemblyPath(key));
        }
Exemple #10
0
        private static string GetSharedTypeLocation(SharedAssemblies sa, Type type)
        {
            var key = CodeMemberKey.CreateTypeKey(type.FullName);

            return(sa.GetSharedAssemblyPath(key));
        }