public static string GetTempFilePath(this PathAbstractions path, string extension) { if (path == null) { throw new ArgumentNullException(nameof(path)); } var tempDirectory = path.GetTempPath(); var tempName = Path.GetFileNameWithoutExtension(path.GetTempFileName()); var tempFileName = Path.ChangeExtension(tempName, extension); return(Path.Combine(tempDirectory, tempName, tempFileName)); }
public void GetTempFilePathShouldThrowArgumentExceptionWhenArgumentsAreInvalid( string expectedParameterName, string expectedMessage, Type expectedType, PathBase path, string extension) { Action getTempFilePath = () => path.GetTempFilePath(extension); getTempFilePath.ShouldThrow <ArgumentException>() .WithMessage(expectedMessage) .Where( exception => exception.ParamName == expectedParameterName, "the parameter name should be of the problematic parameter") .And.Should() .BeOfType(expectedType); }