diff --git a/.gitignore b/.gitignore index 9217bf3..988b449 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ /.vs /.venv packages +bin/ +obj/ AdSecGH/bin AdSecGH/obj AdSecGHConverters/bin diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f63b4ef..d3433f5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: dotnet-build name: Build - entry: msbuild /p:AppxBundlePlatforms="x64" /p:AppxBundle=Always /p:UapAppxPackageBuildMode=StoreUpload /m /nr:false + entry: msbuild /p:AppxBundlePlatforms="x64" /p:AppxBundle=Always /p:UapAppxPackageBuildMode=StoreUpload /m /nr:false AdSecGH.sln language: system pass_filenames: false stages: [pre-push] diff --git a/AdSecCore.sln b/AdSecCore.sln new file mode 100644 index 0000000..3b37bdf --- /dev/null +++ b/AdSecCore.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCore", "AdSecCore\AdSecCore.csproj", "{2A3194AF-5B84-47DF-8E36-6819C2CF6E97}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCoreTests", "AdSecCoreTests\AdSecCoreTests.csproj", "{2407A2E8-B608-454F-A6A9-EABDFFFF48FD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2A3194AF-5B84-47DF-8E36-6819C2CF6E97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A3194AF-5B84-47DF-8E36-6819C2CF6E97}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A3194AF-5B84-47DF-8E36-6819C2CF6E97}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A3194AF-5B84-47DF-8E36-6819C2CF6E97}.Release|Any CPU.Build.0 = Release|Any CPU + {2407A2E8-B608-454F-A6A9-EABDFFFF48FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2407A2E8-B608-454F-A6A9-EABDFFFF48FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2407A2E8-B608-454F-A6A9-EABDFFFF48FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2407A2E8-B608-454F-A6A9-EABDFFFF48FD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/AdSecCore.sln.DotSettings.user b/AdSecCore.sln.DotSettings.user new file mode 100644 index 0000000..45ee6b9 --- /dev/null +++ b/AdSecCore.sln.DotSettings.user @@ -0,0 +1,4 @@ + + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Solution /> +</SessionState> diff --git a/AdSecCore/AdSecCore.csproj b/AdSecCore/AdSecCore.csproj new file mode 100644 index 0000000..138b136 --- /dev/null +++ b/AdSecCore/AdSecCore.csproj @@ -0,0 +1,9 @@ + + + + disable + disable + net48;net7.0 + + + diff --git a/AdSecCore/DoubleComparer.cs b/AdSecCore/DoubleComparer.cs new file mode 100644 index 0000000..02ecf02 --- /dev/null +++ b/AdSecCore/DoubleComparer.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace AdSecGHCore.Helpers { + public class DoubleComparer : IEqualityComparer { + private readonly double _epsilon = 0.01; //default accuracy in % + private readonly bool _margin; + + public DoubleComparer(double epsilon = 0.01, bool useEpsilonAsMargin = false) { + _epsilon = epsilon; + _margin = useEpsilonAsMargin; + } + + public bool Equals(double x, double y) { + x = Math.Round(x, 6); + y = Math.Round(y, 6); + + if (x == y) { + return true; + } + + if (_margin) { + if (Math.Abs(x - y) < _epsilon) { + return true; + } + } else { + double error = Math.Abs(x - y) / (x + y) * 0.5; + return error < _epsilon; + } + + return false; + } + + public int GetHashCode(double obj) { + return obj.GetHashCode(); + } + } +} diff --git a/AdSecCore/Result.cs b/AdSecCore/Result.cs new file mode 100644 index 0000000..5526ae1 --- /dev/null +++ b/AdSecCore/Result.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; + +namespace AdSecGHCore.Helpers { + + internal class Result { + + internal static double RoundToSignificantDigits(double d, int digits) { + if (d == 0.0) { + return 0.0; + } + + double leftSideNumbers = Math.Floor(Math.Log10(Math.Abs(d))) + 1; + double scale = Math.Pow(10, leftSideNumbers); + double result = scale * Math.Round(d / scale, digits, MidpointRounding.AwayFromZero); + + // Clean possible precision error. + if ((int)leftSideNumbers >= digits) { + return Math.Round(result, 0, MidpointRounding.AwayFromZero); + } + + if (Math.Abs(digits - (int)leftSideNumbers) > 15) { + return 0.0; + } + + return Math.Round(result, digits - (int)leftSideNumbers, MidpointRounding.AwayFromZero); + } + + internal static List SmartRounder(double max, double min) { + // find the biggest abs value of max and min + double val = Math.Max(Math.Abs(max), Math.Abs(min)); + + // round that with 4 significant digits + double scale = RoundToSignificantDigits(val, 4); + + // list to hold output values + var roundedvals = new List(); + + // do max + if (max == 0) { + roundedvals.Add(0); + } else { + double tempmax = scale * Math.Round(max / scale, 4); + tempmax = Math.Ceiling(tempmax * 1000) / 1000; + roundedvals.Add(tempmax); + } + + // do min + if (min == 0) { + roundedvals.Add(0); + } else { + double tempmin = scale * Math.Round(min / scale, 4); + tempmin = Math.Floor(tempmin * 1000) / 1000; + roundedvals.Add(tempmin); + } + + return roundedvals; + } + } +} diff --git a/AdSecCoreTests/AdSecCoreTests.csproj b/AdSecCoreTests/AdSecCoreTests.csproj new file mode 100644 index 0000000..04cd64a --- /dev/null +++ b/AdSecCoreTests/AdSecCoreTests.csproj @@ -0,0 +1,31 @@ + + + + net7.0 + enable + enable + + false + true + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/AdSecCoreTests/DoubleComparerTests.cs b/AdSecCoreTests/DoubleComparerTests.cs new file mode 100644 index 0000000..5f43011 --- /dev/null +++ b/AdSecCoreTests/DoubleComparerTests.cs @@ -0,0 +1,16 @@ +using AdSecGHCore.Helpers; + +namespace AdSecCoreTests { + public class DoubleComparerTests { + [Fact] + public void ValuesDifferLessThanEpsilonShouldBeConsideredEqual() { + Assert.Equal(10.0, 10.01, new DoubleComparer()); + } + + [Fact] + public void ValuesLargerThanEpsilonShouldBeConsideredEqual() { + int epsilon = 1; + Assert.NotEqual(10.0, 10.0 + (epsilon * 2), new DoubleComparer(epsilon, true)); + } + } +} diff --git a/AdSecGH.sln b/AdSecGH.sln index e5231d2..2c81397 100644 --- a/AdSecGH.sln +++ b/AdSecGH.sln @@ -13,6 +13,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdSecGHConverters", "AdSecG EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdSecGHConverterTests", "AdSecGHConverterTests\AdSecGHConverterTests.csproj", "{885C7D18-8B54-4430-A84B-8FD37CF7AD27}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCore", "AdSecCore\AdSecCore.csproj", "{D7A31820-EC4F-42EC-863C-51BB3647A145}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCoreTests", "AdSecCoreTests\AdSecCoreTests.csproj", "{DF259C79-A298-44B9-B702-573D4206A3C2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -39,6 +43,14 @@ Global {885C7D18-8B54-4430-A84B-8FD37CF7AD27}.Debug|x64.Build.0 = Debug|x64 {885C7D18-8B54-4430-A84B-8FD37CF7AD27}.Release|x64.ActiveCfg = Release|x64 {885C7D18-8B54-4430-A84B-8FD37CF7AD27}.Release|x64.Build.0 = Release|x64 + {D7A31820-EC4F-42EC-863C-51BB3647A145}.Debug|x64.ActiveCfg = Debug|Any CPU + {D7A31820-EC4F-42EC-863C-51BB3647A145}.Debug|x64.Build.0 = Debug|Any CPU + {D7A31820-EC4F-42EC-863C-51BB3647A145}.Release|x64.ActiveCfg = Release|Any CPU + {D7A31820-EC4F-42EC-863C-51BB3647A145}.Release|x64.Build.0 = Release|Any CPU + {DF259C79-A298-44B9-B702-573D4206A3C2}.Debug|x64.ActiveCfg = Debug|Any CPU + {DF259C79-A298-44B9-B702-573D4206A3C2}.Debug|x64.Build.0 = Debug|Any CPU + {DF259C79-A298-44B9-B702-573D4206A3C2}.Release|x64.ActiveCfg = Release|Any CPU + {DF259C79-A298-44B9-B702-573D4206A3C2}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AdSecGH.sln.DotSettings.user b/AdSecGH.sln.DotSettings.user new file mode 100644 index 0000000..edce023 --- /dev/null +++ b/AdSecGH.sln.DotSettings.user @@ -0,0 +1,4 @@ + + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Solution /> +</SessionState> diff --git a/AdSecGH/AdSecGH.csproj b/AdSecGH/AdSecGH.csproj index 50f792c..d3176bd 100644 --- a/AdSecGH/AdSecGH.csproj +++ b/AdSecGH/AdSecGH.csproj @@ -84,6 +84,9 @@ + + + C:\Program Files\Rhino 7\System\Rhino.exe diff --git a/AdSecGH/Helpers/Result.cs b/AdSecGH/Helpers/Result.cs index ba3e5f6..4ac9bf8 100644 --- a/AdSecGH/Helpers/Result.cs +++ b/AdSecGH/Helpers/Result.cs @@ -1,94 +1,94 @@ -using System; -using System.Collections.Generic; - -namespace AdSecGH.Helpers { - public class DoubleComparer : IEqualityComparer { - private double _epsilon = 0.01; //default accuracy in % - private bool _margin = false; - - public DoubleComparer(double epsilon = 0.01, bool useEpsilonAsMargin = false) { - _epsilon = epsilon; - _margin = useEpsilonAsMargin; - } - - public bool Equals(double x, double y) { - x = Math.Round(x, 6); - y = Math.Round(y, 6); - - if (x == y) { - return true; - } - - if (_margin) { - if (Math.Abs(x - y) < _epsilon) { - return true; - } - } else { - double error = Math.Abs(x - y) / (x + y) * 0.5; - return error < _epsilon; - } - - return false; - } - - public int GetHashCode(double obj) { - return obj.GetHashCode(); - } - - } - - internal class Result { - - internal static double RoundToSignificantDigits(double d, int digits) { - if (d == 0.0) { - return 0.0; - } else { - double leftSideNumbers = Math.Floor(Math.Log10(Math.Abs(d))) + 1; - double scale = Math.Pow(10, leftSideNumbers); - double result = scale * Math.Round(d / scale, digits, MidpointRounding.AwayFromZero); - - // Clean possible precision error. - if ((int)leftSideNumbers >= digits) { - return Math.Round(result, 0, MidpointRounding.AwayFromZero); - } else { - if (Math.Abs(digits - (int)leftSideNumbers) > 15) { - return 0.0; - } - - return Math.Round(result, digits - (int)leftSideNumbers, MidpointRounding.AwayFromZero); - } - } - } - - internal static List SmartRounder(double max, double min) { - // find the biggest abs value of max and min - double val = Math.Max(Math.Abs(max), Math.Abs(min)); - - // round that with 4 significant digits - double scale = RoundToSignificantDigits(val, 4); - - // list to hold output values - var roundedvals = new List(); - - // do max - if (max == 0) { - roundedvals.Add(0); - } else { - double tempmax = scale * Math.Round(max / scale, 4); - tempmax = Math.Ceiling(tempmax * 1000) / 1000; - roundedvals.Add(tempmax); - } - - // do min - if (min == 0) { - roundedvals.Add(0); - } else { - double tempmin = scale * Math.Round(min / scale, 4); - tempmin = Math.Floor(tempmin * 1000) / 1000; - roundedvals.Add(tempmin); - } - - return roundedvals; - } - } -} +// using System; +// using System.Collections.Generic; +// +// namespace AdSecGH.Helpers { +// public class DoubleComparer : IEqualityComparer { +// private double _epsilon = 0.01; //default accuracy in % +// private bool _margin = false; +// +// public DoubleComparer(double epsilon = 0.01, bool useEpsilonAsMargin = false) { +// _epsilon = epsilon; +// _margin = useEpsilonAsMargin; +// } +// +// public bool Equals(double x, double y) { +// x = Math.Round(x, 6); +// y = Math.Round(y, 6); +// +// if (x == y) { +// return true; +// } +// +// if (_margin) { +// if (Math.Abs(x - y) < _epsilon) { +// return true; +// } +// } else { +// double error = Math.Abs(x - y) / (x + y) * 0.5; +// return error < _epsilon; +// } +// +// return false; +// } +// +// public int GetHashCode(double obj) { +// return obj.GetHashCode(); +// } +// +// } +// +// internal class Result { +// +// internal static double RoundToSignificantDigits(double d, int digits) { +// if (d == 0.0) { +// return 0.0; +// } else { +// double leftSideNumbers = Math.Floor(Math.Log10(Math.Abs(d))) + 1; +// double scale = Math.Pow(10, leftSideNumbers); +// double result = scale * Math.Round(d / scale, digits, MidpointRounding.AwayFromZero); +// +// // Clean possible precision error. +// if ((int)leftSideNumbers >= digits) { +// return Math.Round(result, 0, MidpointRounding.AwayFromZero); +// } else { +// if (Math.Abs(digits - (int)leftSideNumbers) > 15) { +// return 0.0; +// } +// +// return Math.Round(result, digits - (int)leftSideNumbers, MidpointRounding.AwayFromZero); +// } +// } +// } +// +// internal static List SmartRounder(double max, double min) { +// // find the biggest abs value of max and min +// double val = Math.Max(Math.Abs(max), Math.Abs(min)); +// +// // round that with 4 significant digits +// double scale = RoundToSignificantDigits(val, 4); +// +// // list to hold output values +// var roundedvals = new List(); +// +// // do max +// if (max == 0) { +// roundedvals.Add(0); +// } else { +// double tempmax = scale * Math.Round(max / scale, 4); +// tempmax = Math.Ceiling(tempmax * 1000) / 1000; +// roundedvals.Add(tempmax); +// } +// +// // do min +// if (min == 0) { +// roundedvals.Add(0); +// } else { +// double tempmin = scale * Math.Round(min / scale, 4); +// tempmin = Math.Floor(tempmin * 1000) / 1000; +// roundedvals.Add(tempmin); +// } +// +// return roundedvals; +// } +// } +// } diff --git a/AdSecGHTests/AdSecGHTests.csproj b/AdSecGHTests/AdSecGHTests.csproj index 59a67be..badfb4d 100644 --- a/AdSecGHTests/AdSecGHTests.csproj +++ b/AdSecGHTests/AdSecGHTests.csproj @@ -3,12 +3,13 @@ net48 x64 x64 + 8 - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -20,7 +21,7 @@ - + @@ -28,10 +29,10 @@ - + - + diff --git a/AdSecGHTests/Components/1_Properties/CreateConcreteCrackCalculationParametersComponentTests.cs b/AdSecGHTests/Components/1_Properties/CreateConcreteCrackCalculationParametersComponentTests.cs index ed635fc..80bc709 100644 --- a/AdSecGHTests/Components/1_Properties/CreateConcreteCrackCalculationParametersComponentTests.cs +++ b/AdSecGHTests/Components/1_Properties/CreateConcreteCrackCalculationParametersComponentTests.cs @@ -17,7 +17,7 @@ public static GH_OasysDropDownComponent ComponentMother() { comp.SetSelected(0, 0); // change dropdown to ? - ComponentTestHelper.SetInput(comp, 130, 0); + ComponentTestHelper.SetInput(comp, 130); ComponentTestHelper.SetInput(comp, 1700, 1); ComponentTestHelper.SetInput(comp, 1200, 2); @@ -26,13 +26,13 @@ public static GH_OasysDropDownComponent ComponentMother() { [Fact] public void ChangeDropDownTest() { - GH_OasysDropDownComponent comp = ComponentMother(); + var comp = ComponentMother(); OasysDropDownComponentTestHelper.ChangeDropDownTest(comp); } [Fact] public void CreateComponent() { - GH_OasysDropDownComponent comp = ComponentMother(); + var comp = ComponentMother(); comp.SetSelected(0, 0); // change dropdown to ? var output = (AdSecConcreteCrackCalculationParametersGoo)ComponentTestHelper.GetOutput(comp); //Assert.Equal(0, output.Value.StartPosition.Value); @@ -61,7 +61,7 @@ public void CreateComponent() { [Fact] public void DeserializeTest() { - GH_OasysDropDownComponent comp = ComponentMother(); + var comp = ComponentMother(); OasysDropDownComponentTestHelper.DeserializeTest(comp); } } diff --git a/AdSecGHTests/Helpers/AdSecFileTest.cs b/AdSecGHTests/Helpers/AdSecFileTest.cs index 90543a8..59abad4 100644 --- a/AdSecGHTests/Helpers/AdSecFileTest.cs +++ b/AdSecGHTests/Helpers/AdSecFileTest.cs @@ -5,7 +5,6 @@ using AdSecGH; using AdSecGH.Helpers; -using AdSecGH.Parameters; using Xunit; @@ -26,7 +25,7 @@ public void GetDesignCode_ForExistingCodesInAdSecFile_Test() { foreach (string key in AdSecFile.Codes.Keys) { string json = CreateSampleJson(key); - AdSecDesignCode code = AdSecFile.GetDesignCode(json); + var code = AdSecFile.GetDesignCode(json); Assert.True(AdSecFile.Codes.ContainsValue(code.DesignCode)); Assert.True(AdSecFile.CodesStrings.ContainsValue(code.DesignCodeName.Replace(" ", "+"))); @@ -41,7 +40,7 @@ public void GetDesignCode_ForInvalidCode_Test() { string json = CreateSampleJson("I'm invalid design code!"); - AdSecDesignCode code = AdSecFile.GetDesignCode(json); + var code = AdSecFile.GetDesignCode(json); Assert.Null(code); } @@ -54,7 +53,7 @@ public void GetDesignCode_ForInvalidJson_Test() { string json = CreateSampleJson(AdSecFile.Codes.Keys.FirstOrDefault(), false); - AdSecDesignCode code = AdSecFile.GetDesignCode(json); + var code = AdSecFile.GetDesignCode(json); Assert.Null(code); } diff --git a/AdSecGHTests/Helpers/Duplicates.cs b/AdSecGHTests/Helpers/Duplicates.cs index cd414d7..365ea60 100644 --- a/AdSecGHTests/Helpers/Duplicates.cs +++ b/AdSecGHTests/Helpers/Duplicates.cs @@ -4,36 +4,118 @@ using System.Linq; using System.Reflection; +using AdSecGH.Components; + +using Grasshopper.Kernel; + +using OasysGH.Components; + using Xunit; namespace AdSecGHTests.Helpers { + + public static class ModFactory { + public static Type[] GetAllAssemblyTypes(string assemblyName = "AdSec.dll", string nameSpace = "") { + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + + foreach (var item in assemblies) { + Console.WriteLine(item); + var other = item.GetLoadedModules(); + other.ToList().ForEach(m => Console.WriteLine(m)); + } + + var assembly = assemblies.FirstOrDefault(x => x.ManifestModule.Name.Equals(assemblyName) + || x.ManifestModule.ScopeName.Equals(assemblyName)); + + var classes = assembly.GetTypes(); + if (nameSpace != string.Empty) { + classes = classes.Where(x => x.Namespace == nameSpace).ToArray(); + } + + return classes; + } + + public static IEnumerable ImplementsInterface(this Type[] collection, Type[] interfaces) { + return collection.Where(x => x.IsClass && !x.IsAbstract && interfaces.All(y => y.IsAssignableFrom(x))); + } + + public static IEnumerable GetAllInterfaceTypes(Type[] interfaces) { + var allAssemblyTypes = GetAllAssemblyTypes(); + return allAssemblyTypes.ImplementsInterface(interfaces); + } + + public static IEnumerable GetAllInterfaceTypes() { + return GetAllInterfaceTypes(new[] { + typeof(GH_Component), + typeof(GH_OasysComponent), + }); + } + + public static GH_Component[] CreateInstancesWithCreateInterface() { + var allInterfaceTypes = GetAllInterfaceTypes(); + var components = allInterfaceTypes.Select(Activator.CreateInstance).Select(x => x as GH_Component).ToArray(); + return components; + } + } + + [Collection("GrasshopperFixture collection")] + public class DropToCanvasTests { + //[Fact] + //public void TestAllComponents() { + // var instances = ModFactory.CreateInstancesWithCreateInterface(); + // foreach (var instance in instances) { + // Assert.NotNull(instance); + // } + //} + + [Fact] + public void TestAllComponentsByType() { + // Get All Assemblies + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + // Get The One for AdSecGH + var assembly = assemblies.FirstOrDefault(x => x.ManifestModule.Name.Equals("AdSecGH.dll") + || x.ManifestModule.ScopeName.Equals("AdSecGH.dll")); + // Get All Types matching GH_Component or GH_OasysDropdownComponent + var types = assembly.GetTypes().Where(x + => x.IsClass && !x.IsAbstract && typeof(GH_OasysDropDownComponent).IsAssignableFrom(x) + && x != typeof(CreateDesignCode)).ToArray(); + foreach (var type in types) { + var instance = (GH_Component)Activator.CreateInstance(type); + instance.ExpireSolution(true); + Assert.True(instance.RuntimeMessages(GH_RuntimeMessageLevel.Error).Count == 0); + } + } + } + public class Duplicates { public static bool AreEqual(object objA, object objB, bool excludeGuid = false) { - if (!(excludeGuid && objA.Equals(typeof(System.Guid)))) { + if (!(excludeGuid && objA.Equals(typeof(Guid)))) { Assert.Equal(objA.ToString(), objB.ToString()); } - Type typeA = objA.GetType(); - Type typeB = objB.GetType(); + var typeA = objA.GetType(); + var typeB = objB.GetType(); - PropertyInfo[] propertyInfoA = typeA.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - PropertyInfo[] propertyInfoB = typeB.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + var propertyInfoA = typeA.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + var propertyInfoB = typeB.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int i = 0; i < propertyInfoA.Length; i++) { - PropertyInfo propertyA = propertyInfoA[i]; - PropertyInfo propertyB = propertyInfoB[i]; + var propertyA = propertyInfoA[i]; + var propertyB = propertyInfoB[i]; if (!propertyA.CanWrite && !propertyB.CanWrite) { continue; - } else if (!propertyA.CanWrite || !propertyB.CanWrite) { + } + + if (!propertyA.CanWrite || !propertyB.CanWrite) { Assert.Equal(objA, objB); } object objPropertyValueA; object objPropertyValueB; - Type propertyTypeA = propertyA.PropertyType; - Type propertyTypeB = propertyB.PropertyType; + var propertyTypeA = propertyA.PropertyType; + var propertyTypeB = propertyB.PropertyType; try { objPropertyValueA = propertyA.GetValue(objA, null); @@ -45,6 +127,7 @@ public static bool AreEqual(object objA, object objB, bool excludeGuid = false) propertyTypeA = objPropertyValueA.GetType(); } } + if (propertyTypeB.IsInterface) { if (objPropertyValueB != null) { propertyTypeB = objPropertyValueB.GetType(); @@ -53,21 +136,24 @@ public static bool AreEqual(object objA, object objB, bool excludeGuid = false) // check wether property is an enumerable if (typeof(IEnumerable).IsAssignableFrom(propertyTypeA) && !typeof(string).IsAssignableFrom(propertyTypeA)) { - if (typeof(IEnumerable).IsAssignableFrom(propertyTypeB) && !typeof(string).IsAssignableFrom(propertyTypeB)) { + if (typeof(IEnumerable).IsAssignableFrom(propertyTypeB) + && !typeof(string).IsAssignableFrom(propertyTypeB)) { if (objPropertyValueA == null || objPropertyValueB == null) { Assert.Equal(objPropertyValueA, objPropertyValueB); } else { - IEnumerable enumerableA = ((IEnumerable)objPropertyValueA).Cast(); - IEnumerable enumerableB = ((IEnumerable)objPropertyValueB).Cast(); + var enumerableA = ((IEnumerable)objPropertyValueA).Cast(); + var enumerableB = ((IEnumerable)objPropertyValueB).Cast(); Type enumrableTypeA = null; Type enumrableTypeB = null; if (enumerableA.GetType().GetGenericArguments().Length > 0) { enumrableTypeA = enumerableA.GetType().GetGenericArguments()[0]; } + if (enumerableB.GetType().GetGenericArguments().Length > 0) { enumrableTypeB = enumerableB.GetType().GetGenericArguments()[0]; } + Assert.Equal(enumrableTypeA, enumrableTypeB); // if type is a struct, we have to check the actual list items @@ -79,6 +165,7 @@ public static bool AreEqual(object objA, object objB, bool excludeGuid = false) continue; // can´t get type of struct in empty list? } } + if (enumrableTypeB.ToString() is "System.Object") { if (enumerableB.Any()) { enumrableTypeB = enumerableB.First().GetType(); @@ -87,13 +174,13 @@ public static bool AreEqual(object objA, object objB, bool excludeGuid = false) } } - Type genericListTypeA = typeof(List<>).MakeGenericType(enumrableTypeA); - Type genericListTypeB = typeof(List<>).MakeGenericType(enumrableTypeB); + var genericListTypeA = typeof(List<>).MakeGenericType(enumrableTypeA); + var genericListTypeB = typeof(List<>).MakeGenericType(enumrableTypeB); Assert.Equal(genericListTypeA, genericListTypeB); - IEnumerator enumeratorB = enumerableB.GetEnumerator(); + var enumeratorB = enumerableB.GetEnumerator(); - using (IEnumerator enumeratorA = enumerableA.GetEnumerator()) { + using (var enumeratorA = enumerableA.GetEnumerator()) { while (enumeratorA.MoveNext()) { Assert.True(enumeratorB.MoveNext()); AreEqual(enumeratorA.Current, enumeratorB.Current); @@ -106,21 +193,23 @@ public static bool AreEqual(object objA, object objB, bool excludeGuid = false) } // check whether property type is value type, enum or string type else if (propertyTypeA.IsValueType || propertyTypeA.IsEnum || propertyTypeA.Equals(typeof(string))) { - if (excludeGuid && propertyTypeA.Equals(typeof(System.Guid))) { + if (excludeGuid && propertyTypeA.Equals(typeof(Guid))) { continue; } + Assert.Equal(objPropertyValueA, objPropertyValueB); } else if (objPropertyValueA == null || objPropertyValueB == null) { Assert.Equal(objPropertyValueA, objPropertyValueB); } else - // property type is object/complex type, so need to recursively call this method until the end of the tree is reached - { + // property type is object/complex type, so need to recursively call this method until the end of the tree is reached + { AreEqual(objPropertyValueA, objPropertyValueB, excludeGuid); } } catch (TargetParameterCountException) { propertyTypeA = propertyA.PropertyType; } } + return true; } } diff --git a/AdSecGHTests/Parameters/AdSecSectionTests.cs b/AdSecGHTests/Parameters/AdSecSectionTests.cs index 947fefb..96fab45 100644 --- a/AdSecGHTests/Parameters/AdSecSectionTests.cs +++ b/AdSecGHTests/Parameters/AdSecSectionTests.cs @@ -1,42 +1,48 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.IO; using AdSecGH.Helpers; +using AdSecGHCore.Helpers; + using Oasys.AdSec; using Oasys.AdSec.DesignCode; using Oasys.AdSec.IO.Serialization; using Oasys.AdSec.Materials; using Oasys.AdSec.Reinforcement; using Oasys.AdSec.Reinforcement.Groups; +using Oasys.AdSec.StandardMaterials; using Oasys.Profiles; using Oasys.Taxonomy.Geometry; +using Oasys.Taxonomy.Profiles; using OasysUnits; using OasysUnits.Units; using Xunit; +using IPerimeterProfile = Oasys.Profiles.IPerimeterProfile; +using IPolygon = Oasys.Taxonomy.Geometry.IPolygon; + namespace AdSecGHTests.Parameters { [Collection("GrasshopperFixture collection")] public class AdSecSectionTests { [Fact] public void SerialiseUnflattenedSectionTest() { - ISection section = CreateSection(); + var section = CreateSection(); - IDesignCode designCode = EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013; + var designCode = EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013; var adSec = IAdSec.Create(designCode); - ISection flattened = adSec.Flatten(section); + var flattened = adSec.Flatten(section); string fileName = Path.GetTempPath() + "AdSecSectionTest.ads"; File.WriteAllText(fileName, CreateJson(designCode, section)); string json = File.ReadAllText(fileName); - ParsedResult jsonParser = JsonParser.Deserialize(json); - ISection actualSection = jsonParser.Sections[0]; + var jsonParser = JsonParser.Deserialize(json); + var actualSection = jsonParser.Sections[0]; var expectedProfile = (IPerimeterProfile)flattened.Profile; var actualProfile = (IPerimeterProfile)actualSection.Profile; @@ -46,18 +52,18 @@ public void SerialiseUnflattenedSectionTest() { [Fact] public void SerialiaseFlattenedSectionTest() { - ISection section = CreateSection(); + var section = CreateSection(); - IDesignCode designCode = EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013; + var designCode = EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013; var adSec = IAdSec.Create(designCode); - ISection flattened = adSec.Flatten(section); + var flattened = adSec.Flatten(section); string fileName = Path.GetTempPath() + "AdSecSectionTest.ads"; File.WriteAllText(fileName, CreateJson(designCode, flattened)); string json = File.ReadAllText(fileName); - ParsedResult jsonParser = JsonParser.Deserialize(json); - ISection actualSection = jsonParser.Sections[0]; + var jsonParser = JsonParser.Deserialize(json); + var actualSection = jsonParser.Sections[0]; var expectedProfile = (IPerimeterProfile)flattened.Profile; var actualProfile = (IPerimeterProfile)actualSection.Profile; @@ -72,27 +78,37 @@ private void TestFlattenedSection(ISection expected, ISection actual) { var actualProfile = (IPerimeterProfile)actual.Profile; Assert.Equal(expectedProfile.Area().Value, actualProfile.Area().Value, new DoubleComparer()); double actualBarArea = 0; - foreach (IGroup group in actual.ReinforcementGroups) { + foreach (var group in actual.ReinforcementGroups) { var singleBar = group as ISingleBars; - actualBarArea += Math.PI * Math.Pow(singleBar.BarBundle.Diameter.Value / 2.0, 2) * singleBar.BarBundle.CountPerBundle; + actualBarArea += Math.PI * Math.Pow(singleBar.BarBundle.Diameter.Value / 2.0, 2) + * singleBar.BarBundle.CountPerBundle; } double expectedBarArea = 0; - foreach (IGroup group in expected.ReinforcementGroups) { + foreach (var group in expected.ReinforcementGroups) { var singleBar = group as ISingleBars; - expectedBarArea += Math.PI * Math.Pow(singleBar.BarBundle.Diameter.Value / 2.0, 2) * singleBar.BarBundle.CountPerBundle; + expectedBarArea += Math.PI * Math.Pow(singleBar.BarBundle.Diameter.Value / 2.0, 2) + * singleBar.BarBundle.CountPerBundle; } Assert.Equal(expectedBarArea, actualBarArea, new DoubleComparer()); - Assert.Equal(expectedProfile.ElasticModulus().Y.Value, actualProfile.ElasticModulus().Y.Value, new DoubleComparer()); - Assert.Equal(expectedProfile.ElasticModulus().Z.Value, actualProfile.ElasticModulus().Z.Value, new DoubleComparer()); - Assert.Equal(expectedProfile.SurfaceAreaPerUnitLength().Value, actualProfile.SurfaceAreaPerUnitLength().Value, new DoubleComparer()); - Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().YY.Value, actualProfile.LocalAxisSecondMomentOfArea().YY.Value, new DoubleComparer()); - Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().ZZ.Value, actualProfile.LocalAxisSecondMomentOfArea().ZZ.Value, new DoubleComparer()); - Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().YZ.Value, actualProfile.LocalAxisSecondMomentOfArea().YZ.Value, new DoubleComparer()); - Assert.Equal(expectedProfile.PrincipalAxisSecondMomentOfArea().UU.Value, actualProfile.PrincipalAxisSecondMomentOfArea().UU.Value, new DoubleComparer()); - Assert.Equal(expectedProfile.PrincipalAxisSecondMomentOfArea().VV.Value, actualProfile.PrincipalAxisSecondMomentOfArea().VV.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.ElasticModulus().Y.Value, actualProfile.ElasticModulus().Y.Value, + new DoubleComparer()); + Assert.Equal(expectedProfile.ElasticModulus().Z.Value, actualProfile.ElasticModulus().Z.Value, + new DoubleComparer()); + Assert.Equal(expectedProfile.SurfaceAreaPerUnitLength().Value, actualProfile.SurfaceAreaPerUnitLength().Value, + new DoubleComparer()); + Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().YY.Value, + actualProfile.LocalAxisSecondMomentOfArea().YY.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().ZZ.Value, + actualProfile.LocalAxisSecondMomentOfArea().ZZ.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.LocalAxisSecondMomentOfArea().YZ.Value, + actualProfile.LocalAxisSecondMomentOfArea().YZ.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.PrincipalAxisSecondMomentOfArea().UU.Value, + actualProfile.PrincipalAxisSecondMomentOfArea().UU.Value, new DoubleComparer()); + Assert.Equal(expectedProfile.PrincipalAxisSecondMomentOfArea().VV.Value, + actualProfile.PrincipalAxisSecondMomentOfArea().VV.Value, new DoubleComparer()); } private static string CreateJson(IDesignCode designCode, ISection section) { @@ -101,10 +117,10 @@ private static string CreateJson(IDesignCode designCode, ISection section) { } private static ISection CreateSection() { - IMaterial material = Oasys.AdSec.StandardMaterials.Concrete.EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013.C40_50; - IReinforcement rebarMaterial = Oasys.AdSec.StandardMaterials.Reinforcement.Steel.EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013.S500B; + IMaterial material = Concrete.EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013.C40_50; + var rebarMaterial = Reinforcement.Steel.EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013.S500B; - var points = new List() { + var points = new List { new Point2d(new Length(3.1464410643837, LengthUnit.Meter), new Length(2.9552083887352, LengthUnit.Meter)), new Point2d(new Length(-0.6535618090254, LengthUnit.Meter), new Length(2.9552083887352, LengthUnit.Meter)), new Point2d(new Length(-0.6535618090254, LengthUnit.Meter), new Length(-1.2447891504457, LengthUnit.Meter)), @@ -140,12 +156,13 @@ private static ISection CreateSection() { }; var polygon = new Polygon(points); - var profile = new Oasys.Taxonomy.Profiles.PerimeterProfile(polygon, new List()); - IPerimeterProfile adsecProfile = AdSecProfiles.CreatePerimeterProfile(profile); + var profile = new PerimeterProfile(polygon, new List()); + var adsecProfile = AdSecProfiles.CreatePerimeterProfile(profile); var section = ISection.Create(adsecProfile, material); var bars = ISingleBars.Create(IBarBundle.Create(rebarMaterial, new Length(25, LengthUnit.Millimeter))); - bars.Positions.Add(IPoint.Create(new Length(5400, LengthUnit.Millimeter), new Length(3000, LengthUnit.Millimeter))); + bars.Positions.Add( + IPoint.Create(new Length(5400, LengthUnit.Millimeter), new Length(3000, LengthUnit.Millimeter))); section.ReinforcementGroups.Add(bars); section.Profile.Validate(); diff --git a/IntegrationTests/1_ExampleFiles/AdSecGH_Example1_RectangularBeam.cs b/IntegrationTests/1_ExampleFiles/AdSecGH_Example1_RectangularBeam.cs index cd2ef74..7f1951e 100644 --- a/IntegrationTests/1_ExampleFiles/AdSecGH_Example1_RectangularBeam.cs +++ b/IntegrationTests/1_ExampleFiles/AdSecGH_Example1_RectangularBeam.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using System.Reflection; using Grasshopper.Kernel; @@ -9,15 +8,16 @@ namespace IntegrationTests.Components { [Collection("GrasshopperFixture collection")] public class AdSecGH_Example1_RectangularBeamTests { + private static GH_Document _document; public static GH_Document Document { get { if (_document == null) { _document = OpenDocument(); } + return _document; } } - private static GH_Document _document = null; [Fact] public void NoRuntimeErrorTest() { @@ -28,25 +28,85 @@ public void NoRuntimeErrorTest() { [Theory] [InlineData("CadTest", 15)] [InlineData("NmDiagramTest", 116003.838766)] - [InlineData("ConcreteStressTest", new double[] { -0.327292, -5.108709, -0.13875, -4.642858 })] - [InlineData("RebarUlsStrainTest", new double[] { 0.262073, 0.216727, 0.166176, 0.115644, 0.145305, 0.016448, -0.134224, -0.006349, -0.104581, -0.15289, -0.201211, -0.246279 })] - [InlineData("RebarUlsStressTest", new double[] { 52.414556, 43.34542, 33.235123, 23.128806, 29.061078, 3.289703, -26.844842, -1.269816, -20.916174, -30.577941, -40.242196, -49.255725 })] - [InlineData("RebarSlsStrainTest", new double[] { 0.058393, 0.044786, 0.029483, 0.014066, 0.017519, -0.027111, -0.073019, -0.028389, -0.069464, -0.084162, -0.09879, -0.112358 })] - [InlineData("RebarSlsStressTest", new double[] { 11.678512, 8.957159, 5.896622, 2.813283, 3.503728, -5.422205, -14.603815, -5.677882, -13.892725, -16.83249, -19.758003, -22.471527 })] + [InlineData("ConcreteStressTest", new[] { + -0.327292, + -5.108709, + -0.13875, + -4.642858, + })] + [InlineData("RebarUlsStrainTest", new[] { + 0.262073, + 0.216727, + 0.166176, + 0.115644, + 0.145305, + 0.016448, + -0.134224, + -0.006349, + -0.104581, + -0.15289, + -0.201211, + -0.246279, + })] + [InlineData("RebarUlsStressTest", new[] { + 52.414556, + 43.34542, + 33.235123, + 23.128806, + 29.061078, + 3.289703, + -26.844842, + -1.269816, + -20.916174, + -30.577941, + -40.242196, + -49.255725, + })] + [InlineData("RebarSlsStrainTest", new[] { + 0.058393, + 0.044786, + 0.029483, + 0.014066, + 0.017519, + -0.027111, + -0.073019, + -0.028389, + -0.069464, + -0.084162, + -0.09879, + -0.112358, + })] + [InlineData("RebarSlsStressTest", new[] { + 11.678512, + 8.957159, + 5.896622, + 2.813283, + 3.503728, + -5.422205, + -14.603815, + -5.677882, + -13.892725, + -16.83249, + -19.758003, + -22.471527, + })] [InlineData("LoadUtilisationTest", 0.137663)] [InlineData("CrackUtilisationTest", 1.423388)] public void Test(string groupIdentifier, object expected) { - IGH_Param param = Helper.FindParameter(Document, groupIdentifier); + var param = Helper.FindParameter(Document, groupIdentifier); Helper.TestGHPrimitives(param, expected); } private static GH_Document OpenDocument() { - Type thisClass = MethodBase.GetCurrentMethod().DeclaringType; + var thisClass = MethodBase.GetCurrentMethod().DeclaringType; string fileName = thisClass.Name + ".gh"; fileName = fileName.Replace(thisClass.Namespace, string.Empty).Replace("Tests", string.Empty); string solutiondir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.FullName; - string path = Path.Combine(new string[] { solutiondir, "ExampleFiles" }); + string path = Path.Combine(new[] { + solutiondir, + "ExampleFiles", + }); return Helper.CreateDocument(Path.Combine(path, fileName)); } diff --git a/IntegrationTests/1_ExampleFiles/AdSecGH_Example2_CompositeColumn.cs b/IntegrationTests/1_ExampleFiles/AdSecGH_Example2_CompositeColumn.cs index 035b5f0..de79909 100644 --- a/IntegrationTests/1_ExampleFiles/AdSecGH_Example2_CompositeColumn.cs +++ b/IntegrationTests/1_ExampleFiles/AdSecGH_Example2_CompositeColumn.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using System.Reflection; using Grasshopper.Kernel; @@ -9,15 +8,16 @@ namespace IntegrationTests.Components { [Collection("GrasshopperFixture collection")] public class AdSecGH_Example2_CompositeColumnTests { + private static GH_Document _document; public static GH_Document Document { get { if (_document == null) { _document = OpenDocument(); } + return _document; } } - private static GH_Document _document = null; [Fact] public void NoRuntimeErrorTest() { @@ -28,25 +28,73 @@ public void NoRuntimeErrorTest() { [Theory] [InlineData("CadTest", 14)] [InlineData("NmDiagramTest", 120215.428945)] - [InlineData("ConcreteStressTest", new double[] { -0.373978, -7.684297, -0.16744, -6.056018 })] - [InlineData("RebarUlsStrainTest", new double[] { 0.241326, 0.220247, 0.102692, -0.056334, -0.182421, -0.216571, -0.142805, 0.005074, 0.156066 })] - [InlineData("RebarUlsStressTest", new double[] { 48.265163, 44.04935, 20.538307, -11.26689, -36.484234, -43.31425, -28.561098, 1.014877, 31.213118 })] - [InlineData("RebarSlsStrainTest", new double[] { 0.064542, 0.055894, 0.01106, -0.04898, -0.096133, -0.108336, -0.079879, -0.024077, 0.032959 })] - [InlineData("RebarSlsStressTest", new double[] { 12.908482, 11.178755, 2.212077, -9.795945, -19.226623, -21.667238, -15.9758, -4.815395, 6.591898 })] + [InlineData("ConcreteStressTest", new[] { + -0.373978, + -7.684297, + -0.16744, + -6.056018, + })] + [InlineData("RebarUlsStrainTest", new[] { + 0.241326, + 0.220247, + 0.102692, + -0.056334, + -0.182421, + -0.216571, + -0.142805, + 0.005074, + 0.156066, + })] + [InlineData("RebarUlsStressTest", new[] { + 48.265163, + 44.04935, + 20.538307, + -11.26689, + -36.484234, + -43.31425, + -28.561098, + 1.014877, + 31.213118, + })] + [InlineData("RebarSlsStrainTest", new[] { + 0.064542, + 0.055894, + 0.01106, + -0.04898, + -0.096133, + -0.108336, + -0.079879, + -0.024077, + 0.032959, + })] + [InlineData("RebarSlsStressTest", new[] { + 12.908482, + 11.178755, + 2.212077, + -9.795945, + -19.226623, + -21.667238, + -15.9758, + -4.815395, + 6.591898, + })] [InlineData("LoadUtilisationTest", 0.128236)] [InlineData("CrackUtilisationTest", 1.315612)] public void Test(string groupIdentifier, object expected) { - IGH_Param param = Helper.FindParameter(Document, groupIdentifier); + var param = Helper.FindParameter(Document, groupIdentifier); Helper.TestGHPrimitives(param, expected); } private static GH_Document OpenDocument() { - Type thisClass = MethodBase.GetCurrentMethod().DeclaringType; + var thisClass = MethodBase.GetCurrentMethod().DeclaringType; string fileName = thisClass.Name + ".gh"; fileName = fileName.Replace(thisClass.Namespace, string.Empty).Replace("Tests", string.Empty); string solutiondir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.FullName; - string path = Path.Combine(new string[] { solutiondir, "ExampleFiles" }); + string path = Path.Combine(new[] { + solutiondir, + "ExampleFiles", + }); return Helper.CreateDocument(Path.Combine(path, fileName)); } diff --git a/IntegrationTests/Helper/Helper.cs b/IntegrationTests/Helper/Helper.cs index 1c51001..51ddc71 100644 --- a/IntegrationTests/Helper/Helper.cs +++ b/IntegrationTests/Helper/Helper.cs @@ -1,7 +1,6 @@ -using System; -using System.IO; +using System.IO; -using AdSecGH.Helpers; +using AdSecGHCore.Helpers; using Grasshopper.Kernel; using Grasshopper.Kernel.Special; @@ -23,12 +22,12 @@ public static GH_Document CreateDocument(string path) { } public static GH_Component FindComponent(GH_Document doc, string groupIdentifier) { - foreach (IGH_DocumentObject obj in doc.Objects) { + foreach (var obj in doc.Objects) { if (obj is GH_Group group) { if (group.NickName == groupIdentifier) { - Guid componentguid = group.ObjectIDs[0]; + var componentguid = group.ObjectIDs[0]; - foreach (IGH_DocumentObject obj2 in doc.Objects) { + foreach (var obj2 in doc.Objects) { if (obj2.InstanceGuid == componentguid) { var comp = (GH_Component)obj2; Assert.NotNull(comp); @@ -36,34 +35,38 @@ public static GH_Component FindComponent(GH_Document doc, string groupIdentifier return comp; } } + Assert.Fail("Unable to find component in group with Nickname " + groupIdentifier); return null; } } } + Assert.Fail("Unable to find group with Nickname " + groupIdentifier); return null; } public static IGH_Param FindParameter(GH_Document doc, string groupIdentifier) { - foreach (IGH_DocumentObject obj in doc.Objects) { + foreach (var obj in doc.Objects) { if (obj is GH_Group group) { if (group.NickName == groupIdentifier) { - Guid componentguid = group.ObjectIDs[0]; + var componentguid = group.ObjectIDs[0]; - foreach (IGH_DocumentObject obj2 in doc.Objects) { + foreach (var obj2 in doc.Objects) { if (obj2.InstanceGuid == componentguid) { - var param = (IGH_Param)(object)obj2; + var param = (IGH_Param)obj2; Assert.NotNull(param); param.CollectData(); return param; } } + Assert.Fail("Unable to find parameter in group with Nickname " + groupIdentifier); return null; } } } + Assert.Fail("Unable to find group with Nickname " + groupIdentifier); return null; } @@ -106,8 +109,9 @@ public static void TestGHPrimitives(IGH_Param param, object expected) { } } - public static void TestNoRuntimeMessagesInDocument(GH_Document doc, GH_RuntimeMessageLevel runtimeMessageLevel, string exceptComponentNamed = "") { - foreach (IGH_DocumentObject obj in doc.Objects) { + public static void TestNoRuntimeMessagesInDocument( + GH_Document doc, GH_RuntimeMessageLevel runtimeMessageLevel, string exceptComponentNamed = "") { + foreach (var obj in doc.Objects) { if (obj is GH_Component comp) { comp.CollectData(); comp.Params.Output[0].CollectData(); diff --git a/IntegrationTests/IntegrationTests.csproj b/IntegrationTests/IntegrationTests.csproj index 919524d..70cb688 100644 --- a/IntegrationTests/IntegrationTests.csproj +++ b/IntegrationTests/IntegrationTests.csproj @@ -3,11 +3,12 @@ net48 x64 x64 + 8 - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -18,7 +19,7 @@ - + @@ -26,10 +27,10 @@ - + - + diff --git a/addAdSecReference.ps1 b/addAdSecReference.ps1 new file mode 100644 index 0000000..cd0ae54 --- /dev/null +++ b/addAdSecReference.ps1 @@ -0,0 +1,6 @@ +$relevantPath = "AdSecGH\bin\x64\Debug\net48" +$absolutePath = Resolve-Path $relevantPath + +$destinationDir = "$env:APPDATA\Grasshopper\Libraries" + +echo $absolutePath > "$destinationDir\AdSecGHTests.ghlink" diff --git a/removeAdSecReference.ps1 b/removeAdSecReference.ps1 new file mode 100644 index 0000000..f67eafd --- /dev/null +++ b/removeAdSecReference.ps1 @@ -0,0 +1,6 @@ +$relevantPath = "AdSecGH\bin\x64\Debug\net48" +$absolutePath = Resolve-Path $relevantPath + +$destinationDir = "$env:APPDATA\Grasshopper\Libraries" + +rm "$destinationDir\AdSecGHTests.ghlink"