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 UpdateFileData(IRelationAdditionOptions options, string filePath) { string fileData = File.ReadAllText(filePath); StringEditor stringEditor = new StringEditor(fileData); stringEditor.NextThatContains("GridColumns: string[]"); stringEditor.NextThatContains("'detail'"); stringEditor.InsertLine($" '{options.PropertyNameFrom.LowerFirstChar()}',"); stringEditor.NextThatContains("constructor("); stringEditor.InsertLine($" {options.EntityNamePluralLowerFrom}: I{options.EntityNameFrom}[];"); stringEditor.InsertNewLine(); stringEditor.Next(); stringEditor.InsertLine($" private {options.EntityNamePluralLowerFrom}CrudService: {options.EntityNamePluralFrom}CrudService,"); stringEditor.NextThatContains("ngOnInit()"); int lineNumber = stringEditor.GetLineNumber(); stringEditor.Next(line => !line.Trim().StartsWith("await this.setup")); stringEditor.InsertLine($" await this.setup{options.EntityNamePluralFrom}Filter();"); if (stringEditor.GetLineNumber() - lineNumber == 2) { stringEditor.InsertNewLine(); } stringEditor.MoveToEnd(); stringEditor.PrevThatContains("}"); stringEditor.InsertNewLine(); stringEditor.InsertLine(GetNameResolutionMethod(options)); stringEditor.InsertNewLine(); stringEditor.InsertLine(GetSetupMethod(options)); return(stringEditor.GetText()); }