GetStandardizedExtension unit tests
This commit is contained in:
parent
68da9779da
commit
b42ff827d5
@ -18,13 +18,13 @@ namespace FileLiberator
|
|||||||
public string MultipartFilename(string outputFileName, int partsPosition, int partsTotal, AAXClean.NewSplitCallback newSplitCallback)
|
public string MultipartFilename(string outputFileName, int partsPosition, int partsTotal, AAXClean.NewSplitCallback newSplitCallback)
|
||||||
{
|
{
|
||||||
var extension = Path.GetExtension(outputFileName);
|
var extension = Path.GetExtension(outputFileName);
|
||||||
var baseFileName = AudioFileStorageExt.GetValidFilename(AudibleFileStorage.DecryptInProgressDirectory, LibraryBook.Book.Title, extension, LibraryBook);
|
var baseFileName = GetValidFilename(AudibleFileStorage.DecryptInProgressDirectory, LibraryBook.Book.Title, extension, LibraryBook);
|
||||||
|
|
||||||
var template = Path.ChangeExtension(baseFileName, null) + " - <chapter> - <title>" + extension;
|
var template = Path.ChangeExtension(baseFileName, null) + " - <chapter number> - <chapter title>" + extension;
|
||||||
|
|
||||||
var fileTemplate = new FileTemplate(template) { IllegalCharacterReplacements = " " };
|
var fileTemplate = new FileTemplate(template) { IllegalCharacterReplacements = " " };
|
||||||
fileTemplate.AddParameterReplacement("chapter", FileUtility.GetSequenceFormatted(partsPosition, partsTotal));
|
fileTemplate.AddParameterReplacement("chapter number", FileUtility.GetSequenceFormatted(partsPosition, partsTotal));
|
||||||
fileTemplate.AddParameterReplacement("title", newSplitCallback?.Chapter?.Title ?? "");
|
fileTemplate.AddParameterReplacement("chapter title", newSplitCallback?.Chapter?.Title ?? "");
|
||||||
|
|
||||||
return fileTemplate.GetFilePath();
|
return fileTemplate.GetFilePath();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace FileManager
|
|||||||
public static string GetStandardizedExtension(string extension)
|
public static string GetStandardizedExtension(string extension)
|
||||||
=> string.IsNullOrWhiteSpace(extension)
|
=> string.IsNullOrWhiteSpace(extension)
|
||||||
? (extension ?? "")?.Trim()
|
? (extension ?? "")?.Trim()
|
||||||
: '.' + extension.Trim('.');
|
: '.' + extension.Trim().Trim('.');
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return position with correct number of leading zeros.
|
/// Return position with correct number of leading zeros.
|
||||||
|
|||||||
@ -90,4 +90,24 @@ namespace FileUtilityTests
|
|||||||
public void Tests(int partsPosition, int partsTotal, string expected)
|
public void Tests(int partsPosition, int partsTotal, string expected)
|
||||||
=> FileUtility.GetSequenceFormatted(partsPosition, partsTotal).Should().Be(expected);
|
=> FileUtility.GetSequenceFormatted(partsPosition, partsTotal).Should().Be(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class GetStandardizedExtension
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void is_null() => Tests(null, "");
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void is_empty() => Tests("", "");
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void is_whitespace() => Tests(" ", "");
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("txt", ".txt")]
|
||||||
|
[DataRow(".txt", ".txt")]
|
||||||
|
[DataRow(" .txt ", ".txt")]
|
||||||
|
public void Tests(string input, string expected)
|
||||||
|
=> FileUtility.GetStandardizedExtension(input).Should().Be(expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user