/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreSdkInstalledConditionTests.cs

https://github.com/directhex/monodevelop · C# · 97 lines · 57 code · 12 blank · 28 comment · 0 complexity · 20ff287949847054b3b2454eeba2a70e MD5 · raw file

  1. //
  2. // DotNetCoreSdkInstalledConditionTests.cs
  3. //
  4. // Author:
  5. // Matt Ward <matt.ward@microsoft.com>
  6. //
  7. // Copyright (c) 2018 Microsoft
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using System;
  27. using System.Linq;
  28. using System.Xml;
  29. using Mono.Addins;
  30. using NUnit.Framework;
  31. namespace MonoDevelop.DotNetCore.Tests
  32. {
  33. [TestFixture]
  34. class DotNetCoreSdkInstalledConditionTests : DotNetCoreVersionsRestorerTestBase
  35. {
  36. [TestCase ("<Condition sdkVersion='2.*' />", "2.1.4", true)]
  37. [TestCase ("<Condition sdkVersion='2.*' />", "2.0.3", true)]
  38. [TestCase ("<Condition sdkVersion='2.*' />", "2.0.0", true)]
  39. [TestCase ("<Condition sdkVersion='2.*' />", "1.0.0", false)]
  40. [TestCase ("<Condition sdkVersion='1.*' />", "1.0.0", true)]
  41. [TestCase ("<Condition sdkVersion='1.*' />", "1.1.0", true)]
  42. [TestCase ("<Condition sdkVersion='2.0' />", "2.1.4", true)]
  43. [TestCase ("<Condition sdkVersion='2.0' />", "2.0.3", true)]
  44. // Here the sdkVersion is the logical version and not the actual version
  45. // .NET Core SDK 2.1.4 supports .NET Core 2.0 so this is treated as the '2.0' SDK.
  46. // .NET Core SDK 2.1.300 supports .NET Core 2.1 so this is treated as '2.1' SDK.
  47. [TestCase ("<Condition sdkVersion='2.0' />", "2.1.3", true)]
  48. [TestCase ("<Condition sdkVersion='2.1' />", "2.1.4", false)]
  49. [TestCase ("<Condition sdkVersion='2.1' />", "2.1.300", true)]
  50. [TestCase ("<Condition sdkVersion='2.1' />", "2.1.301", true)]
  51. [TestCase ("<Condition sdkVersion='2.1' />", "2.1.200", false)]
  52. [TestCase ("<Condition sdkVersion='2.0' />", "2.1.200", true)]
  53. [TestCase ("<Condition sdkVersion='2.1' />", "2.1.299", false)]
  54. [TestCase ("<Condition sdkVersion='2.0' />", "2.1.299", true)]
  55. public void DotNetCoreSdkInstalled (string conditionXml, string sdk, bool expected)
  56. {
  57. DotNetCoreSdksInstalled (new [] { sdk });
  58. bool result = EvaluateCondition (conditionXml);
  59. Assert.AreEqual (expected, result);
  60. }
  61. static bool EvaluateCondition (string conditionXml)
  62. {
  63. var node = new TestConditionNodeElement (conditionXml);
  64. var condition = new DotNetCoreSdkInstalledCondition ();
  65. return condition.Evaluate (node);
  66. }
  67. }
  68. class TestConditionNodeElement : NodeElement
  69. {
  70. XmlElement conditionElement;
  71. public TestConditionNodeElement (string xml)
  72. {
  73. var doc = new XmlDocument ();
  74. doc.LoadXml (xml);
  75. conditionElement = doc.DocumentElement;
  76. }
  77. public string NodeName => "Condition";
  78. public NodeAttribute [] Attributes => throw new NotImplementedException ();
  79. public NodeElementCollection ChildNodes => throw new NotImplementedException ();
  80. public string GetAttribute (string key)
  81. {
  82. return conditionElement.GetAttribute (key);
  83. }
  84. }
  85. }