-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
3,003 additions
and
505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
Oops, something went wrong.