Browse Source

Merge branch 'dev' into external-user-update

pull/12692/head
Halil İbrahim Kalkan 4 years ago
parent
commit
4d82198f71
  1. 35
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryExtensions.cs
  2. 1
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs
  3. 6
      framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js
  4. 137
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/Check_Tests.cs

35
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("</TEMPLATE-REMOVE>"))
if (!file.Content.Contains("<TEMPLATE-REMOVE") && !file.Content.Contains("</TEMPLATE-REMOVE>") )
{
return;
}
@ -37,9 +39,9 @@ public static class FileEntryExtensions
{
//TODO: What if we use inline like: <TEMPLATE-REMOVE IF-NOT="..."> some-code </TEMPLATE-REMOVE>
//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<string> symbols)
private static void RemoveMarkedTemplateCode(this FileEntry file, List<string> symbols, int recursionCount = 0)
{
if (!file.Content.Contains("</TEMPLATE-REMOVE>"))
if (!file.Content.Contains("<TEMPLATE-REMOVE") || recursionCount > _maximumRecursionCount)
{
return;
}
@ -97,9 +99,25 @@ public static class FileEntryExtensions
continue;
}
while (i < lines.Length && !lines[i].Contains("</TEMPLATE-REMOVE>"))
var innerConditionCount = 0;
while (i < lines.Length)
{
++i;
i++;
if (lines[i].Contains("<TEMPLATE-REMOVE"))
{
innerConditionCount++;
}
else if (lines[i].Contains("</TEMPLATE-REMOVE>"))
{
if (innerConditionCount < 1)
{
break;
}
innerConditionCount--;
}
}
if (lines[i+1].Contains("<TEMPLATE-REMOVE"))
@ -117,6 +135,8 @@ public static class FileEntryExtensions
}
file.SetLines(newLines);
RemoveMarkedTemplateCode(file, symbols, recursionCount + 1);
}
private static TemplateRemoveMarkerParseResult ParseTemplateRemoveMarker(string marker)
@ -126,6 +146,7 @@ public static class FileEntryExtensions
var condition = marker.Trim()
.RemovePreFix("//").Trim()
.RemovePreFix("@*").Trim()
.RemovePreFix("#").Trim()
.RemovePreFix("<!--").Trim()
.RemovePreFix("<TEMPLATE-REMOVE").Trim()
.RemovePostFix("*@").Trim()

1
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs

@ -37,6 +37,7 @@ public abstract class AppTemplateBase : TemplateInfo
RandomizeSslPorts(context, steps);
RandomizeStringEncryption(context, steps);
UpdateNuGetConfig(context, steps);
ConfigureDockerFiles(context, steps);
ChangeConnectionString(context, steps);
CleanupFolderHierarchy(context, steps);

6
framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js

