Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void EntityCatalog_Message_FileNotFound_Continues()
        {
            string assemblyFileName = @"c:\Nowhere\DontExist.dll";

            ConsoleLogger                   logger       = new ConsoleLogger();
            IEnumerable <string>            assemblies   = new[] { assemblyFileName, this.GetType().Assembly.Location };
            EntityCatalog                   dsc          = new EntityCatalog(assemblies, logger);
            ICollection <EntityDescription> descriptions = dsc.EntityDescriptions;

            Assert.IsNotNull(descriptions);

            // Need to synthesize exactly the same message we'd expect from failed assembly load
            string exceptionMessage = null;

            try
            {
                AssemblyName.GetAssemblyName(assemblyFileName);
            }
            catch (FileNotFoundException fnfe)
            {
                exceptionMessage = fnfe.Message;
            }
            string expectedMessage = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Assembly_Load_Error, assemblyFileName, exceptionMessage);

            TestHelper.AssertContainsMessages(logger, expectedMessage);

            Assert.IsTrue(descriptions.Count > 0);
        }
Ejemplo n.º 3
0
        public void EntityCatalog_Message_BadImageFormat()
        {
            // 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();
            EntityCatalog dsc    = new EntityCatalog(new string[] { assemblyFileName }, logger);
            ICollection <EntityDescription> descriptions = dsc.EntityDescriptions;

            Assert.IsNotNull(descriptions);
            Assert.AreEqual(0, descriptions.Count);
            Assert.AreEqual(0, logger.ErrorMessages.Count);
            Assert.AreEqual(0, logger.WarningMessages.Count);

            // Need to synthesize exactly the same message we'd expect from failed assembly load
            string exceptionMessage = null;

            try
            {
                AssemblyName.GetAssemblyName(assemblyFileName);
            }
            catch (BadImageFormatException bife)
            {
                exceptionMessage = bife.Message;
            }
            finally
            {
                File.Delete(assemblyFileName);
            }
            string expectedMessage = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Assembly_Load_Error, assemblyFileName, exceptionMessage);

            TestHelper.AssertContainsMessages(logger, expectedMessage);
        }
Ejemplo n.º 4
0
        public void EntityCatalog_Message_FileNotFound()
        {
            var assemblyFileName = @"c:\Nowhere\DontExist.dll";
            var logger           = new ConsoleLogger();
            var dsc          = new EntityCatalog(new[] { assemblyFileName }, logger);
            var descriptions = dsc.EntityDescriptions;

            Assert.IsNotNull(descriptions);
            Assert.AreEqual(0, descriptions.Count);
            Assert.AreEqual(0, logger.ErrorMessages.Count);
            Assert.AreEqual(0, logger.WarningMessages.Count);

            // Need to synthesize exactly the same message we'd expect from failed assembly load
            string exceptionMessage = null;

            try
            {
                AssemblyName.GetAssemblyName(assemblyFileName);
            }
            catch (FileNotFoundException fnfe)
            {
                exceptionMessage = fnfe.Message;
            }
            string expectedMessage = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Assembly_Load_Error, assemblyFileName, exceptionMessage);

            TestHelper.AssertContainsMessages(logger, expectedMessage);
        }
Ejemplo n.º 5
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);
        }