Skip to content

Commit

Permalink
유닛테스트 추가 (1)
Browse files Browse the repository at this point in the history
- 파일명 치환
- 하위문자열
  • Loading branch information
daramkun committed Jun 10, 2022
1 parent d73217a commit 14a4095
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 2 deletions.
10 changes: 8 additions & 2 deletions DaramRenamer.Commands/FileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class FileInfo : IComparable<FileInfo>, INotifyPropertyChanged

private string _originalFullPath;

public FileInfo(string fullPath)
public FileInfo(string fullPath, bool directoryCheck = true)
{
OriginalFullPath = fullPath;
ChangedFilename = OriginalFilename;
ChangedPath = OriginalPath;
IsDirectory = File.GetAttributes(fullPath).HasFlag(FileAttributes.Directory);
IsDirectory = directoryCheck && File.GetAttributes(fullPath).HasFlag(FileAttributes.Directory);
}

public FileInfo(FileInfo file)
Expand Down Expand Up @@ -273,6 +273,12 @@ public bool Copy(bool overwrite, out ErrorCode errorMessage)
return false;
}

public void Reset()
{
ChangedFilename = OriginalFilename;
ChangedPath = OriginalPath;
}

public void Changed()
{
OriginalFullPath = ChangedFullPath;
Expand Down
30 changes: 30 additions & 0 deletions DaramRenamer.Test/DaramRenamer.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;UNIT_TEST</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE;UNIT_TEST</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DaramRenamer.Commands\DaramRenamer.Commands.csproj" />
</ItemGroup>

</Project>
58 changes: 58 additions & 0 deletions DaramRenamer.Test/FilenameUnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Diagnostics;
using DaramRenamer.Commands.Filename;

namespace DaramRenamer.Test;

[TestClass]
public class FilenameUnitTest
{
[TestMethod]
public void ReplacePlainCommandTest()
{
var testFile1 = TestUtil.MakeFileInfo(@"C:\PathA.txt");

var command1 = new ReplacePlainCommand
{
Find = "a",
Replace = "b",
IncludeExtension = false
};
command1.DoCommand(testFile1);

Assert.IsTrue(testFile1.ChangedFilename == "PbthA.txt");

testFile1.Reset();

var command2 = new ReplacePlainCommand
{
Find = "t",
Replace = "r",
IncludeExtension = true
};
command2.DoCommand(testFile1);

Assert.IsTrue(testFile1.ChangedFilename == "ParhA.rxr");
}

[TestMethod]
public void SubstringCommand()
{
var testFile1 = TestUtil.MakeFileInfo(@"C:\Path.txt");
var testFile2 = TestUtil.MakeFileInfo(@"C:\Finder.txt");

var command1 = new SubstringCommand
{
StartIndex = 2,
Length = 3,
IncludeExtension = false
};

command1.DoCommand(testFile1, testFile2);

Debug.Write(testFile1.ChangedFilename);
Assert.IsTrue(testFile1.ChangedFilename == "th.txt");

Debug.Write(testFile2.ChangedFilename);
Assert.IsTrue(testFile2.ChangedFilename == "nde.txt");
}
}
15 changes: 15 additions & 0 deletions DaramRenamer.Test/TestUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace DaramRenamer.Test;

public static class TestUtil
{
public static FileInfo MakeFileInfo(string fullPath)
{
return new FileInfo(fullPath, directoryCheck: false);
}

public static void DoCommand(this ICommand command, params FileInfo[] fileInfos)
{
foreach (var fileInfo in fileInfos)
command.DoCommand(fileInfo);
}
}
1 change: 1 addition & 0 deletions DaramRenamer.Test/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
9 changes: 9 additions & 0 deletions DaramRenamer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Daramee.Nargs.Shared", "Mod
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Blockar.Shared", "Modules\Blockar\Blockar.Shared\Blockar.Shared.shproj", "{24EDA730-617F-409E-BA4A-336B44151438}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{4D30F868-9628-4903-888A-A79D4911E222}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaramRenamer.Test", "DaramRenamer.Test\DaramRenamer.Test.csproj", "{DE09BB4A-C41C-4461-97E2-8BB94B15469D}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Modules\Winston\Daramee.Winston.Shared\Daramee.Winston.Shared.projitems*{07d3172f-ff1f-4e6f-aebe-3e725904b2a7}*SharedItemsImports = 13
Expand All @@ -50,6 +54,10 @@ Global
{9129A4F6-59F4-41EC-A03F-D41251CF2795}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9129A4F6-59F4-41EC-A03F-D41251CF2795}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9129A4F6-59F4-41EC-A03F-D41251CF2795}.Release|Any CPU.Build.0 = Release|Any CPU
{DE09BB4A-C41C-4461-97E2-8BB94B15469D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE09BB4A-C41C-4461-97E2-8BB94B15469D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE09BB4A-C41C-4461-97E2-8BB94B15469D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE09BB4A-C41C-4461-97E2-8BB94B15469D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -62,6 +70,7 @@ Global
{07D3172F-FF1F-4E6F-AEBE-3E725904B2A7} = {BF174B15-5C72-4E5C-8AA4-EF11C3DC6EFF}
{E13FAA4A-99BD-4A4D-8A1C-C1D3260278CD} = {BF174B15-5C72-4E5C-8AA4-EF11C3DC6EFF}
{24EDA730-617F-409E-BA4A-336B44151438} = {BF174B15-5C72-4E5C-8AA4-EF11C3DC6EFF}
{DE09BB4A-C41C-4461-97E2-8BB94B15469D} = {4D30F868-9628-4903-888A-A79D4911E222}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B986277B-4442-49A5-BDBE-5598D87D628C}
Expand Down

0 comments on commit 14a4095

Please sign in to comment.