Add test project, create nuget package
This commit is contained in:
parent
bdf3c2b4b6
commit
889a182f0f
6 changed files with 117 additions and 10 deletions
|
|
@ -6,12 +6,11 @@ MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChart", "QuickChart\QuickChart.csproj", "{60C2308A-500A-4DA1-AF8E-671C88696BFA}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChart", "QuickChart\QuickChart.csproj", "{60C2308A-500A-4DA1-AF8E-671C88696BFA}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C076DB54-F991-4386-969E-110648801D22}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C076DB54-F991-4386-969E-110648801D22}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
|
||||||
EmptyClass.cs = EmptyClass.cs
|
|
||||||
EndProjectSection
|
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChartExamples", "QuickChartExamples\QuickChartExamples.csproj", "{52AC08E4-5A20-4A46-A117-BFAC03BB7940}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChartExamples", "QuickChartExamples\QuickChartExamples.csproj", "{52AC08E4-5A20-4A46-A117-BFAC03BB7940}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickChartTest", "QuickChartTest\QuickChartTest.csproj", "{0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
@ -26,6 +25,10 @@ Global
|
||||||
{52AC08E4-5A20-4A46-A117-BFAC03BB7940}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{52AC08E4-5A20-4A46-A117-BFAC03BB7940}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{52AC08E4-5A20-4A46-A117-BFAC03BB7940}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{52AC08E4-5A20-4A46-A117-BFAC03BB7940}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{52AC08E4-5A20-4A46-A117-BFAC03BB7940}.Release|Any CPU.Build.0 = Release|Any CPU
|
{52AC08E4-5A20-4A46-A117-BFAC03BB7940}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0CEF2268-6F2B-4DEB-B152-DDA0B09ABEDA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,10 @@ namespace QuickChart
|
||||||
queryString.Add("devicePixelRatio", DevicePixelRatio.ToString());
|
queryString.Add("devicePixelRatio", DevicePixelRatio.ToString());
|
||||||
queryString.Add("bkg", BackgroundColor);
|
queryString.Add("bkg", BackgroundColor);
|
||||||
queryString.Add("c", Config);
|
queryString.Add("c", Config);
|
||||||
|
if (!string.IsNullOrEmpty(Key))
|
||||||
|
{
|
||||||
|
queryString.Add("key", Key);
|
||||||
|
}
|
||||||
|
|
||||||
return $"{Protocol}://{Host}:{Port}/chart?{queryString}";
|
return $"{Protocol}://{Host}:{Port}/chart?{queryString}";
|
||||||
}
|
}
|
||||||
|
|
@ -67,6 +71,9 @@ namespace QuickChart
|
||||||
throw new NullReferenceException("You must set Config on the QuickChart object before generating a URL");
|
throw new NullReferenceException("You must set Config on the QuickChart object before generating a URL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonSerializerOptions options = new JsonSerializerOptions();
|
||||||
|
options.IgnoreNullValues = true;
|
||||||
|
|
||||||
String json = JsonSerializer.Serialize(new
|
String json = JsonSerializer.Serialize(new
|
||||||
{
|
{
|
||||||
width = Width,
|
width = Width,
|
||||||
|
|
@ -74,9 +81,8 @@ namespace QuickChart
|
||||||
backgroundColor = BackgroundColor,
|
backgroundColor = BackgroundColor,
|
||||||
devicePixelRatio = DevicePixelRatio,
|
devicePixelRatio = DevicePixelRatio,
|
||||||
chart = Config,
|
chart = Config,
|
||||||
});
|
key = Key,
|
||||||
|
}, options);
|
||||||
// TODO(ian): key
|
|
||||||
|
|
||||||
string url = $"{Protocol}://{Host}:{Port}/chart/create";
|
string url = $"{Protocol}://{Host}:{Port}/chart/create";
|
||||||
|
|
||||||
|
|
@ -102,6 +108,9 @@ namespace QuickChart
|
||||||
throw new NullReferenceException("You must set Config on the QuickChart object before generating a URL");
|
throw new NullReferenceException("You must set Config on the QuickChart object before generating a URL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonSerializerOptions options = new JsonSerializerOptions();
|
||||||
|
options.IgnoreNullValues = true;
|
||||||
|
|
||||||
String json = JsonSerializer.Serialize(new
|
String json = JsonSerializer.Serialize(new
|
||||||
{
|
{
|
||||||
width = Width,
|
width = Width,
|
||||||
|
|
@ -109,9 +118,8 @@ namespace QuickChart
|
||||||
backgroundColor = BackgroundColor,
|
backgroundColor = BackgroundColor,
|
||||||
devicePixelRatio = DevicePixelRatio,
|
devicePixelRatio = DevicePixelRatio,
|
||||||
chart = Config,
|
chart = Config,
|
||||||
});
|
key = Key,
|
||||||
|
}, options);
|
||||||
// TODO(ian): key
|
|
||||||
|
|
||||||
string url = $"{Protocol}://{Host}:{Port}/chart";
|
string url = $"{Protocol}://{Host}:{Port}/chart";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,18 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<PackOnBuild>true</PackOnBuild>
|
||||||
|
<Authors>Ian Webster</Authors>
|
||||||
|
<Copyright>Ian Webster 2020</Copyright>
|
||||||
|
<PackageLicenseUrl>https://github.com/typpo/quickchart-csharp/blob/main/LICENSE</PackageLicenseUrl>
|
||||||
|
<Owners>QuickChart</Owners>
|
||||||
|
<PackageProjectUrl>https://github.com/typpo/quickchart-csharp</PackageProjectUrl>
|
||||||
|
<Summary>Client library for the QuickChart Chart API, used to generate chart images.</Summary>
|
||||||
|
<PackageTags>chart image, chart api, chart, charts</PackageTags>
|
||||||
|
<Title>QuickChart</Title>
|
||||||
|
<Description>Client library for the QuickChart Chart API, used to generate chart images.</Description>
|
||||||
|
<PackageVersion>1.0.0</PackageVersion>
|
||||||
|
<PackageId>QuickChart</PackageId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ namespace QuickChartExamples
|
||||||
{
|
{
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
Console.WriteLine("Writing simple URL...");
|
Console.WriteLine("Writing simple URL...");
|
||||||
QuickChart qc = new QuickChart();
|
Chart qc = new Chart();
|
||||||
|
|
||||||
qc.Width = 500;
|
qc.Width = 500;
|
||||||
qc.Height = 300;
|
qc.Height = 300;
|
||||||
|
|
|
||||||
63
QuickChartTest/QuickChartTest.cs
Normal file
63
QuickChartTest/QuickChartTest.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
using QuickChart;
|
||||||
|
|
||||||
|
namespace QuickChartTest
|
||||||
|
{
|
||||||
|
public class QuickChartTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void TestBasic()
|
||||||
|
{
|
||||||
|
Chart qc = new Chart
|
||||||
|
{
|
||||||
|
Width = 500,
|
||||||
|
Height = 300,
|
||||||
|
Config = @"{
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
|
||||||
|
datasets: [{
|
||||||
|
label: 'Users',
|
||||||
|
data: [50, 60, 70, 180]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
};
|
||||||
|
|
||||||
|
string url = qc.GetUrl();
|
||||||
|
Assert.Contains("https://quickchart.io:443/chart", url);
|
||||||
|
Assert.Contains("w=500", url);
|
||||||
|
Assert.Contains("h=300", url);
|
||||||
|
Assert.DoesNotContain("key=", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestWithKey()
|
||||||
|
{
|
||||||
|
Chart qc = new Chart
|
||||||
|
{
|
||||||
|
Key = "abc123",
|
||||||
|
Width = 500,
|
||||||
|
Height = 300,
|
||||||
|
Config = @"{
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
|
||||||
|
datasets: [{
|
||||||
|
label: 'Users',
|
||||||
|
data: [50, 60, 70, 180]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
};
|
||||||
|
|
||||||
|
string url = qc.GetUrl();
|
||||||
|
Assert.Contains("https://quickchart.io:443/chart", url);
|
||||||
|
Assert.Contains("w=500", url);
|
||||||
|
Assert.Contains("h=300", url);
|
||||||
|
Assert.Contains("key=abc123", url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
QuickChartTest/QuickChartTest.csproj
Normal file
21
QuickChartTest/QuickChartTest.csproj
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.0" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\QuickChart\QuickChart.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue