コード例 #1
0
        public void SharedAssembliesManaged_Types()
        {
            string projectPath = null;
            string outputPath  = null;

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

            ConsoleLogger logger = new ConsoleLogger();

            using (var sa = CreatedSharedAssembliesService(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger))
            {
                string sharedTypeLocation = GetSharedTypeLocation(sa, typeof(TestEntity));
                Assert.IsNotNull(sharedTypeLocation, "Expected TestEntity type to be shared");
                Assert.IsTrue(sharedTypeLocation.Contains("ClientClassLib"), "Expected to find type in client class lib");

                sharedTypeLocation = GetSharedTypeLocation(sa, typeof(TestValidator));
                Assert.IsNotNull(sharedTypeLocation, "Expected TestValidator type to be shared");
                Assert.IsTrue(sharedTypeLocation.Contains("ClientClassLib"), "Expected to find type in client class lib");

                sharedTypeLocation = GetSharedTypeLocation(sa, typeof(DomainService));
                Assert.IsNull(sharedTypeLocation, "Expected DomainService type not to be shared");

                sharedTypeLocation = GetSharedTypeLocation(sa, typeof(TestValidatorServer));
                Assert.IsNull(sharedTypeLocation, "Expected TestValidatorServer type not to be shared");
            }

            TestHelper.AssertNoErrorsOrWarnings(logger);
        }
コード例 #2
0
        public void SharedAssembliesManaged_Methods()
        {
            string projectPath = null;
            string outputPath  = null;

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

            ConsoleLogger logger = new ConsoleLogger();

            using (var sa = CreatedSharedAssembliesService(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger))
            {
                var sharedMethodLocation = GetSharedMethodLocation(sa, typeof(TestValidator), "IsValid", new[] { typeof(TestEntity), typeof(ValidationContext) });
                Assert.IsNotNull(sharedMethodLocation, "Expected TestValidator.IsValid to be shared");
                Assert.IsTrue(sharedMethodLocation.Contains("ClientClassLib"), "Expected to find method in client class lib");

                sharedMethodLocation = GetSharedMethodLocation(sa, typeof(TestEntity), "ServerAndClientMethod", Type.EmptyTypes);
                Assert.IsNotNull(sharedMethodLocation, "Expected TestEntity.ServerAndClientMethod to be shared");
                Assert.IsTrue(sharedMethodLocation.Contains("ClientClassLib"), "Expected to find method in client class lib");

                sharedMethodLocation = GetSharedMethodLocation(sa, typeof(TestValidator), "ServertMethod", Type.EmptyTypes);
                Assert.IsNull(sharedMethodLocation, "Expected TestValidator.ServerMethod not to be shared");
            }

            TestHelper.AssertNoErrorsOrWarnings(logger);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
        public void SharedAssembliesManaged_Matches_MsCorLib()
        {
            Type[] sharedTypes = new Type[] {
                typeof(Int32),
                typeof(string),
                typeof(Decimal),
                typeof(List <int>),
                typeof(Dictionary <int, string>)
            };

            Type[] nonSharedTypes = new Type[] {
                typeof(DomainService),
                typeof(List <DomainService>),
                typeof(DomainService[])
                // Below is fomr System.IO.Compression.Filesystem which is not referenced by client
                //typeof(System.Xml.Linq.XElement)
            };

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

            string projectPath = null;
            string outputPath  = null;

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

            ConsoleLogger logger = new ConsoleLogger();

            using (var sa = CreatedSharedAssembliesService(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger))
            {
                foreach (Type t in sharedTypes)
                {
                    var sharedTypeLocation = GetSharedTypeLocation(sa, t);
                    Assert.IsNotNull(sharedTypeLocation, "Expected type " + t.Name + " to be considered shared.");
                }

                foreach (MethodBase m in sharedMethods)
                {
                    Type[] parameterTypes       = m.GetParameters().Select(p => p.ParameterType).ToArray();
                    var    sharedMethodLocation = GetSharedMethodLocation(sa, m.DeclaringType, m.Name, parameterTypes);
                    Assert.IsNotNull(sharedMethodLocation, "Expected method " + m.DeclaringType.Name + "." + m.Name + " to be considered shared.");
                }

                foreach (Type t in nonSharedTypes)
                {
                    var sType = GetSharedTypeLocation(sa, t);
                    Assert.IsNull(sType, "Expected type " + t.Name + " to be considered *not* shared.");
                }
            }
        }
コード例 #6
0
        public void SharedAssembliesManaged_Logs_Message_NonExistent_Assembly()
        {
            ConsoleLogger logger = new ConsoleLogger();
            string        file   = "DoesNotExist.dll";

            using (var sa = CreatedSharedAssembliesService(new string[] { file }, CodeGenHelper.GetClientAssemblyPaths(), logger))
            {
                var sharedType = GetSharedTypeLocation(sa, typeof(TestEntity));
                Assert.IsNull(sharedType, "Should not have detected any shared type.");

                string message = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Assembly_Load_Error, file, null);
                TestHelper.AssertHasInfoThatStartsWith(logger, message);
            }
        }
コード例 #7
0
        internal static SharedCodeService CreateSharedCodeService(string clientProjectPath, ILoggingService logger)
        {
            List <string> sourceFiles = CodeGenHelper.ClientClassLibSourceFiles(clientProjectPath);
            List <string> assemblies  = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true);

            SharedCodeServiceParameters parameters = new SharedCodeServiceParameters()
            {
                SharedSourceFiles             = sourceFiles.ToArray(),
                ClientAssemblies              = assemblies.ToArray(),
                ClientAssemblyPathsNormalized = CodeGenHelper.GetClientAssemblyPaths()
            };

            SharedCodeService sts = new SharedCodeService(parameters, logger);

            return(sts);
        }
コード例 #8
0
        [Microsoft.VisualStudio.TestTools.UnitTesting.Ignore] // Add this test for all other target frameworks where client is different from server
        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 = 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);

            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.");
            }
        }
コード例 #9
0
        public void SharedAssembliesManaged_Properties()
        {
            string projectPath = null;
            string outputPath  = null;

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

            ConsoleLogger logger = new ConsoleLogger();

            using (var sa = CreatedSharedAssembliesService(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger))
            {
                string sharedTypeLocation = GetSharedPropertyLocation(sa, typeof(TestEntity), nameof(TestEntity.ClientAndServerValue));
                Assert.IsNotNull(sharedTypeLocation, "Expected TestEntity type to be shared");
                Assert.IsTrue(sharedTypeLocation.Contains("ClientClassLib"), "Expected to find type in client class lib");

                sharedTypeLocation = GetSharedPropertyLocation(sa, typeof(TestEntity), nameof(TestEntity.ServerAndClientValue));
                Assert.IsNotNull(sharedTypeLocation, "Expected TestEntity type to be shared");
                Assert.IsTrue(sharedTypeLocation.Contains("ClientClassLib"), "Expected to find type in client class lib");

                sharedTypeLocation = GetSharedPropertyLocation(sa, typeof(TestEntity), nameof(TestEntity.TheValue));
                Assert.IsNull(sharedTypeLocation, "Expected TestEntity.TheValue type to not be shared");

                // We should detect properties from derived types
                sharedTypeLocation = GetSharedPropertyLocation(sa, "ServerClassLib.TestDomainSharedContext", "ValidationContext");
                Assert.IsNotNull(sharedTypeLocation, "Expected to detect properties from base classes (DomainContext.ValidationContext)");
                StringAssert.Contains(sharedTypeLocation, "OpenRiaServices.DomainServices.Client");

                // We should not detect internal properties
                sharedTypeLocation = GetSharedPropertyLocation(sa, "OpenRiaServices.DomainServices.Client.Entity", "ValidationErrors");
                Assert.IsNotNull(sharedTypeLocation, "Should detect properties in other assemblies");
                StringAssert.Contains(sharedTypeLocation, "OpenRiaServices.DomainServices.Client");

                sharedTypeLocation = GetSharedPropertyLocation(sa, "OpenRiaServices.DomainServices.Client.Entity", "ParentAssociation");
                Assert.IsNull(sharedTypeLocation, "Expected to not detect internal properties");

                sharedTypeLocation = GetSharedPropertyLocation(sa, "OpenRiaServices.DomainServices.Client.Entity", "IsMergingState");
                Assert.IsNull(sharedTypeLocation, "Expected to not detect protected internal properties");
            }

            TestHelper.AssertNoErrorsOrWarnings(logger);
        }
コード例 #10
0
        public void SharedAssemblies_Logs_Message_NonExistent_Assembly()
        {
            ConsoleLogger    logger = new ConsoleLogger();
            string           file   = "DoesNotExist.dll";
            SharedAssemblies sa     = new SharedAssemblies(new string[] { file }, CodeGenHelper.GetClientAssemblyPaths(), 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);
        }
コード例 #11
0
        public void SharedAssembliesManaged_Logs_Message_BadImageFormat_Assembly()
        {
            // Create fake DLL with bad image
            string assemblyFileName = Path.Combine(Path.GetTempPath(), (Guid.NewGuid().ToString() + ".dll"));

            File.WriteAllText(assemblyFileName, "neener neener neener");

            ConsoleLogger logger = new ConsoleLogger();

            using (var sa = CreatedSharedAssembliesService(new string[] { assemblyFileName }, CodeGenHelper.GetClientAssemblyPaths(), logger))
            {
                var sharedType = GetSharedTypeLocation(sa, typeof(TestEntity));
                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, null);

            TestHelper.AssertHasInfoThatStartsWith(logger, message);
        }