Skip to content

Commit

Permalink
Add management of partial url
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric L. Charlier committed Jul 11, 2016
1 parent 0e87dcd commit 2b61c30
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
67 changes: 67 additions & 0 deletions SsrsDeploy.Testing/ProgramTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SsrsDeploy.Testing
{
[TestFixture]
public class ProgramTest
{
[Test]
public void GetUrl_FullName()
{
var options = new Options() { Url = "http://reporting.company.com/ReportServer/ReportService2010.asmx" };
var url = Program.GetUrl(options);

Assert.That(url, Is.EqualTo("http://reporting.company.com/ReportServer/ReportService2010.asmx"));
}

[Test]
public void GetUrl_Host()
{
var options = new Options() { Url = "reporting.company.com" };
var url = Program.GetUrl(options);

Assert.That(url, Is.EqualTo("http://reporting.company.com/ReportServer/ReportService2010.asmx"));
}

[Test]
public void GetUrl_HostPath()
{
var options = new Options() { Url = "reporting.company.com/ReportServer" };
var url = Program.GetUrl(options);

Assert.That(url, Is.EqualTo("http://reporting.company.com/ReportServer/ReportService2010.asmx"));
}

[Test]
public void GetUrl_HostPathSlash()
{
var options = new Options() { Url = "reporting.company.com/ReportServer/" };
var url = Program.GetUrl(options);

Assert.That(url, Is.EqualTo("http://reporting.company.com/ReportServer/ReportService2010.asmx"));
}

[Test]
public void GetUrl_HostPathFile()
{
var options = new Options() { Url = "reporting.company.com/ReportServer/ReportService2010.asmx" };
var url = Program.GetUrl(options);

Assert.That(url, Is.EqualTo("http://reporting.company.com/ReportServer/ReportService2010.asmx"));
}

[Test]
public void GetUrl_SchemeHostPort()
{
var options = new Options() { Url = "http://reporting.company.com:8080" };
var url = Program.GetUrl(options);

Assert.That(url, Is.EqualTo("http://reporting.company.com:8080/ReportServer/ReportService2010.asmx"));
}
}
}
1 change: 1 addition & 0 deletions SsrsDeploy.Testing/SsrsDeploy.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="Parser\Xml\DataSourceParserTest.cs" />
<Compile Include="Parser\Xml\FolderParserTest.cs" />
<Compile Include="Parser\Xml\ReportParserTest.cs" />
<Compile Include="ProgramTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion SsrsDeploy/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace SsrsDeploy
{
class Options
public class Options
{
[Option('u', "url", Required = true,
HelpText = "Url of the webservice where to deploy the reports.")]
Expand Down
27 changes: 25 additions & 2 deletions SsrsDeploy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace SsrsDeploy
{
class Program
public class Program
{
static int Main(string[] args)
{
Expand All @@ -23,7 +23,7 @@ static int Main(string[] args)
var argsValue = ((Parsed<Options>)result).Value;

var rs = new ReportingService.ReportingService2010();
rs.Url = argsValue.Url;
rs.Url = GetUrl(argsValue);
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

var rootPath = argsValue.Root ?? Path.GetDirectoryName(argsValue.Source);
Expand All @@ -38,5 +38,28 @@ static int Main(string[] args)

return exitCode;
}

public static string GetUrl(Options options)
{
var baseUrl = options.Url;
var builder = new UriBuilder(baseUrl);

if (string.IsNullOrEmpty(builder.Scheme))
builder.Scheme = Uri.UriSchemeHttp;

if (builder.Scheme != Uri.UriSchemeHttp && builder.Scheme != Uri.UriSchemeHttps)
throw new ArgumentException();

if (!builder.Path.EndsWith("/ReportService2010.asmx"))
builder.Path += (builder.Path.EndsWith("/") ? "" : "/") + "ReportService2010.asmx";

if (builder.Path.Equals("/ReportService2010.asmx"))
builder.Path = "/ReportServer" + builder.Path;

if (builder.Uri.IsDefaultPort)
return builder.Uri.GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Port, UriFormat.UriEscaped);

return builder.ToString();
}
}
}

0 comments on commit 2b61c30

Please sign in to comment.