Skip to content

Commit 5d49e51

Browse files
authored
Merge pull request #38 from linked-data-dotnet/feature/travis
Add Travis build
2 parents d601cdf + d85e877 commit 5d49e51

File tree

8 files changed

+68
-8
lines changed

8 files changed

+68
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ build/
3131
# MSTest test Results
3232
[Tt]est[Rr]esult*/
3333
[Bb]uild[Ll]og.*
34+
*opencover.xml
3435

3536
*_i.c
3637
*_p.c

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: csharp
2+
mono: none
3+
env:
4+
global:
5+
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
6+
- DOTNET_CLI_TELEMETRY_OPTOUT=1
7+
- secure: LyfZri+LDXaez/OqC/JU+HMNQeDebmf+SYPZUOGDtWeYBWsYdpsIuhQj5PgfV5aNwSMeefxjFPk/27Cw8D7M7SDcIavBoZbP5fCBqGr9FQKRWkDizaKqP1Mnmu5bFCCr7+7jgTueFk2NZ60rj6vJsmmDtIrMoGF07RzqPySgfLM=
8+
dotnet: 2.1.401
9+
install:
10+
- dotnet restore
11+
script:
12+
- dotnet test -c Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[JsonLD.Test*]*"
13+
after_success:
14+
- bash <(curl -s https://codecov.io/bash)

Directory.Build.targets

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<Target Name="VSTestIfTestProject">
3+
<CallTarget Targets="VSTest" Condition="'$(IsTestProject)' == 'true'" />
4+
</Target>
5+
</Project>

after.JsonLD.sln.targets

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<Target Name="VSTest">
3+
<MSBuild Projects="@(ProjectReference)" Targets="VSTestIfTestProject" />
4+
</Target>
5+
</Project>

src/json-ld.net/Core/DocumentLoader.cs

+29-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ public virtual RemoteDocument LoadDocument(string url)
1616
{
1717
#if !PORTABLE && !IS_CORECLR
1818
RemoteDocument doc = new RemoteDocument(url, null);
19+
HttpWebResponse resp;
20+
1921
try
2022
{
2123
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
2224
req.Accept = AcceptHeader;
23-
WebResponse resp = req.GetResponse();
25+
resp = (HttpWebResponse)req.GetResponse();
2426
bool isJsonld = resp.Headers[HttpResponseHeader.ContentType] == "application/ld+json";
2527
if (!resp.Headers[HttpResponseHeader.ContentType].Contains("json"))
2628
{
@@ -31,7 +33,7 @@ public virtual RemoteDocument LoadDocument(string url)
3133
if (!isJsonld && linkHeaders != null)
3234
{
3335
linkHeaders = linkHeaders.SelectMany((h) => h.Split(",".ToCharArray()))
34-
.Select(h => h.Trim()).ToArray();
36+
.Select(h => h.Trim()).ToArray();
3537
IEnumerable<string> linkedContexts = linkHeaders.Where(v => v.EndsWith("rel=\"http://www.w3.org/ns/json-ld#context\""));
3638
if (linkedContexts.Count() > 1)
3739
{
@@ -54,9 +56,32 @@ public virtual RemoteDocument LoadDocument(string url)
5456
{
5557
throw;
5658
}
57-
catch (Exception)
59+
catch (WebException webException)
60+
{
61+
try
62+
{
63+
resp = (HttpWebResponse)webException.Response;
64+
int baseStatusCode = (int)(Math.Floor((double)resp.StatusCode / 100)) * 100;
65+
if (baseStatusCode == 300)
66+
{
67+
string location = resp.Headers[HttpResponseHeader.Location];
68+
if (!string.IsNullOrWhiteSpace(location))
69+
{
70+
// TODO: Add recursion break or simply switch to HttpClient so we don't have to recurse on HTTP redirects.
71+
return LoadDocument(location);
72+
}
73+
}
74+
}
75+
catch (Exception innerException)
76+
{
77+
throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url, innerException);
78+
}
79+
80+
throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url, webException);
81+
}
82+
catch (Exception exception)
5883
{
59-
throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url);
84+
throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url, exception);
6085
}
6186
return doc;
6287
#else

src/json-ld.net/Core/JsonLdError.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ public class JsonLdError : Exception
1111
private JsonLdError.Error type;
1212
internal JObject details = null;
1313

14-
public JsonLdError(JsonLdError.Error type, object detail) : base(detail == null ?
15-
string.Empty : detail.ToString())
14+
public JsonLdError(JsonLdError.Error type, object detail, Exception innerException)
15+
: base(detail == null ? string.Empty : detail.ToString(), innerException)
1616
{
1717
// TODO: pretty toString (e.g. print whole json objects)
1818
this.type = type;
1919
}
2020

21-
public JsonLdError(JsonLdError.Error type) : base(string.Empty)
21+
public JsonLdError(JsonLdError.Error type, object detail)
22+
: base(detail == null ? string.Empty : detail.ToString())
23+
{
24+
// TODO: pretty toString (e.g. print whole json objects)
25+
this.type = type;
26+
}
27+
28+
public JsonLdError(JsonLdError.Error type)
29+
: base(string.Empty)
2230
{
2331
this.type = type;
2432
}

src/json-ld.net/json-ld.net.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Implements the W3C JSON-LD 1.0 standard.</Description>
66
<VersionPrefix>1.0.6</VersionPrefix>
77
<Authors>NuGet;linked-data-dotnet</Authors>
8-
<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>
8+
<TargetFrameworks>netstandard1.3;netstandard2.0;netcoreapp2.1</TargetFrameworks>
99
<AssemblyName>json-ld.net</AssemblyName>
1010
<PackageId>json-ld.net</PackageId>
1111
<PackageTags>json-ld;jsonld;json;linked-data;rdf;semantic;web</PackageTags>

test/json-ld.net.tests/json-ld.net.tests.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
77
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
88
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
9+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
910
</PropertyGroup>
1011

1112
<ItemGroup>
@@ -19,6 +20,7 @@
1920
</ItemGroup>
2021

2122
<ItemGroup>
23+
<PackageReference Include="coverlet.msbuild" Version="2.3.1" />
2224
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
2325
<PackageReference Include="xunit" Version="2.3.1" />
2426
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />

0 commit comments

Comments
 (0)