public void ShouldCreateFileNameFromConfigIfNull() { EFMGSettings settings = new EFMGSettings(); var configFilePath = @"c:\Temp\myConfig.json"; Generator.ManageFilePath(configFilePath, settings); settings.FilePath.ShouldBe(@"c:\Temp\myConfig.cs"); }
public void ShouldCreateRootFromConfigForFileWithoutRoot() { EFMGSettings settings = new EFMGSettings(); settings.FilePath = "SomeFileName.cs"; var configFilePath = @"c:\Temp\myConfig.json"; Generator.ManageFilePath(configFilePath, settings); settings.FilePath.ShouldBe(@"c:\Temp\SomeFileName.cs"); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { try { //get the selected item and some more info var _dte = (DTE2)Package.GetGlobalService(typeof(SDTE)); ProjectItem projectItem = Utils.GetSelectedProjectItem(_dte); if (projectItem == null) { return; } //init some props string projectPath = Utils.GetItemProjectPath(projectItem); String selectedItemFullPath = (string)projectItem.Properties.Item("FullPath").Value; string fileContent = File.ReadAllText(selectedItemFullPath); EFMGSettings[] settings = EFMGSettings.Build(fileContent); foreach (var setting in settings) { if (setting.Options.ImplementingClassPath == null) { setting.Options.ImplementingClassPath = Path.Combine(projectPath, "bin", "Debug"); } Generator.ManageFilePath(selectedItemFullPath, setting); var resultFile = Generator.Generate(setting); ProjectItem item = projectItem.ContainingProject.ProjectItems.AddFromFile(resultFile); } } catch (Exception ex) { throw new Exception("An error occured while generating the sources : " + ex.Message, ex); } }
public void ShouldSerializeModel(string folder, string configFile = null, string schemaFile = null, string expectedFile = null) { ApplicationInfo.TestMode = true; //1. Arrange string content = GetFileContent(configFile ?? "config.json", folder); string schema = GetFileContent(schemaFile ?? "schema.txt", folder); //Configure the test provider EFMGSettings[] settings = EFMGSettings.Build(content); //2. Act for each settings foreach (var setting in settings) { setting.Options.ProviderType = "Test.Helpers.TestSchemaProvider, Test.Helpers"; setting.Options.ProviderTypeArguments = new string[] { schema }; StringBuilder sb = new StringBuilder(); using (TextWriter sw = new StringWriter(sb)) { Generator.Generate(setting, sw); } //write tests //var pathToExpected = Path.Combine("C:\\projects\\cextensions\\CExtensions-EFModelGenerator\\src\\Test\\CExtensions.EFModelGenerator.Breeze.Test", folder, setting.FilePath); ; //using (TextWriter writer = File.CreateText(pathToExpected)) //{ // writer.Write(sb.ToString()); //} //3. Assert string expectedOutput = GetFileContent(setting.FilePath, folder); string a = System.Text.RegularExpressions.Regex.Replace(sb.ToString(), @"\s+|\t|\n|\t\n\r\0\x0B", ""); string b = System.Text.RegularExpressions.Regex.Replace(expectedOutput, @"\s+|\t|\n|\t\n\r\0\x0B", ""); bool isTheSame = String.Compare(a, b) == 0; isTheSame.ShouldBe(true, $"Should be {Environment.NewLine}{b}{Environment.NewLine} but was {Environment.NewLine}{a}{Environment.NewLine}"); } //Assert.False(true); }