Reorganize for unit tests, add URI.WithXXX methods
ln.build - build0.waldrennach.l--n.de build job pending
Details
ln.build - build0.waldrennach.l--n.de build job pending
Details
parent
38bc2953d6
commit
1d02544745
|
@ -0,0 +1,48 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.type", "ln.type\ln.type.csproj", "{98686C62-A822-4045-8403-A6CBD40E7EB3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.type.tests", "ln.type.tests\ln.type.tests.csproj", "{EDFCB172-4EFD-4731-98CB-CB0E082F3204}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|x64.Build.0 = Release|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|x86.Build.0 = Release|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|x64.Build.0 = Release|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,41 @@
|
|||
using NUnit.Framework;
|
||||
|
||||
namespace ln.type.tests
|
||||
{
|
||||
public class URITests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test1()
|
||||
{
|
||||
string testBaseURI = "http://alpha:beta:gamma@myHost:3456/path/to/resource?query=all#fragmentA";
|
||||
|
||||
URI testURI = new URI(testBaseURI);
|
||||
Assert.AreEqual(testBaseURI, testURI.ToString(true));
|
||||
|
||||
Assert.AreEqual(
|
||||
"http://omega@myHost:3456/path/to/resource?query=all#fragmentA",
|
||||
testURI.WithUserInfo("omega").ToString(true)
|
||||
);
|
||||
Assert.AreEqual(
|
||||
"http://alpha:beta:gamma@myHost:3456/my/path?query=all#fragmentA",
|
||||
testURI.WithPath("/my/path").ToString(true)
|
||||
);
|
||||
Assert.AreEqual(
|
||||
"http://alpha:beta:gamma@myHost:3456/path/to/resource?such=a&shame#fragmentA",
|
||||
testURI.WithQuery("such=a&shame").ToString(true)
|
||||
);
|
||||
Assert.AreEqual(
|
||||
"https://alpha:beta:gamma@myHost:3456/path/to/resource?query=all#fragmentA",
|
||||
testURI.WithScheme("https").ToString(true)
|
||||
);
|
||||
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
|
||||
<ProjectReference Include="../ln.type/ln.type.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -8,6 +8,7 @@
|
|||
// *
|
||||
// **/
|
||||
using System;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
namespace ln.type
|
||||
{
|
||||
|
@ -43,6 +44,20 @@ namespace ln.type
|
|||
Parse(String.Format("{0}://{1}{2}", scheme, authority, path));
|
||||
ParseAuthority();
|
||||
}
|
||||
public URI(String scheme,string[] userinfo,string host,string port,string path,string query,string fragment)
|
||||
{
|
||||
Scheme = scheme;
|
||||
UserInfo = userinfo ?? new string[0];
|
||||
Host = host;
|
||||
Port = port;
|
||||
if (userinfo.Length == 0)
|
||||
Authority = String.Format("{0}:{1}", Host, Port);
|
||||
else
|
||||
Authority = String.Format("{2}@{0}:{1}", Host, Port, string.Join(':', UserInfo));
|
||||
Path = path;
|
||||
Query = query;
|
||||
Fragment = fragment;
|
||||
}
|
||||
public URI(String scheme,String authority,string path,string query,string fragment)
|
||||
{
|
||||
Scheme = scheme;
|
||||
|
@ -75,6 +90,13 @@ namespace ln.type
|
|||
}
|
||||
}
|
||||
|
||||
public URI WithUserInfo(params string[] userInfo) => new URI(Scheme,userInfo, Host, Port, Path, Query, Fragment);
|
||||
public URI WithHost(string host) => new URI(Scheme,UserInfo, host, Port, Path, Query, Fragment);
|
||||
public URI WithPort(string port) => new URI(Scheme,UserInfo, Host, port, Path, Query, Fragment);
|
||||
public URI WithScheme(string scheme) => new URI(scheme, UserInfo, Host, Port, Path, Query, Fragment);
|
||||
public URI WithPath(string path) => new URI(Scheme, UserInfo, Host, Port, path, Query, Fragment);
|
||||
public URI WithQuery(string query) => new URI(Scheme, UserInfo, Host, Port, Path, query, Fragment);
|
||||
public URI WithFragment(string fragment) => new URI(Scheme, UserInfo, Host, Port, Path, Query, fragment);
|
||||
|
||||
private void Parse(String uri)
|
||||
{
|
||||
|
@ -181,7 +203,8 @@ namespace ln.type
|
|||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
public override string ToString() => ToString(false);
|
||||
public string ToString(bool withFullUserInfo)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
|
@ -193,7 +216,10 @@ namespace ln.type
|
|||
stringBuilder.Append("//");
|
||||
if (UserInfo.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(UserInfo[0]);
|
||||
if (withFullUserInfo)
|
||||
stringBuilder.Append(String.Join(':',UserInfo));
|
||||
else
|
||||
stringBuilder.Append(UserInfo[0]);
|
||||
stringBuilder.Append('@');
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>0.1.4</Version>
|
||||
<Version>0.1.5</Version>
|
||||
<Authors>Harald Wolff-Thobaben</Authors>
|
||||
<Company>l--n.de</Company>
|
||||
<AssemblyVersion>0.0.1.0</AssemblyVersion>
|
Loading…
Reference in New Issue