Skip to content

Commit 14a4095

Browse files
committed
유닛테스트 추가 (1)
- 파일명 치환 - 하위문자열
1 parent d73217a commit 14a4095

File tree

6 files changed

+121
-2
lines changed

6 files changed

+121
-2
lines changed

DaramRenamer.Commands/FileInfo.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public class FileInfo : IComparable<FileInfo>, INotifyPropertyChanged
1919

2020
private string _originalFullPath;
2121

22-
public FileInfo(string fullPath)
22+
public FileInfo(string fullPath, bool directoryCheck = true)
2323
{
2424
OriginalFullPath = fullPath;
2525
ChangedFilename = OriginalFilename;
2626
ChangedPath = OriginalPath;
27-
IsDirectory = File.GetAttributes(fullPath).HasFlag(FileAttributes.Directory);
27+
IsDirectory = directoryCheck && File.GetAttributes(fullPath).HasFlag(FileAttributes.Directory);
2828
}
2929

3030
public FileInfo(FileInfo file)
@@ -273,6 +273,12 @@ public bool Copy(bool overwrite, out ErrorCode errorMessage)
273273
return false;
274274
}
275275

276+
public void Reset()
277+
{
278+
ChangedFilename = OriginalFilename;
279+
ChangedPath = OriginalPath;
280+
}
281+
276282
public void Changed()
277283
{
278284
OriginalFullPath = ChangedFullPath;
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
12+
<DefineConstants>TRACE;UNIT_TEST</DefineConstants>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
16+
<DefineConstants>TRACE;UNIT_TEST</DefineConstants>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
21+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
22+
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
23+
<PackageReference Include="coverlet.collector" Version="3.1.2" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<ProjectReference Include="..\DaramRenamer.Commands\DaramRenamer.Commands.csproj" />
28+
</ItemGroup>
29+
30+
</Project>

DaramRenamer.Test/FilenameUnitTest.cs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Diagnostics;
2+
using DaramRenamer.Commands.Filename;
3+
4+
namespace DaramRenamer.Test;
5+
6+
[TestClass]
7+
public class FilenameUnitTest
8+
{
9+
[TestMethod]
10+
public void ReplacePlainCommandTest()
11+
{
12+
var testFile1 = TestUtil.MakeFileInfo(@"C:\PathA.txt");
13+
14+
var command1 = new ReplacePlainCommand
15+
{
16+
Find = "a",
17+
Replace = "b",
18+
IncludeExtension = false
19+
};
20+
command1.DoCommand(testFile1);
21+
22+
Assert.IsTrue(testFile1.ChangedFilename == "PbthA.txt");
23+
24+
testFile1.Reset();
25+
26+
var command2 = new ReplacePlainCommand
27+
{
28+
Find = "t",
29+
Replace = "r",
30+
IncludeExtension = true
31+
};
32+
command2.DoCommand(testFile1);
33+
34+
Assert.IsTrue(testFile1.ChangedFilename == "ParhA.rxr");
35+
}
36+
37+
[TestMethod]
38+
public void SubstringCommand()
39+
{
40+
var testFile1 = TestUtil.MakeFileInfo(@"C:\Path.txt");
41+
var testFile2 = TestUtil.MakeFileInfo(@"C:\Finder.txt");
42+
43+
var command1 = new SubstringCommand
44+
{
45+
StartIndex = 2,
46+
Length = 3,
47+
IncludeExtension = false
48+
};
49+
50+
command1.DoCommand(testFile1, testFile2);
51+
52+
Debug.Write(testFile1.ChangedFilename);
53+
Assert.IsTrue(testFile1.ChangedFilename == "th.txt");
54+
55+
Debug.Write(testFile2.ChangedFilename);
56+
Assert.IsTrue(testFile2.ChangedFilename == "nde.txt");
57+
}
58+
}

DaramRenamer.Test/TestUtil.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace DaramRenamer.Test;
2+
3+
public static class TestUtil
4+
{
5+
public static FileInfo MakeFileInfo(string fullPath)
6+
{
7+
return new FileInfo(fullPath, directoryCheck: false);
8+
}
9+
10+
public static void DoCommand(this ICommand command, params FileInfo[] fileInfos)
11+
{
12+
foreach (var fileInfo in fileInfos)
13+
command.DoCommand(fileInfo);
14+
}
15+
}

DaramRenamer.Test/Usings.cs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using Microsoft.VisualStudio.TestTools.UnitTesting;

DaramRenamer.sln

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Daramee.Nargs.Shared", "Mod
2525
EndProject
2626
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Blockar.Shared", "Modules\Blockar\Blockar.Shared\Blockar.Shared.shproj", "{24EDA730-617F-409E-BA4A-336B44151438}"
2727
EndProject
28+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{4D30F868-9628-4903-888A-A79D4911E222}"
29+
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaramRenamer.Test", "DaramRenamer.Test\DaramRenamer.Test.csproj", "{DE09BB4A-C41C-4461-97E2-8BB94B15469D}"
31+
EndProject
2832
Global
2933
GlobalSection(SharedMSBuildProjectFiles) = preSolution
3034
Modules\Winston\Daramee.Winston.Shared\Daramee.Winston.Shared.projitems*{07d3172f-ff1f-4e6f-aebe-3e725904b2a7}*SharedItemsImports = 13
@@ -50,6 +54,10 @@ Global
5054
{9129A4F6-59F4-41EC-A03F-D41251CF2795}.Debug|Any CPU.Build.0 = Debug|Any CPU
5155
{9129A4F6-59F4-41EC-A03F-D41251CF2795}.Release|Any CPU.ActiveCfg = Release|Any CPU
5256
{9129A4F6-59F4-41EC-A03F-D41251CF2795}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{DE09BB4A-C41C-4461-97E2-8BB94B15469D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{DE09BB4A-C41C-4461-97E2-8BB94B15469D}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{DE09BB4A-C41C-4461-97E2-8BB94B15469D}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{DE09BB4A-C41C-4461-97E2-8BB94B15469D}.Release|Any CPU.Build.0 = Release|Any CPU
5361
EndGlobalSection
5462
GlobalSection(SolutionProperties) = preSolution
5563
HideSolutionNode = FALSE
@@ -62,6 +70,7 @@ Global
6270
{07D3172F-FF1F-4E6F-AEBE-3E725904B2A7} = {BF174B15-5C72-4E5C-8AA4-EF11C3DC6EFF}
6371
{E13FAA4A-99BD-4A4D-8A1C-C1D3260278CD} = {BF174B15-5C72-4E5C-8AA4-EF11C3DC6EFF}
6472
{24EDA730-617F-409E-BA4A-336B44151438} = {BF174B15-5C72-4E5C-8AA4-EF11C3DC6EFF}
73+
{DE09BB4A-C41C-4461-97E2-8BB94B15469D} = {4D30F868-9628-4903-888A-A79D4911E222}
6574
EndGlobalSection
6675
GlobalSection(ExtensibilityGlobals) = postSolution
6776
SolutionGuid = {B986277B-4442-49A5-BDBE-5598D87D628C}

0 commit comments

Comments
 (0)