Skip to content

Commit

Permalink
small mods
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Nov 5, 2024
1 parent c3177d7 commit 0a0e4ad
Show file tree
Hide file tree
Showing 13 changed files with 3,003 additions and 505 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml → .github/workflows/lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ name: build
env:
VERSION: '6.0.0'
ASM_VERSION: '6.0.0'
VERSION_SUFFIX: '-pre.1'

on:
push:
branches:
- master
- codegen
- codegen
pull_request:
branches:
- master
Expand Down
110 changes: 49 additions & 61 deletions src/Config.Net.Tests/AbstractTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,66 @@
using System;
using System.IO;
using System.Reflection;
using NetBox.Extensions;

namespace Config.Net.Tests
{
public class AbstractTestFixture
{
private string TestDirContainer = "ts" + Guid.NewGuid();
private DirectoryInfo _testDir;
private static bool cleanedUp = false;
namespace Config.Net.Tests {
public class AbstractTestFixture {
private readonly string _testDirContainer = "ts" + Guid.NewGuid();
private DirectoryInfo _testDir;
private static bool cleanedUp = false;

/// <summary>
/// Isolated directory will be created for every test only when needed, and destroyed automagicaly
/// </summary>
protected DirectoryInfo TestDir
{
get
{
if (_testDir == null)
{
//Cleanup();
/// <summary>
/// Isolated directory will be created for every test only when needed, and destroyed automagicaly
/// </summary>
protected DirectoryInfo TestDir {
get {
if(_testDir == null) {
//Cleanup();

string testDir = Path.Combine(BuildDir.FullName, TestDirContainer, Guid.NewGuid().ToString());
Directory.CreateDirectory(testDir);
_testDir = new DirectoryInfo(testDir);
string testDir = Path.Combine(BuildDir.FullName, _testDirContainer, Guid.NewGuid().ToString());
Directory.CreateDirectory(testDir);
_testDir = new DirectoryInfo(testDir);
}
return _testDir;
}
return _testDir;
}
}
}

public AbstractTestFixture()
{
if (cleanedUp) return;
public AbstractTestFixture() {
if(cleanedUp)
return;

string dirPath = Path.Combine(BuildDir.FullName, TestDirContainer);
string dirPath = Path.Combine(BuildDir.FullName, _testDirContainer);

if (Directory.Exists(dirPath)) Directory.Delete(dirPath, true);
if(Directory.Exists(dirPath))
Directory.Delete(dirPath, true);

cleanedUp = true;
}
cleanedUp = true;
}

private void Cleanup()
{
//FS cleanup
foreach (DirectoryInfo oldDir in BuildDir.GetDirectories(TestDirContainer + "*", SearchOption.TopDirectoryOnly))
{
oldDir.Delete(true);
}
_testDir = null;
}
private void Cleanup() {
//FS cleanup
foreach(DirectoryInfo oldDir in BuildDir.GetDirectories(_testDirContainer + "*", SearchOption.TopDirectoryOnly)) {
oldDir.Delete(true);
}
_testDir = null;
}

protected DirectoryInfo BuildDir {
get {
string dllPath = new Uri(ThisAssembly.CodeBase).LocalPath;
return new FileInfo(dllPath).Directory;
}
}

protected DirectoryInfo BuildDir
{
get
{
string dllPath = new Uri(ThisAssembly.CodeBase).LocalPath;
return new FileInfo(dllPath).Directory;
}
}

private static Assembly _thisAsm;
internal static Assembly ThisAssembly {
get {
if(_thisAsm == null) {
_thisAsm = Assembly.GetExecutingAssembly();
}

private static Assembly _thisAsm;
internal static Assembly ThisAssembly
{
get
{
if (_thisAsm == null)
{
_thisAsm = Assembly.GetExecutingAssembly();
return _thisAsm;
}

return _thisAsm;
}
}
}
}
}
}
26 changes: 9 additions & 17 deletions src/Config.Net.Tests/Config.Net.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>3.0.0</VersionPrefix>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>


<ItemGroup>
<Compile Include="..\NetBox.cs" Link="NetBox.cs" />
</ItemGroup>

<ItemGroup>
<None Update="TestData\.env">
Expand All @@ -23,27 +26,16 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Config.Net.Yaml\Config.Net.Yaml.csproj" />
<ProjectReference Include="..\Config.Net\Config.Net.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Storage.Net" Version="9.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="netbox" Version="2.5.3" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="DotNet.ReproducibleBuilds" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
105 changes: 49 additions & 56 deletions src/Config.Net.Tests/CoreParsersTest.cs
Original file line number Diff line number Diff line change
@@ -1,63 +1,56 @@
using Config.Net.TypeParsers;
using NetBox.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Config.Net.Tests
{
public class CoreParsersTest
{
private static readonly ITypeParser Parser = new CoreParsers();

[Theory]
[InlineData("true", "true")]
[InlineData("false", "false")]
[InlineData("yes", "true")]
[InlineData("no", "false")]
[InlineData("1", "true")]
[InlineData("0", "false")]
public void Boolean__(string input, string expected)
{
object result;
bool parsed = Parser.TryParse(input, typeof(bool), out result);
Assert.True(parsed); // boolean always parses

string back = Parser.ToRawString(result);
Assert.Equal(expected, back);
}

[Fact]
public void Guid_Valid_Parses()
{
Guid g = Guid.NewGuid();

bool parsed = Parser.TryParse(g.ToString(), typeof(Guid), out object result);

Assert.True(parsed);
string back = Parser.ToRawString(g);
Assert.Equal(g.ToString(), back);
}

[Fact]
public void Guid_Invalid_False()
{
bool parsed = Parser.TryParse("dsfdsf", typeof(Guid), out object result);
Assert.False(parsed);
Assert.Null(result);
}

[Fact]
public void Dates_Valid_Parses()
{
DateTime d = DateTime.Now;

string s = Parser.ToRawString(d);

Assert.True(Parser.TryParse(s, typeof(DateTime), out object d1obj));
Assert.Equal(d.RoundToSecond(), ((DateTime)d1obj).RoundToSecond());
}
}
}
namespace Config.Net.Tests {
public class CoreParsersTest {
private static readonly ITypeParser Parser = new CoreParsers();

[Theory]
[InlineData("true", "true")]
[InlineData("false", "false")]
[InlineData("yes", "true")]
[InlineData("no", "false")]
[InlineData("1", "true")]
[InlineData("0", "false")]
public void Boolean__(string input, string expected) {
object result;
bool parsed = Parser.TryParse(input, typeof(bool), out result);
Assert.True(parsed); // boolean always parses

string back = Parser.ToRawString(result);
Assert.Equal(expected, back);
}

[Fact]
public void Guid_Valid_Parses() {
Guid g = Guid.NewGuid();

bool parsed = Parser.TryParse(g.ToString(), typeof(Guid), out object result);

Assert.True(parsed);
string back = Parser.ToRawString(g);
Assert.Equal(g.ToString(), back);
}

[Fact]
public void Guid_Invalid_False() {
bool parsed = Parser.TryParse("dsfdsf", typeof(Guid), out object result);
Assert.False(parsed);
Assert.Null(result);
}

[Fact]
public void Dates_Valid_Parses() {
DateTime d = DateTime.Now;

string s = Parser.ToRawString(d);

Assert.True(Parser.TryParse(s, typeof(DateTime), out object d1obj));
Assert.Equal(d.RoundToSecond(), ((DateTime)d1obj).RoundToSecond());
}
}
}
Loading

0 comments on commit 0a0e4ad

Please sign in to comment.