public void ClientCodeGenerationDispatcher_Throws_Exception_Fully_Qualified_Name() { ConsoleLogger logger = new ConsoleLogger(); ClientCodeGenerationOptions options = new ClientCodeGenerationOptions() { Language = "C#", ClientProjectPath = "SampleProject.csproj" }; ICodeGenerationHost host = TestHelper.CreateMockCodeGenerationHost(logger, /*sharedTypeService*/ null); using (ClientCodeGenerationDispatcher dispatcher = new ClientCodeGenerationDispatcher()) { // Disable MEF for this test string[] compositionAssemblies = new string[0]; // And use FQN instead string codeGeneratorName = typeof(MockCodeGenerator).AssemblyQualifiedName; // Ask our mock to throw MockCodeGenerator.ThrowException = true; dispatcher.GenerateCode(host, options, Enumerable.Empty <Type>(), compositionAssemblies, codeGeneratorName); string error = string.Format(CultureInfo.CurrentCulture, Resource.CodeGenerator_Threw_Exception, codeGeneratorName, options.ClientProjectPath, MockCodeGenerator.Exception.Message); TestHelper.AssertContainsErrors(logger, error); } }
public void ClientCodeGenerationDispatcher_Throws_Exception_Logical_Name() { ConsoleLogger logger = new ConsoleLogger(); ClientCodeGenerationOptions options = new ClientCodeGenerationOptions() { Language = "C#", ClientProjectPath = "SampleProject.csproj" }; ICodeGenerationHost host = TestHelper.CreateMockCodeGenerationHost(logger, /*sharedTypeService*/ null); using (ClientCodeGenerationDispatcher dispatcher = new ClientCodeGenerationDispatcher()) { string[] compositionAssemblies = new string[] { Assembly.GetExecutingAssembly().Location }; string codeGeneratorName = MockCodeGenerator.GeneratorName; // Ask our mock to throw MockCodeGenerator.ThrowException = true; dispatcher.GenerateCode(host, options, Enumerable.Empty <Type>(), compositionAssemblies, codeGeneratorName); string error = string.Format(CultureInfo.CurrentCulture, Resource.CodeGenerator_Threw_Exception, codeGeneratorName, options.ClientProjectPath, MockCodeGenerator.Exception.Message); TestHelper.AssertContainsErrors(logger, error); } }
public void ClientCodeGenerationDispatcher_Error_Missing_Custom() { ConsoleLogger logger = new ConsoleLogger(); ClientCodeGenerationOptions options = new ClientCodeGenerationOptions() { Language = "C#", ClientProjectPath = "ClientProject", ServerProjectPath = "ServerProject" }; ICodeGenerationHost host = TestHelper.CreateMockCodeGenerationHost(logger, /*sharedTypeService*/ null); // Create a new dispatcher and call an internal extensibility point to add ourselves // into the MEF composition container using (ClientCodeGenerationDispatcher dispatcher = new ClientCodeGenerationDispatcher()) { string[] compositionAssemblies = new string[] { Assembly.GetExecutingAssembly().Location }; IClientCodeGenerator generator = dispatcher.FindCodeGenerator(host, options, compositionAssemblies, "NotAGenerator"); Assert.IsNull(generator, "the dispatcher should not find any code generator"); string error = string.Format(CultureInfo.CurrentCulture, Resource.Code_Generator_Not_Found, "NotAGenerator", options.Language, options.ServerProjectPath, options.ClientProjectPath, CodeDomClientCodeGenerator.GeneratorName); TestHelper.AssertContainsErrors(logger, error); } }
public void SharedTypes_CodeGen_Errors_On_Existing_Generated_Entity() { CreateClientFilesTask task = null; try { task = CodeGenHelper.CreateClientFilesTaskInstance("STT", /*includeClientOutputAssembly*/ true); var mockBuildEngine = (MockBuildEngine)task.BuildEngine; bool success = task.Execute(); Assert.IsFalse(success, "Expected build to fail"); string entityMsg = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_EntityTypesCannotBeShared_Reference, "ServerClassLib.TestEntity"); TestHelper.AssertContainsErrors(mockBuildEngine.ConsoleLogger, entityMsg); } finally { CodeGenHelper.DeleteTempFolder(task); } }
public void ClientCodeGenerationDispatcher_Custom_By_AssemblyQualifiedName_Ctor_Throws() { ConsoleLogger logger = new ConsoleLogger(); ClientCodeGenerationOptions options = new ClientCodeGenerationOptions() { Language = "C#" }; ICodeGenerationHost host = TestHelper.CreateMockCodeGenerationHost(logger, /*sharedTypeService*/ null); string codeGeneratorName = typeof(ThrowingCtorCodeGenerator).AssemblyQualifiedName; // Create a new dispatcher and call an internal extensibility point to add ourselves // into the MEF composition container using (ClientCodeGenerationDispatcher dispatcher = new ClientCodeGenerationDispatcher()) { string[] compositionAssemblies = new string[0]; IClientCodeGenerator generator = dispatcher.FindCodeGenerator(host, options, compositionAssemblies, codeGeneratorName); Assert.IsNull(generator, "the dispatcher should not find the code generator"); string error = string.Format(CultureInfo.CurrentCulture, Resource.Code_Generator_Instantiation_Error, codeGeneratorName, ThrowingCtorCodeGenerator.ErrorMessage); TestHelper.AssertContainsErrors(logger, error); } }
public void ClientCodeGenerationDispatcher_Error_Multiple_Generators_Same_Name() { ConsoleLogger logger = new ConsoleLogger(); ClientCodeGenerationOptions options = new ClientCodeGenerationOptions() { Language = "F#", ClientProjectPath = "ClientProject", ServerProjectPath = "ServerProject" }; ICodeGenerationHost host = TestHelper.CreateMockCodeGenerationHost(logger, /*sharedTypeService*/ null); // Create a new dispatcher and call an internal extensibility point to add ourselves // into the MEF composition container using (ClientCodeGenerationDispatcher dispatcher = new ClientCodeGenerationDispatcher()) { string[] compositionAssemblies = new string[] { Assembly.GetExecutingAssembly().Location }; string generatorName = MockFSharpCodeGenerator1.GeneratorName; IClientCodeGenerator generator = dispatcher.FindCodeGenerator(host, options, compositionAssemblies, generatorName); Assert.IsNull(generator, "the dispatcher should not pick a generator"); string errorParam = " " + typeof(MockFSharpCodeGenerator1).FullName + Environment.NewLine + " " + typeof(MockFSharpCodeGenerator2).FullName + Environment.NewLine; string error = string.Format(CultureInfo.CurrentCulture, Resource.Multiple_Named_Code_Generators, generatorName, options.Language, errorParam, options.ServerProjectPath, options.ClientProjectPath, typeof(MockFSharpCodeGenerator1).AssemblyQualifiedName); TestHelper.AssertContainsErrors(logger, error); } }