-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set the temp file extension based on the content type (#208)
* Set the temp file extension based on the content type * Making RealFileSystem public so we can remove an IVT; adding another content type for json * Modifying RealFileSystem's GetTempFileName implementation to always require an extension; pass in .tmp if we can't find a more appropriate one. Also moved a couple integration tests to be unit tests now that there was no file system dependency. * Fixing a namespace and making a public class internal again * Changing RealFileSystem to disallow period-only extensions. Adding tests for the failure conditions, renaming the success conditions
- Loading branch information
Showing
8 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/Microsoft.HttpRepl.Tests/FileSystem/RealFileSystemTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
using Microsoft.HttpRepl.FileSystem; | ||
using Xunit; | ||
|
||
namespace Microsoft.HttpRepl.Tests.FileSystem | ||
{ | ||
public class RealFileSystemTests | ||
{ | ||
[Theory] | ||
[InlineData(".json")] | ||
[InlineData(".xml")] | ||
[InlineData(".tmp")] | ||
[InlineData(".a")] | ||
public void GetTempFileName_WithValidInput_ReturnsFileNameWithExtension(string extension) | ||
{ | ||
RealFileSystem realFileSystem = new RealFileSystem(); | ||
|
||
string fullName = realFileSystem.GetTempFileName(extension); | ||
|
||
Assert.NotNull(fullName); | ||
Assert.EndsWith(extension, fullName, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
[Theory] | ||
[InlineData(".json")] | ||
[InlineData(".xml")] | ||
[InlineData(".tmp")] | ||
[InlineData(".a")] | ||
public void GetTempFileName_WithValidInput_ReturnsFileInTempPath(string extension) | ||
{ | ||
RealFileSystem realFileSystem = new RealFileSystem(); | ||
string expectedPath = Path.GetTempPath(); | ||
|
||
string actualPath = realFileSystem.GetTempFileName(extension); | ||
|
||
Assert.StartsWith(expectedPath, actualPath, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
[Theory] | ||
[InlineData(".json")] | ||
[InlineData(".xml")] | ||
[InlineData(".tmp")] | ||
[InlineData(".a")] | ||
public void GetTempFileName_WithValidInput_ReturnsFileThatStartsWithHttpRepl(string extension) | ||
{ | ||
RealFileSystem realFileSystem = new RealFileSystem(); | ||
string expectedStart = "HttpRepl."; | ||
|
||
string fullName = realFileSystem.GetTempFileName(extension); | ||
string actualFileName = Path.GetFileName(fullName); | ||
|
||
Assert.StartsWith(expectedStart, actualFileName, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
[Fact] | ||
public void GetTempFileName_WithNullExtension_ThrowsArgumentNullException() | ||
{ | ||
RealFileSystem realFileSystem = new RealFileSystem(); | ||
|
||
Assert.Throws<ArgumentNullException>(() => realFileSystem.GetTempFileName(null)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData(".")] | ||
[InlineData(",a")] | ||
public void GetTEmpFileName_WithInvalidInput_ThrowsArgumentException(string extension) | ||
{ | ||
RealFileSystem realFileSystem = new RealFileSystem(); | ||
|
||
Assert.Throws<ArgumentException>(() => realFileSystem.GetTempFileName(extension)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters