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

fix: get CM tests working against OSLC RefImpl #115

Merged
merged 9 commits into from
Jan 31, 2024
Merged
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
11 changes: 7 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ indent_style = space
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80

[*.cs]
indent_size = 4
max_line_length = 100
dotnet_sort_system_directives_first = true

# Don't use this. qualifier
Expand Down Expand Up @@ -231,7 +233,8 @@ dotnet_diagnostic.CA1857.severity = warning
dotnet_diagnostic.CA1858.severity = warning

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = warning
# TODO: reenable
# dotnet_diagnostic.CA2007.severity = warning

# CA2008: Do not create tasks without passing a TaskScheduler
dotnet_diagnostic.CA2008.severity = warning
Expand Down Expand Up @@ -323,8 +326,8 @@ dotnet_diagnostic.IDE0060.severity = warning
dotnet_diagnostic.IDE0062.severity = warning

# IDE0073: File header
dotnet_diagnostic.IDE0073.severity = warning
file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.
# dotnet_diagnostic.IDE0073.severity = warning
# file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.

# IDE0161: Convert to file-scoped namespace
dotnet_diagnostic.IDE0161.severity = warning
Expand Down Expand Up @@ -457,4 +460,4 @@ dotnet_diagnostic.IDE0161.severity = silent

[{**/Shared/**.cs,**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}]
# IDE0005: Remove unused usings. Ignore for shared src files since imports for those depend on the projects in which they are included.
dotnet_diagnostic.IDE0005.severity = silent
dotnet_diagnostic.IDE0005.severity = silent
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ jobs:
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal --filter TestCategory!=RunningOslcServerRequired
run: dotnet test --no-build --verbosity normal --filter TestCategory!=RunningOslcServerRequired --collect:"OSLC4Net code coverage"
# - name: Set version suffix
# id: version
# run: echo "::set-output name=suffix::$(date +'-ts.%y%m%d%H%M')"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Build and publish NuGet package
shell: pwsh
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*******************************************************************************
* Copyright (c) 2013 IBM Corporation.
* Copyright (c) 2023 Andrii Berezovskyi and OSLC4Net contributors.
* Copyright (c) 2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
Expand Down Expand Up @@ -135,7 +135,7 @@ public string GetRequestToken()
private readonly string consumerKey;
private readonly string consumerSecret;
}

private static HttpMessageHandler OAuthHandler(String requestTokenURL,
String authorizationTokenURL,
String accessTokenURL,
Expand Down Expand Up @@ -170,7 +170,7 @@ private static HttpMessageHandler OAuthHandler(String requestTokenURL,
String location = null;
HttpResponseMessage resp;

try
try
{
client.DefaultRequestHeaders.Clear();

Expand All @@ -196,14 +196,14 @@ private static HttpMessageHandler OAuthHandler(String requestTokenURL,

resp = client.PostAsync(authUrl + "/j_security_check", content).Result;
statusCode = resp.StatusCode;

String jazzAuthMessage = null;
IEnumerable<string> values = new List<string>();

if (resp.Headers.TryGetValues(JAZZ_AUTH_MESSAGE_HEADER, out values)) {
jazzAuthMessage = values.Last();
}

if (jazzAuthMessage != null && String.Compare(jazzAuthMessage, JAZZ_AUTH_FAILED, true) == 0)
{
resp.ConsumeContent();
Expand All @@ -229,7 +229,7 @@ private static HttpMessageHandler OAuthHandler(String requestTokenURL,
{
DesktopConsumer desktopConsumer = new DesktopConsumer(serviceDescription, tokenManager);
AuthorizedTokenResponse authorizedTokenResponse = desktopConsumer.ProcessUserAuthorization(tokenManager.GetRequestToken(), qscoll["oauth_verifier"]);

return consumer.CreateAuthorizingHandler(authorizedTokenResponse.AccessToken, CreateSSLHandler());
}

Expand Down
95 changes: 74 additions & 21 deletions OSLC4Net_SDK/JsonProvider/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,17 +1411,17 @@

return any;
}
else if (jsonValue is string)
else if (jsonValue is string jsonString)
{
// Check if it's in the OSLC date format.
try
{
return DateTime.Parse((string)jsonValue);
return DateTime.Parse(jsonString);
}
catch (FormatException e)

Check warning on line 1421 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 6.x, net6.0)

The variable 'e' is declared but never used

Check warning on line 1421 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 7.x, net7.0)

The variable 'e' is declared but never used

Check warning on line 1421 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (windows-latest, 8.x, net8.0)

The variable 'e' is declared but never used

Check warning on line 1421 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (windows-latest, 7.x, net7.0)

The variable 'e' is declared but never used

Check warning on line 1421 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (windows-latest, 6.x, net6.0)

The variable 'e' is declared but never used
{
// It's not a date. Treat it as a string.
return jsonValue;
return jsonString;
}
}

Expand Down Expand Up @@ -1455,7 +1455,7 @@
return false;
}

JsonObject jsonObject = (JsonObject)jsonValue;
var jsonObject = jsonValue as JsonObject;

bool isListNode =
jsonObject.ContainsKey(rdfPrefix + JSON_PROPERTY_DELIMITER + JSON_PROPERTY_SUFFIX_FIRST)
Expand Down Expand Up @@ -1688,59 +1688,112 @@
}
else
{
string stringValue = (string)(JsonValue)jsonValue;
// TODO: JsonPrimitive<JsonValue can be a ready-made boolean
JsonPrimitive jsonPrimitive = jsonValue as JsonPrimitive;
if (jsonPrimitive == null)
{
logger.Warn($"JSON value is not a primitive: '{jsonValue}'");
throw new ArgumentException();
}

if (typeof(string) == setMethodComponentParameterType)
{
return stringValue;
return (string)jsonPrimitive;
}
else if (typeof(bool) == setMethodComponentParameterType || typeof(bool?) == setMethodComponentParameterType)
{
// Cannot use Boolean.parseBoolean since it supports case-insensitive TRUE.
if (bool.TrueString.ToUpper().Equals(stringValue.ToUpper()))
if (jsonPrimitive.JsonType == JsonType.Boolean)
{
return true;
}
else if (bool.FalseString.ToUpper().Equals(stringValue.ToUpper()))
return (bool)jsonPrimitive;
} else if (jsonPrimitive.JsonType == JsonType.String)
{
return false;
var boolString = (string)jsonPrimitive;
// TODO: revisit the decision not to use Boolean.TryParse()
// Cannot use Boolean.parseBoolean since it supports case-insensitive TRUE.
if (bool.TrueString.ToUpper().Equals(boolString.ToUpper()))
{
return true;
}
else if (bool.FalseString.ToUpper().Equals(boolString.ToUpper()))
{
return false;
}
}
else
{
throw new InvalidOperationException("'" + stringValue + "' has wrong format for Boolean.");
throw new ArgumentException($"'{jsonPrimitive}' has wrong format for Boolean.");
}
}
else if (typeof(byte) == setMethodComponentParameterType || typeof(byte?) == setMethodComponentParameterType)
{
return byte.Parse(stringValue);
return byte.Parse(jsonPrimitive);
}
else if (typeof(short) == setMethodComponentParameterType || typeof(short?) == setMethodComponentParameterType)
{
return short.Parse(stringValue);
return short.Parse(jsonPrimitive);
}
else if (typeof(int) == setMethodComponentParameterType || typeof(int?) == setMethodComponentParameterType)
{
return int.Parse(stringValue);
if (jsonPrimitive.JsonType == JsonType.Number)
{
return (int)jsonPrimitive;
}
else
{
return int.Parse((string)jsonPrimitive);
}
}
else if (typeof(long) == setMethodComponentParameterType || typeof(long?) == setMethodComponentParameterType)
{
return long.Parse(stringValue);
if (jsonPrimitive.JsonType == JsonType.Number)
{
return (long)jsonPrimitive;
}
else
{
return long.Parse((string)jsonPrimitive);
}
}
else if (typeof(float) == setMethodComponentParameterType || typeof(float?) == setMethodComponentParameterType)
{
return float.Parse(stringValue);
if (jsonPrimitive.JsonType == JsonType.Number)
{
return (float)jsonPrimitive;
}
else
{
return float.Parse((string)jsonPrimitive);
}
}
else if (typeof(decimal) == setMethodComponentParameterType || typeof(decimal?) == setMethodComponentParameterType)
{
return decimal.Parse(stringValue);
if (jsonPrimitive.JsonType == JsonType.Number)
{
return (decimal)jsonPrimitive;
}
else
{
return decimal.Parse((string)jsonPrimitive);
}
}
else if (typeof(double) == setMethodComponentParameterType || typeof(double?) == setMethodComponentParameterType)
{
return double.Parse(stringValue);
if (jsonPrimitive.JsonType == JsonType.Number)
{
return (double)jsonPrimitive;
}
else
{
return double.Parse((string)jsonPrimitive);
}
}
else if (typeof(DateTime) == setMethodComponentParameterType || typeof(DateTime?) == setMethodComponentParameterType)
{
return DateTime.Parse(stringValue);
if (!DateTime.TryParse(jsonPrimitive, out var parsedDate))
{
logger.Warn($"Cannot parse '{jsonPrimitive}' as a DateTime");
}
return parsedDate;
}
}

Expand Down Expand Up @@ -1808,7 +1861,7 @@
{
}

public void Add(TKey key, TValue value)

Check warning on line 1864 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 6.x, net6.0)

'JsonHelper.DictionaryWithReplacement<TKey, TValue>.Add(TKey, TValue)' hides inherited member 'Dictionary<TKey, TValue>.Add(TKey, TValue)'. Use the new keyword if hiding was intended.

Check warning on line 1864 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 7.x, net7.0)

'JsonHelper.DictionaryWithReplacement<TKey, TValue>.Add(TKey, TValue)' hides inherited member 'Dictionary<TKey, TValue>.Add(TKey, TValue)'. Use the new keyword if hiding was intended.

Check warning on line 1864 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (windows-latest, 8.x, net8.0)

'JsonHelper.DictionaryWithReplacement<TKey, TValue>.Add(TKey, TValue)' hides inherited member 'Dictionary<TKey, TValue>.Add(TKey, TValue)'. Use the new keyword if hiding was intended.

Check warning on line 1864 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (windows-latest, 7.x, net7.0)

'JsonHelper.DictionaryWithReplacement<TKey, TValue>.Add(TKey, TValue)' hides inherited member 'Dictionary<TKey, TValue>.Add(TKey, TValue)'. Use the new keyword if hiding was intended.

Check warning on line 1864 in OSLC4Net_SDK/JsonProvider/JsonHelper.cs

View workflow job for this annotation

GitHub Actions / test (windows-latest, 6.x, net6.0)

'JsonHelper.DictionaryWithReplacement<TKey, TValue>.Add(TKey, TValue)' hides inherited member 'Dictionary<TKey, TValue>.Add(TKey, TValue)'. Use the new keyword if hiding was intended.
{
if (ContainsKey(key))
{
Expand Down
4 changes: 4 additions & 0 deletions OSLC4Net_SDK/JsonProvider/JsonMediaTypeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ IFormatterLogger formatterLogger

try
{
StreamReader sr = new(readStream);
berezovskyi marked this conversation as resolved.
Show resolved Hide resolved
var httpResponseBody = sr.ReadToEnd();
readStream.Position = 0;
Debug.WriteLine("HTTP response body" + httpResponseBody);
JsonObject jsonObject = (JsonObject)JsonObject.Load(readStream);

Debug.WriteLine("JsonMediaTypeFormatter.ReadFromStreamAsync(): Loaded JSON: " + jsonObject?.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="log4net">
<Version>2.0.15</Version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>

</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OSLC4Net.DotNetRdfProvider\OSLC4Net.Core.DotNetRdfProvider.csproj" />
<ProjectReference Include="..\OSLC4Net.ChangeManagement\OSLC4Net.ChangeManagementCommon.csproj" />
<ProjectReference Include="..\OSLC4Net.Client\OSLC4Net.Client.csproj" />
<ProjectReference Include="..\OSLC4Net.Core\OSLC4Net.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="log4net">
<Version>2.0.15</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.Client">
<Version>5.2.9</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter">
<Version>3.2.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>3.2.0</Version>
</PackageReference>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>

</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\JsonProvider\OSLC4Net.Core.JsonProvider.csproj" />
<ProjectReference Include="..\OSLC4Net.DotNetRdfProvider\OSLC4Net.Core.DotNetRdfProvider.csproj" />
<ProjectReference Include="..\OSLC4Net.ChangeManagement\OSLC4Net.ChangeManagementCommon.csproj" />
<ProjectReference Include="..\OSLC4Net.Client\OSLC4Net.Client.csproj" />
<ProjectReference Include="..\OSLC4Net.Core\OSLC4Net.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<None Include="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

This file was deleted.

Loading
Loading