Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use location instead of codebase #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions DocsByReflection.UnitTests/PathHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,24 @@ public void GetAssemblyDocFileNameFromCodeBase_NullOrEmpty_Exception()
{
Assert.Throws<ArgumentNullException>(() =>
{
PathHelper.GetAssemblyDocFileNameFromCodeBase(null);
PathHelper.GetAssemblyDocFileNameFromLocation(null);
});

Assert.Throws<ArgumentNullException>(() =>
{
PathHelper.GetAssemblyDocFileNameFromCodeBase("");
PathHelper.GetAssemblyDocFileNameFromLocation("");
});
}

[Test()]
public void GetAssemblyDocFileNameFromCodeBase_DoesNotStartWithPrefix_Exception()
{
Assert.Throws<DocsByReflectionException>(() =>
{
PathHelper.GetAssemblyDocFileNameFromCodeBase("file://notExists");
}, "Could not ascertain assembly filename from assembly code base 'file://notExists'.");
}

[Test()]
public void GetAssemblyDocFileNameFromCodeBase_RightCodeBase_DocFileName()
{
var actual = PathHelper.GetAssemblyDocFileNameFromCodeBase("file:///Users/giacomelli/Dropbox/jogosdaqui/Plataforma/src/jogosdaqui.WebApi/Bin/jogosdaqui.WebApi.dll");
var actual = PathHelper.GetAssemblyDocFileNameFromLocation("c:/Users/giacomelli/Dropbox/jogosdaqui/Plataforma/src/jogosdaqui.WebApi/Bin/jogosdaqui.WebApi.dll");

if (Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix)
{
Assert.AreEqual("/Users/giacomelli/Dropbox/jogosdaqui/Plataforma/src/jogosdaqui.WebApi/Bin/jogosdaqui.WebApi.xml", actual);
}
else
{
Assert.AreEqual("Users/giacomelli/Dropbox/jogosdaqui/Plataforma/src/jogosdaqui.WebApi/Bin/jogosdaqui.WebApi.xml", actual);
}
Assert.AreEqual(
"c:/Users/giacomelli/Dropbox/jogosdaqui/Plataforma/src/jogosdaqui.WebApi/Bin/jogosdaqui.WebApi.xml",
actual
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion DocsByReflection/DocsAssemblyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static XmlDocument GetXmlFromAssembly(Assembly assembly, bool throwError
/// <returns>The XML document</returns>
private static XmlDocument GetXmlFromAssemblyNonCached(Assembly assembly)
{
string filePath = PathHelper.GetAssemblyDocFileNameFromCodeBase(assembly.CodeBase);
string filePath = PathHelper.GetAssemblyDocFileNameFromLocation(assembly.Location);

try
{
Expand Down
34 changes: 10 additions & 24 deletions DocsByReflection/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,19 @@ namespace DocsByReflection
/// </summary>
public static class PathHelper
{
#region Methods
/// <summary>
/// Gets the assembly document file name from code base.
/// </summary>
/// <returns>The assembly document file name from code base.</returns>
/// <param name="assemblyCodeBase">Assemby code base.</param>
public static string GetAssemblyDocFileNameFromCodeBase(string assemblyCodeBase)
#region Methods
/// <summary>
/// Gets the assembly document file name from location.
/// </summary>
/// <returns>The assembly document file name from location.</returns>
/// <param name="assemblyLocation">Assemby location.</param>
public static string GetAssemblyDocFileNameFromLocation(string assemblyLocation)
{
if (string.IsNullOrWhiteSpace (assemblyCodeBase)) {
throw new ArgumentNullException ("assemblyCodeBase");
if (string.IsNullOrWhiteSpace (assemblyLocation)) {
throw new ArgumentNullException (nameof(assemblyLocation));
}

var prefix = "file:///";

if (assemblyCodeBase.StartsWith (prefix, StringComparison.OrdinalIgnoreCase)) {
var filePath = assemblyCodeBase.Substring (prefix.Length);

if (Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix) {
filePath = "/" + filePath;
}

return Path.ChangeExtension (filePath, ".xml");
}
else
{
throw new DocsByReflectionException(string.Format("Could not ascertain assembly filename from assembly code base '{0}'.", assemblyCodeBase));
}
return Path.ChangeExtension (assemblyLocation, ".xml");
}
#endregion
}
Expand Down