Skip to content

Commit

Permalink
Fix 'innerhandler is null' in refreshTokenHandler + add test in .NET …
Browse files Browse the repository at this point in the history
…Core 2.2
  • Loading branch information
Tim Stuyckens committed Jan 25, 2019
1 parent acadda4 commit a8c13e1
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Viren.Core/Authentication/RefreshTokenHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class RefreshTokenHandler : DelegatingHandler
{
private readonly AccessTokenCache _accessTokenCache;

public RefreshTokenHandler(AccessTokenCache accessTokenCache)
public RefreshTokenHandler(AccessTokenCache accessTokenCache): base(new HttpClientHandler())
{
_accessTokenCache = accessTokenCache;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Viren.Core/Viren.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>0.5.4</Version>
<Version>0.5.5</Version>
<Authors>Teal Partners</Authors>
<Company>Teal Partners</Company>
<Product>Viren .NET client core library</Product>
Expand All @@ -16,6 +15,7 @@
<RepositoryUrl>https://github.com/tealpartners/viren.net</RepositoryUrl>
<PackageTags>Viren; API; Client</PackageTags>
<ApplicationIcon>icon.ico</ApplicationIcon>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>0.5.4</Version>
<Version>0.5.5</Version>
<Authors>Teal Partners</Authors>
<Product>Viren execution .NET client</Product>
<RepositoryUrl>https://github.com/tealpartners/viren.net</RepositoryUrl>
Expand All @@ -19,6 +18,7 @@
<AssemblyOriginatorKeyFile>VirenExecutionKey.pfx</AssemblyOriginatorKeyFile>
<AssemblyName>Viren.Execution.Extensions.DependencyInjection</AssemblyName>
<RootNamespace>Viren.Execution.Extensions.DependencyInjection</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
Expand Down
4 changes: 2 additions & 2 deletions src/Viren.Execution/Viren.Execution.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>0.5.4</Version>
<Version>0.5.5</Version>
<Authors>Teal Partners</Authors>
<Product>Viren execution .NET client</Product>
<RepositoryUrl>https://github.com/tealpartners/viren.net</RepositoryUrl>
Expand All @@ -19,6 +18,7 @@
<AssemblyOriginatorKeyFile>VirenExecutionKey.pfx</AssemblyOriginatorKeyFile>
<AssemblyName>Viren.Execution</AssemblyName>
<RootNamespace>Viren.Execution</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Viren.Core\Viren.Core.csproj" />
Expand Down
67 changes: 67 additions & 0 deletions src/Viren.Tests/SimpleTestCall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using Microsoft.Extensions.Configuration;
using Viren.Execution;
using Xunit;

namespace Viren.Tests
{
public class TestSettings
{
public string apiHostName { get; set; }
public string auth0Domain { get; set; }
public string auth0TestsClientId { get; set; }
public string auth0TestsClientSecret { get; set; }

public override string ToString()
{
return $"{apiHostName} {auth0Domain} {auth0TestsClientId} {auth0TestsClientSecret}";
}
}

public class SimpleTestCall
{

private TestSettings _testSettings;

public SimpleTestCall()
{
//https://xunit.github.io/docs/comparisons
// We believe that use of [SetUp] is generally bad. However, you can implement a parameterless constructor as a direct replacement. See Note 2

var config=new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.Build();

_testSettings = new TestSettings();

config
.GetSection("AppSettings")
.Bind(_testSettings);
}

[Fact]
public async void ModelGetVersion()
{
Console.WriteLine(_testSettings);
var apiHostName = _testSettings.apiHostName; // "http://dev.calc-exec.be/" ;

var auth0Domain = _testSettings.auth0Domain;// "https://teal-calculation-dev.eu.auth0.com";
var auth0TestsClientId= _testSettings.auth0TestsClientId; // "Hekmz983EKNcZTh5kETQqChZtUnuDXwe";
var auth0TestsClientSecret = _testSettings.auth0TestsClientSecret; // "9TPXNqylBXydE2H20QFxQc6lGy6MShk9nAxsr8LwH6E-klpLyNzPgoRcrPGSRGm5";


var httpClient = VirenHttpClientFactory.Create(auth0TestsClientId, auth0TestsClientSecret, apiHostName,auth0Domain);
var client = new ExecutionClient(httpClient);

try
{
var version = await client.Model.GetVersion("TestProject", "TestModel",false);
Assert.NotNull(version);
}
catch (Exception e) when (e.Message.Contains("you don't have enough rights you need to have"))
{
Assert.True(true); //rechten issue, maar API call is gelukt
}
}
}
}
35 changes: 35 additions & 0 deletions src/Viren.Tests/Viren.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Viren.Core\Viren.Core.csproj" />
<ProjectReference Include="..\Viren.Execution\Viren.Execution.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.Extensions.Configuration, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<HintPath>..\..\..\..\Users\Tim\.nuget\packages\microsoft.extensions.configuration\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions src/Viren.Tests/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"AppSettings": {
"apiHostName": "https://teal-calculation-execution-develop.azurewebsites.net/",
"auth0Domain": "https://teal-calculation-test.eu.auth0.com",
"auth0TestsClientId": "NWEkzBg4OBSzbEWya3avWCs2QP3S3M6D",
"auth0TestsClientSecret": "8C_7ej-Ca22qGkLGVYdw92ENZjKKD9IgcS-Vl0tB2OtuCvFBlgW4SeiMqNlwdBbq"
}
}
6 changes: 6 additions & 0 deletions src/viren.net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Viren.Execution.Extensions.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Viren.Core", "Viren.Core\Viren.Core.csproj", "{22120959-586C-4EA7-A76A-ECB5F5756B3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Viren.Tests", "Viren.Tests\Viren.Tests.csproj", "{4640630A-13E1-46B0-A789-A5B0DA41828C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{22120959-586C-4EA7-A76A-ECB5F5756B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22120959-586C-4EA7-A76A-ECB5F5756B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22120959-586C-4EA7-A76A-ECB5F5756B3F}.Release|Any CPU.Build.0 = Release|Any CPU
{4640630A-13E1-46B0-A789-A5B0DA41828C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4640630A-13E1-46B0-A789-A5B0DA41828C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4640630A-13E1-46B0-A789-A5B0DA41828C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4640630A-13E1-46B0-A789-A5B0DA41828C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit a8c13e1

Please sign in to comment.