Skip to content

Commit 45c4b05

Browse files
committed
unit testing
1 parent 622949f commit 45c4b05

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

AdSecGHTests/AdSecGHTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<Platforms>x64</Platforms>
66
</PropertyGroup>
77
<ItemGroup>
8+
<PackageReference Include="AdSec" Version="2.0.0.21" />
89
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.3" />
910
<PackageReference Include="Rhino.Inside" Version="7.0.0" />
1011
<PackageReference Include="xunit" Version="2.7.0" />

AdSecGHTests/Helper/AdSecFileTest.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Reflection;
5+
using AdSecGH;
6+
using AdSecGH.Helpers;
7+
using AdSecGH.Parameters;
8+
using Xunit;
9+
10+
namespace AdSecGHTests.Helper {
11+
[Collection("GrasshopperFixture collection")]
12+
public class AdSecFileTest {
13+
private string CreateSampleJson(string codeName, bool valid = true) {
14+
return valid ?
15+
"something before codes \n\n \"codes\": {\r\n \"concrete\": \"" + codeName
16+
+ "\"\n },\n \n something after" : " \"codes\": {\"concrete\": \"" + codeName;
17+
}
18+
19+
[Fact]
20+
public void GetDesignCode_ForExistingCodesInAdSecFile_Test() {
21+
//workaround for loading API dll
22+
AddReferencePriority.AdSecAPI
23+
= Assembly.LoadFile(Path.GetFullPath(Environment.CurrentDirectory + "//AdSec_API.dll"));
24+
25+
foreach (string key in AdSecFile.Codes.Keys) {
26+
string json = CreateSampleJson(key);
27+
AdSecDesignCode code = AdSecFile.GetDesignCode(json);
28+
29+
Assert.True(AdSecFile.Codes.ContainsValue(code.DesignCode));
30+
Assert.True(AdSecFile.CodesStrings.ContainsValue(code.DesignCodeName.Replace(" ", "+")));
31+
}
32+
}
33+
34+
[Fact]
35+
public void GetDesignCode_ForInvalidCode_Test() {
36+
//workaround for loading API dll
37+
AddReferencePriority.AdSecAPI
38+
= Assembly.LoadFile(Path.GetFullPath(Environment.CurrentDirectory + "//AdSec_API.dll"));
39+
40+
string json = CreateSampleJson("I'm invalid design code!");
41+
42+
AdSecDesignCode code = AdSecFile.GetDesignCode(json);
43+
44+
Assert.Null(code);
45+
}
46+
47+
[Fact]
48+
public void GetDesignCode_ForInvalidJson_Test() {
49+
//workaround for loading API dll
50+
AddReferencePriority.AdSecAPI
51+
= Assembly.LoadFile(Path.GetFullPath(Environment.CurrentDirectory + "//AdSec_API.dll"));
52+
53+
string json = CreateSampleJson(AdSecFile.Codes.Keys.FirstOrDefault(), false);
54+
55+
AdSecDesignCode code = AdSecFile.GetDesignCode(json);
56+
57+
Assert.Null(code);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)