private string UpdateFileData(IRelationAdditionOptions options, string filePath) { string fileData = File.ReadAllText(filePath); fileData = UsingStatements.Add(fileData, $"{options.ProjectName}.Contract.Persistence.Modules.{options.DomainFrom}.{options.EntityNamePluralFrom}"); fileData = UsingStatements.Add(fileData, $"{options.ProjectName}.Logic.Tests.Modules.{options.DomainFrom}.{options.EntityNamePluralFrom}"); // ----------- Repository Generation ----------- StringEditor stringEditor = new StringEditor(fileData); stringEditor.MoveToEnd(); stringEditor.Next(); stringEditor.PrevThatContains("}"); stringEditor.PrevThatContains("}"); stringEditor.InsertLine("\n" + $" private Mock<I{options.EntityNamePluralFrom}CrudRepository> Setup{options.EntityNamePluralFrom}RepositoryDefault()\n" + " {\n" + $" var {options.EntityNamePluralLowerFrom}CrudRepository = new Mock<I{options.EntityNamePluralFrom}CrudRepository>(MockBehavior.Strict);\n" + $" {options.EntityNamePluralLowerFrom}CrudRepository.Setup(repository => repository.Does{options.EntityNameFrom}Exist({options.EntityNameFrom}TestValues.IdDefault)).Returns(true);\n" + $" {options.EntityNamePluralLowerFrom}CrudRepository.Setup(repository => repository.Does{options.EntityNameFrom}Exist({options.EntityNameFrom}TestValues.IdDefault2)).Returns(true);\n" + $" {options.EntityNamePluralLowerFrom}CrudRepository.Setup(repository => repository.Does{options.EntityNameFrom}Exist({options.EntityNameFrom}TestValues.IdForCreate)).Returns(false);\n" + $" return {options.EntityNamePluralLowerFrom}CrudRepository;\n" + " }"); fileData = stringEditor.GetText(); // ----------- TestMethods ----------- stringEditor = new StringEditor(fileData); stringEditor.NextThatContains("[TestMethod]"); while (stringEditor.GetLineNumber() < stringEditor.GetLineCount()) { stringEditor.Next(); if (stringEditor.GetLine().Contains("Create" + options.EntityNameTo) || stringEditor.GetLine().Contains("Update" + options.EntityNameTo)) { stringEditor.NextThatContains($"Mock<I{options.EntityNamePluralTo}CrudRepository>"); stringEditor.Next(line => !line.Contains("CrudRepository>") && line.Trim().Length > 0); stringEditor.InsertLine($" Mock<I{options.EntityNamePluralFrom}CrudRepository> {options.EntityNamePluralLowerFrom}CrudRepository = this.Setup{options.EntityNamePluralFrom}RepositoryDefault();"); stringEditor.NextThatContains($"{options.EntityNamePluralTo}CrudLogic {options.EntityNamePluralLowerTo}CrudLogic = new {options.EntityNamePluralTo}CrudLogic"); stringEditor.Next(line => !line.Contains("CrudRepository.Object")); stringEditor.InsertLine($" {options.EntityNamePluralLowerFrom}CrudRepository.Object,"); } else { stringEditor.NextThatContains($"{options.EntityNamePluralTo}CrudLogic {options.EntityNamePluralLowerTo}CrudLogic = new {options.EntityNamePluralTo}CrudLogic"); stringEditor.Next(line => !line.Contains("CrudRepository.Object")); stringEditor.InsertLine(" null,"); } stringEditor.NextThatContains("[TestMethod]"); } return(stringEditor.GetText()); }
private string AddProperty(string file, IPropertyAdditionOptions options, bool forInterface) { StringEditor stringEditor = new StringEditor(file); FindStartingLineForNewProperty(file, options, stringEditor); if (!stringEditor.GetLine().Contains("}")) { stringEditor.Prev(); } if (ContainsProperty(file)) { stringEditor.InsertNewLine(); } if (forInterface) { stringEditor.InsertLine(BackendDtoInterfacePropertyLine.GetPropertyLine(options)); } else { stringEditor.InsertLine(BackendDtoPropertyLine.GetPropertyLine(options)); } return(stringEditor.GetText()); }
private string AddProperty(string file, IPropertyAdditionOptions options) { StringEditor stringEditor = new StringEditor(file); FindStartingLineForNewProperty(file, options, stringEditor); if (!stringEditor.GetLine().Contains("}")) { stringEditor.Prev(); } if (ContainsProperty(file)) { stringEditor.InsertNewLine(); } if (!options.IsOptional) { stringEditor.InsertLine(" [Required]"); } if (options.PropertyType == PropertyTypes.String && options.PropertyTypeExtra != null) { stringEditor.InsertLine($" [StringLength({options.PropertyTypeExtra})]"); } stringEditor.InsertLine(BackendDtoPropertyLine.GetPropertyLine(options)); return(stringEditor.GetText()); }
private string AddProperty(string file, IRelationSideAdditionOptions options, bool forInterface) { StringEditor stringEditor = new StringEditor(file); FindStartingLineForNewProperty(file, options, stringEditor); if (!stringEditor.GetLine().Contains("}")) { stringEditor.Prev(); } if (ContainsProperty(file)) { stringEditor.InsertNewLine(); } if (forInterface) { stringEditor.InsertLine($" {options.PropertyType} {options.PropertyName} {{ get; set; }}"); } else { stringEditor.InsertLine($" public {options.PropertyType} {options.PropertyName} {{ get; set; }}"); } return(stringEditor.GetText()); }
private string UpdateFileData(IRelationSideAdditionOptions options, string filePath) { string fileData = File.ReadAllText(filePath); StringEditor stringEditor = new StringEditor(fileData); if (!stringEditor.GetLine().Contains("export interface")) { stringEditor.NextThatContains($"export interface"); } stringEditor.NextThatContains("}"); stringEditor.InsertLine($" {options.PropertyName.LowerFirstChar()}: {options.PropertyType};"); return(stringEditor.GetText()); }
private string AddStartupMethod(string fileData, IDomainAdditionOptions options, string projectFolder) { StringEditor stringEditor = new StringEditor(fileData); // Insert using stringEditor.MoveToEnd(); if (!stringEditor.GetLine().Contains("}")) { stringEditor.PrevThatContains("}"); } stringEditor.PrevThatContains("}"); stringEditor.InsertLine(GetStartupMethod(options.Domain, projectFolder)); return(stringEditor.GetText()); }
private string UpdateFileData(IPropertyAdditionOptions options, string filePath) { string fileData = File.ReadAllText(filePath); StringEditor stringEditor = new StringEditor(fileData); if (!stringEditor.GetLine().Contains("export interface")) { stringEditor.NextThatContains($"export interface"); } stringEditor.NextThatContains("}"); stringEditor.InsertLine(FrontendDtoPropertyLine.GetPropertyLine(options)); return(stringEditor.GetText()); }