|
| 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