@ -8,6 +8,8 @@ var abp = abp || {};
var firstRequest = true;
abp.appPath = configObject.baseUrl || abp.appPath;
var requestInterceptor = configObject.requestInterceptor;
configObject.requestInterceptor = async function (request) {
if(request.url.includes(excludeUrl[1])){
@ -26,6 +28,10 @@ var abp = abp || {};
if (antiForgeryToken) {
request.headers[abp.security.antiForgery.tokenHeaderName] = antiForgeryToken;
}
if(requestInterceptor){
requestInterceptor(request);
}
return request;
};

137
framework/test/Volo.Abp.Core.Tests/Volo/Abp/Check_Tests.cs

@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using Shouldly;
using Xunit;
namespace Volo.Abp;
public class Check_Tests
{
[Fact]
public void NotNull_Test()
{
Check.NotNull("test", nameof(NotNull_Test)).ShouldBe("test");
Check.NotNull(string.Empty, nameof(NotNull_Test)).ShouldBe(string.Empty);
Check.NotNull("test", nameof(NotNull_Test), maxLength: 4, minLength: 0).ShouldBe("test");
Assert.Throws<ArgumentNullException>(() => Check.NotNull<object>(null, nameof(NotNull_Test)));
Assert.Throws<ArgumentException>(() => Check.NotNull(null, nameof(NotNull_Test)));
Assert.Throws<ArgumentException>(() => Check.NotNull("test", nameof(NotNull_Test), maxLength: 3));
Assert.Throws<ArgumentException>(() => 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<ArgumentException>(() => Check.NotNullOrWhiteSpace(null, nameof(NotNullOrWhiteSpace_Test)));
Assert.Throws<ArgumentException>(() => Check.NotNullOrWhiteSpace(string.Empty, nameof(NotNullOrWhiteSpace_Test)));
Assert.Throws<ArgumentException>(() => Check.NotNullOrWhiteSpace("test", nameof(NotNullOrWhiteSpace_Test), maxLength: 3));
Assert.Throws<ArgumentException>(() => 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<string>{"test"}, nameof(NotNullOrEmpty_Test));
Assert.Throws<ArgumentException>(() => Check.NotNullOrEmpty(null, nameof(NotNullOrEmpty_Test)));
Assert.Throws<ArgumentException>(() => Check.NotNullOrEmpty(string.Empty, nameof(NotNullOrEmpty_Test)));
Assert.Throws<ArgumentException>(() => Check.NotNullOrEmpty("test", nameof(NotNullOrEmpty_Test), maxLength: 3));
Assert.Throws<ArgumentException>(() => Check.NotNullOrEmpty("test", nameof(NotNullOrEmpty_Test), minLength: 5));
Assert.Throws<ArgumentException>(() => Check.NotNullOrEmpty(new List<string>(), nameof(NotNullOrEmpty_Test)));
}
[Fact]
public void AssignableTo_Test()
{
Check.AssignableTo<object>(typeof(string), nameof(AssignableTo_Test)).ShouldBe(typeof(string));
Check.AssignableTo<Parent>(typeof(Child), nameof(AssignableTo_Test)).ShouldBe(typeof(Child));
Check.AssignableTo<Child>(typeof(Child2), nameof(AssignableTo_Test)).ShouldBe(typeof(Child2));
Check.AssignableTo<Parent>(typeof(Child2), nameof(AssignableTo_Test)).ShouldBe(typeof(Child2));
Assert.Throws<ArgumentException>(() => Check.AssignableTo<Child>(typeof(Parent), nameof(AssignableTo_Test)));
Assert.Throws<ArgumentException>(() => Check.AssignableTo<Child2>(typeof(Child), nameof(AssignableTo_Test)));
Assert.Throws<ArgumentException>(() => Check.AssignableTo<Child2>(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<ArgumentException>(() => Check.Length("test", nameof(Length_Test), maxLength: 0));
Assert.Throws<ArgumentException>(() => Check.Length("test", nameof(Length_Test), maxLength: 3));
Assert.Throws<ArgumentException>(() => Check.Length("test", nameof(Length_Test), maxLength: 4, minLength: 5));
}
[Fact]
public void Positive_Test()
{
Check.Positive(1.To<Int16>(), nameof(Positive_Test)).ShouldBe(1.To<Int16>());
Check.Positive(1.To<Int32>(), nameof(Positive_Test)).ShouldBe(1.To<Int32>());
Check.Positive(1.To<Int64>(), nameof(Positive_Test)).ShouldBe(1.To<Int64>());
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<ArgumentException>(() => Check.Positive(0.To<Int16>(), nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(0.To<Int32>(), nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(0.To<Int64>(), nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(Decimal.Zero, nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(0.0f, nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(0.0, nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(-1.To<Int16>(), nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(-1.To<Int32>(), nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(-1.To<Int64>(), nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(-Decimal.One, nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(-1.0f, nameof(Positive_Test)));
Assert.Throws<ArgumentException>(() => Check.Positive(-1.0, nameof(Positive_Test)));
}
[Fact]
public void Range_Test()
{
Check.Range(1.To<Int16>(), nameof(Range_Test), minimumValue: 1.To<Int16>(), maximumValue: 10.To<Int16>()).ShouldBe(1.To<Int16>());
Check.Range(1.To<Int32>(), nameof(Range_Test), minimumValue: 1.To<Int32>(), maximumValue: 10.To<Int32>()).ShouldBe(1.To<Int32>());
Check.Range(1.To<Int64>(), nameof(Range_Test), minimumValue: 1.To<Int64>(), maximumValue: 10.To<Int64>()).ShouldBe(1.To<Int64>());
Check.Range(Decimal.One, nameof(Range_Test), minimumValue: Decimal.One, maximumValue: 10.To<Decimal>()).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<ArgumentException>(() => Check.Range(0.To<Int16>(), nameof(Range_Test), minimumValue: 1.To<Int16>(), maximumValue: 10.To<Int16>()));
Assert.Throws<ArgumentException>(() => Check.Range(0.To<Int32>(), nameof(Range_Test), minimumValue: 1.To<Int32>(), maximumValue: 10.To<Int32>()));
Assert.Throws<ArgumentException>(() => Check.Range(0.To<Int64>(), nameof(Range_Test), minimumValue: 1.To<Int64>(), maximumValue: 10.To<Int64>()));
Assert.Throws<ArgumentException>(() => Check.Range(Decimal.Zero, nameof(Range_Test), minimumValue: Decimal.One, maximumValue: 10.To<Decimal>()));
Assert.Throws<ArgumentException>(() => Check.Range(0.0f, nameof(Range_Test), minimumValue: 1.0f, maximumValue: 10.0f));
Assert.Throws<ArgumentException>(() => Check.Range(0.0, nameof(Range_Test), minimumValue: 1.0, maximumValue: 10.0));
Assert.Throws<ArgumentException>(() => Check.Range(11.To<Int16>(), nameof(Range_Test), minimumValue: 1.To<Int16>(), maximumValue: 10.To<Int16>()));
Assert.Throws<ArgumentException>(() => Check.Range(11.To<Int32>(), nameof(Range_Test), minimumValue: 1.To<Int32>(), maximumValue: 10.To<Int32>()));
Assert.Throws<ArgumentException>(() => Check.Range(11.To<Int64>(), nameof(Range_Test), minimumValue: 1.To<Int64>(), maximumValue: 10.To<Int64>()));
Assert.Throws<ArgumentException>(() => Check.Range(11.To<Decimal>(), nameof(Range_Test), minimumValue: Decimal.One, maximumValue: 10.To<Decimal>()));
Assert.Throws<ArgumentException>(() => Check.Range(11.0f, nameof(Range_Test), minimumValue: 1.0f, maximumValue: 10.0f));
Assert.Throws<ArgumentException>(() => Check.Range(11.0, nameof(Range_Test), minimumValue: 1.0, maximumValue: 10.0));
}
class Parent
{
}
class Child: Parent
{
}
class Child2: Child
{
}
}
Loading…
Cancel
Save