Commit c02d2720 by Tomo Masakura

Merge branch '40-' into 'master'

Resolve "タイトルと説明のトリミング"

Closes #40

See merge request !14
parents 99a473c0 7fdf28d0
Pipeline #14871761 passed with stages
in 7 minutes 26 seconds
......@@ -46,6 +46,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Issues.Basis.Test", "src\Is
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTest", "src\IntegrationTest\IntegrationTest.csproj", "{F059FC63-1B1F-4BDF-9F62-D63AD7951D22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Issues.Domains", "src\Issues.Domains\Issues.Domains.csproj", "{4457B81D-BF79-4A2E-BD66-75C5A77768C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Issues.Domains.Test", "src\Issues.Domains.Test\Issues.Domains.Test.csproj", "{37467C36-34FD-4A3D-8067-C343588F1D3D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -179,6 +183,30 @@ Global
{F059FC63-1B1F-4BDF-9F62-D63AD7951D22}.Release|x64.Build.0 = Release|x64
{F059FC63-1B1F-4BDF-9F62-D63AD7951D22}.Release|x86.ActiveCfg = Release|x86
{F059FC63-1B1F-4BDF-9F62-D63AD7951D22}.Release|x86.Build.0 = Release|x86
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Debug|x64.ActiveCfg = Debug|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Debug|x64.Build.0 = Debug|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Debug|x86.ActiveCfg = Debug|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Debug|x86.Build.0 = Debug|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Release|Any CPU.Build.0 = Release|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Release|x64.ActiveCfg = Release|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Release|x64.Build.0 = Release|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Release|x86.ActiveCfg = Release|Any CPU
{4457B81D-BF79-4A2E-BD66-75C5A77768C5}.Release|x86.Build.0 = Release|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Debug|x64.ActiveCfg = Debug|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Debug|x64.Build.0 = Debug|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Debug|x86.ActiveCfg = Debug|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Debug|x86.Build.0 = Debug|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Release|Any CPU.Build.0 = Release|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Release|x64.ActiveCfg = Release|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Release|x64.Build.0 = Release|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Release|x86.ActiveCfg = Release|Any CPU
{37467C36-34FD-4A3D-8067-C343588F1D3D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B32D6EA5-22F5-4A06-9986-8AE95732E860} = {7724D563-6B66-4F78-A55A-8A1DB354B737}
......@@ -193,5 +221,7 @@ Global
{57515681-86F7-4830-BE58-A40C9C460B48} = {7724D563-6B66-4F78-A55A-8A1DB354B737}
{6A9DB509-AA06-4445-9F30-EB4264AC4EA6} = {7724D563-6B66-4F78-A55A-8A1DB354B737}
{F059FC63-1B1F-4BDF-9F62-D63AD7951D22} = {7724D563-6B66-4F78-A55A-8A1DB354B737}
{4457B81D-BF79-4A2E-BD66-75C5A77768C5} = {7724D563-6B66-4F78-A55A-8A1DB354B737}
{37467C36-34FD-4A3D-8067-C343588F1D3D} = {7724D563-6B66-4F78-A55A-8A1DB354B737}
EndGlobalSection
EndGlobal
using System;
using AcceptanceTest.Pages;
using Xunit;
namespace AcceptanceTest
{
public sealed class NewIssueTrimingTest : UseWebDriver
{
private readonly CreationIssuePage _target;
public NewIssueTrimingTest()
{
_target = Shortcuts.NewIssue();
}
[Fact]
public void TrimTitle()
{
var created = _target.Submit(new {Title = " hello, world! ", Description = "D"});
Assert.Equal("hello, world!", created.Title.Raw);
}
[Fact]
public void TrimSpecialCharactorsTitle()
{
var created = _target.Submit(new {Title = " hello, world!   ", Description = "D"});
Assert.Equal("hello, world!", created.Title.Raw);
}
[Fact]
public void TrimDescription()
{
var created = _target.Submit(new {Title = "T", Description = " a\n b \n"});
Assert.Equal(N("a\n b"), created.Description.Raw);
}
[Fact]
public void TrimSpecialCharactorsDescription()
{
var created = _target.Submit(new {Title = " T", Description = " a\n b  \n "});
Assert.Equal(N("a\n b"), created.Description.Raw);
}
private static string N(string text)
{
return text?.Replace("\n", Environment.NewLine);
}
}
}
\ No newline at end of file
......@@ -24,6 +24,8 @@ namespace AcceptanceTest.Pages
Target.NewInput(text, _driver);
}
public string Raw => Target.GetAttribute("innerHTML");
public bool HasError => Target.HasClass("input-validation-error");
public string Errors
......
......@@ -7,4 +7,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Issues.Domains\Issues.Domains.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -23,7 +23,23 @@ namespace Issues.Domains
{
var result = new IssueDescription("hello");
Assert.Equal("hello", $"{result}");
Assert.Equal("hello", (string) result);
}
[Fact]
public void Triming()
{
var result = (string) new IssueDescription(" hello ");
Assert.Equal("hello", result);
}
[Fact]
public void TrimingSpecialCharactors()
{
var result = new IssueDescription(" hello \r\n \t ");
Assert.Equal("hello", (string) result);
}
}
}
\ No newline at end of file
......@@ -21,9 +21,25 @@ namespace Issues.Domains
[Fact]
public void ConvertToString()
{
var result = new IssueTitle("hello");
var result = (string) new IssueTitle("hello");
Assert.Equal("hello", result);
}
[Fact]
public void Triming()
{
var result = new IssueTitle(" hello ");
Assert.Equal("hello", (string) result);
}
[Fact]
public void TrimingSpecialCharactors()
{
var result = new IssueTitle(" hello \r\n \t ");
Assert.Equal("hello", $"{result}");
Assert.Equal("hello", (string) result);
}
}
}
\ No newline at end of file
......@@ -9,5 +9,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Issues.Basis\Issues.Basis.csproj" />
<ProjectReference Include="..\Issues.Domains\Issues.Domains.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
namespace Issues.Domains
using static Issues.Domains.ValueObjectUtil;
namespace Issues.Domains
{
public struct IssueDescription
{
......@@ -6,12 +8,12 @@
public IssueDescription(string value)
{
_value = value;
_value = Normalize(value);
}
public override string ToString()
{
return $"{_value}";
return _value;
}
public static explicit operator IssueDescription(string description)
......
namespace Issues.Domains
using static Issues.Domains.ValueObjectUtil;
namespace Issues.Domains
{
public struct IssueTitle
{
......@@ -6,12 +8,12 @@
public IssueTitle(string value)
{
_value = value;
_value = Normalize(value);
}
public override string ToString()
{
return $"{_value}";
return _value;
}
public static explicit operator string(IssueTitle title)
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>
</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Issues.Domains\Issues.Domains.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
using Xunit;
namespace Issues.Domains
{
public sealed class ValueObjectUtilTest
{
[Fact]
public void TrimSpaces()
{
var result = ValueObjectUtil.Normalize(" hello, world ");
Assert.Equal("hello, world", result);
}
[Fact]
public void TrimFullWidthSpaces()
{
var result = ValueObjectUtil.Normalize("  hello, world ");
Assert.Equal("hello, world", result);
}
[Fact]
public void TrimTabs()
{
var result = ValueObjectUtil.Normalize("\t\thello, world\t\t");
Assert.Equal("hello, world", result);
}
[Fact]
public void TrimCrLfs()
{
var result = ValueObjectUtil.Normalize("\r\n\rhello, world\r\n\r");
Assert.Equal("hello, world", result);
}
[Fact]
public void TrimCombine()
{
var result = ValueObjectUtil.Normalize("\r\n  \thello, world .\r\n\t  ");
Assert.Equal("hello, world .", result);
}
[Fact]
public void ConvertFromCrToLf()
{
var result = ValueObjectUtil.Normalize("[\r]");
Assert.Equal("[\n]", result);
}
[Fact]
public void ConvertFromLfToLf()
{
var result = ValueObjectUtil.Normalize("[\n]");
Assert.Equal("[\n]", result);
}
[Fact]
public void ConvertCombine()
{
var result = ValueObjectUtil.Normalize("\r\n[\r\n\n \r]\r\n");
Assert.Equal("[\n\n \n]", result);
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>
</RootNamespace>
</PropertyGroup>
</Project>
\ No newline at end of file
namespace Issues.Domains
{
public static class ValueObjectUtil
{
public static string Normalize(string value)
{
return value?
.Trim()
.Replace("\r\n", "\n")
.Replace("\r", "\n");
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment