diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs index 8543ffb1ac..a5085f83a9 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs @@ -6,6 +6,8 @@ namespace Volo.Abp.Cli.ProjectBuilding.Files; public static class FileEntryExtensions { + private static int _maximumRecursionCount = 20; + public static FileEntry ReplaceText(this FileEntry file, string oldText, string newText) { file.NormalizeLineEndings(); @@ -20,7 +22,7 @@ public static class FileEntryExtensions public static void RemoveTemplateCodeMarkers(this FileEntry file) { - if (!file.Content.Contains("")) + if (!file.Content.Contains("") ) { return; } @@ -37,9 +39,9 @@ public static class FileEntryExtensions { //TODO: What if we use inline like: some-code //TODO: This logic skips the code in that case. Should handle it - ++i; + continue; } - + if (i < lines.Length) { newLines.Add(lines[i]); @@ -49,9 +51,9 @@ public static class FileEntryExtensions file.SetLines(newLines); } - private static void RemoveMarkedTemplateCode(this FileEntry file, List symbols) + private static void RemoveMarkedTemplateCode(this FileEntry file, List symbols, int recursionCount = 0) { - if (!file.Content.Contains("")) + if (!file.Content.Contains(" _maximumRecursionCount) { return; } @@ -97,9 +99,25 @@ public static class FileEntryExtensions continue; } - while (i < lines.Length && !lines[i].Contains("")) + var innerConditionCount = 0; + + while (i < lines.Length) { - ++i; + i++; + + if (lines[i].Contains("")) + { + if (innerConditionCount < 1) + { + break; + } + + innerConditionCount--; + } } if (lines[i+1].Contains("(() => Check.NotNull(null, nameof(NotNull_Test))); + Assert.Throws(() => Check.NotNull(null, nameof(NotNull_Test))); + Assert.Throws(() => Check.NotNull("test", nameof(NotNull_Test), maxLength: 3)); + Assert.Throws(() => Check.NotNull("test", nameof(NotNull_Test), minLength: 5)); + } + + [Fact] + public void NotNullOrWhiteSpace_Test() + { + Check.NotNullOrWhiteSpace("test", nameof(NotNullOrWhiteSpace_Test)).ShouldBe("test"); + Check.NotNullOrWhiteSpace("test", nameof(NotNullOrWhiteSpace_Test), maxLength: 4, minLength: 0).ShouldBe("test"); + + Assert.Throws(() => Check.NotNullOrWhiteSpace(null, nameof(NotNullOrWhiteSpace_Test))); + Assert.Throws(() => Check.NotNullOrWhiteSpace(string.Empty, nameof(NotNullOrWhiteSpace_Test))); + Assert.Throws(() => Check.NotNullOrWhiteSpace("test", nameof(NotNullOrWhiteSpace_Test), maxLength: 3)); + Assert.Throws(() => Check.NotNullOrWhiteSpace("test", nameof(NotNullOrWhiteSpace_Test), minLength: 5)); + } + + [Fact] + public void NotNullOrEmpty_Test() + { + Check.NotNullOrEmpty("test", nameof(NotNullOrEmpty_Test)).ShouldBe("test"); + Check.NotNullOrEmpty("test", nameof(NotNullOrEmpty_Test), maxLength: 4, minLength: 0).ShouldBe("test"); + Check.NotNullOrEmpty(new List{"test"}, nameof(NotNullOrEmpty_Test)); + + Assert.Throws(() => Check.NotNullOrEmpty(null, nameof(NotNullOrEmpty_Test))); + Assert.Throws(() => Check.NotNullOrEmpty(string.Empty, nameof(NotNullOrEmpty_Test))); + Assert.Throws(() => Check.NotNullOrEmpty("test", nameof(NotNullOrEmpty_Test), maxLength: 3)); + Assert.Throws(() => Check.NotNullOrEmpty("test", nameof(NotNullOrEmpty_Test), minLength: 5)); + Assert.Throws(() => Check.NotNullOrEmpty(new List(), nameof(NotNullOrEmpty_Test))); + } + + [Fact] + public void AssignableTo_Test() + { + Check.AssignableTo(typeof(string), nameof(AssignableTo_Test)).ShouldBe(typeof(string)); + Check.AssignableTo(typeof(Child), nameof(AssignableTo_Test)).ShouldBe(typeof(Child)); + Check.AssignableTo(typeof(Child2), nameof(AssignableTo_Test)).ShouldBe(typeof(Child2)); + Check.AssignableTo(typeof(Child2), nameof(AssignableTo_Test)).ShouldBe(typeof(Child2)); + + Assert.Throws(() => Check.AssignableTo(typeof(Parent), nameof(AssignableTo_Test))); + Assert.Throws(() => Check.AssignableTo(typeof(Child), nameof(AssignableTo_Test))); + Assert.Throws(() => Check.AssignableTo(typeof(Parent), nameof(AssignableTo_Test))); + } + + [Fact] + public void Length_Test() + { + Check.Length("test", nameof(Length_Test), maxLength: 4).ShouldBe("test"); + Check.Length("test", nameof(Length_Test), maxLength: 5).ShouldBe("test"); + Check.Length("test", nameof(Length_Test), maxLength:4, minLength: 0).ShouldBe("test"); + Check.Length("test", nameof(Length_Test), maxLength:4, minLength: 4).ShouldBe("test"); + + Assert.Throws(() => Check.Length("test", nameof(Length_Test), maxLength: 0)); + Assert.Throws(() => Check.Length("test", nameof(Length_Test), maxLength: 3)); + Assert.Throws(() => Check.Length("test", nameof(Length_Test), maxLength: 4, minLength: 5)); + } + + [Fact] + public void Positive_Test() + { + Check.Positive(1.To(), nameof(Positive_Test)).ShouldBe(1.To()); + Check.Positive(1.To(), nameof(Positive_Test)).ShouldBe(1.To()); + Check.Positive(1.To(), nameof(Positive_Test)).ShouldBe(1.To()); + Check.Positive(Decimal.One, nameof(Positive_Test)).ShouldBe(Decimal.One); + Check.Positive(1.0f, nameof(Positive_Test)).ShouldBe(1.0f); + Check.Positive(1.0, nameof(Positive_Test)).ShouldBe(1.0); + + Assert.Throws(() => Check.Positive(0.To(), nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(0.To(), nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(0.To(), nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(Decimal.Zero, nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(0.0f, nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(0.0, nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(-1.To(), nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(-1.To(), nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(-1.To(), nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(-Decimal.One, nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(-1.0f, nameof(Positive_Test))); + Assert.Throws(() => Check.Positive(-1.0, nameof(Positive_Test))); + } + + [Fact] + public void Range_Test() + { + Check.Range(1.To(), nameof(Range_Test), minimumValue: 1.To(), maximumValue: 10.To()).ShouldBe(1.To()); + Check.Range(1.To(), nameof(Range_Test), minimumValue: 1.To(), maximumValue: 10.To()).ShouldBe(1.To()); + Check.Range(1.To(), nameof(Range_Test), minimumValue: 1.To(), maximumValue: 10.To()).ShouldBe(1.To()); + Check.Range(Decimal.One, nameof(Range_Test), minimumValue: Decimal.One, maximumValue: 10.To()).ShouldBe(Decimal.One); + Check.Range(1.0f, nameof(Range_Test), minimumValue: 1.0f, maximumValue: 10.0f).ShouldBe(1.0f); + Check.Range(1.0, nameof(Range_Test), minimumValue: 1.0, maximumValue: 10.0).ShouldBe(1.0); + + Assert.Throws(() => Check.Range(0.To(), nameof(Range_Test), minimumValue: 1.To(), maximumValue: 10.To())); + Assert.Throws(() => Check.Range(0.To(), nameof(Range_Test), minimumValue: 1.To(), maximumValue: 10.To())); + Assert.Throws(() => Check.Range(0.To(), nameof(Range_Test), minimumValue: 1.To(), maximumValue: 10.To())); + Assert.Throws(() => Check.Range(Decimal.Zero, nameof(Range_Test), minimumValue: Decimal.One, maximumValue: 10.To())); + Assert.Throws(() => Check.Range(0.0f, nameof(Range_Test), minimumValue: 1.0f, maximumValue: 10.0f)); + Assert.Throws(() => Check.Range(0.0, nameof(Range_Test), minimumValue: 1.0, maximumValue: 10.0)); + Assert.Throws(() => Check.Range(11.To(), nameof(Range_Test), minimumValue: 1.To(), maximumValue: 10.To())); + Assert.Throws(() => Check.Range(11.To(), nameof(Range_Test), minimumValue: 1.To(), maximumValue: 10.To())); + Assert.Throws(() => Check.Range(11.To(), nameof(Range_Test), minimumValue: 1.To(), maximumValue: 10.To())); + Assert.Throws(() => Check.Range(11.To(), nameof(Range_Test), minimumValue: Decimal.One, maximumValue: 10.To())); + Assert.Throws(() => Check.Range(11.0f, nameof(Range_Test), minimumValue: 1.0f, maximumValue: 10.0f)); + Assert.Throws(() => Check.Range(11.0, nameof(Range_Test), minimumValue: 1.0, maximumValue: 10.0)); + } + + class Parent + { + + } + + class Child: Parent + { + + } + + class Child2: Child + { + + } +} \ No newline at end of file