You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.9 KiB

  1. // Copyright (c) 2020 Daniel Grunwald
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
  20. using NUnit.Framework;
  21. namespace ICSharpCode.Decompiler.Tests
  22. {
  23. [TestFixture]
  24. public sealed class TargetFrameworkTests
  25. {
  26. [TestCase(-1)]
  27. [TestCase(0)]
  28. [TestCase(1)]
  29. [TestCase(99)]
  30. [TestCase(int.MinValue)]
  31. public void VerifyThrowsForInvalidVersion(int invalidVersion)
  32. {
  33. // Arrange - nothing
  34. // Act
  35. void CreateInstance() => new TargetFramework(identifier: null, invalidVersion, profile: null);
  36. // Assert
  37. Assert.Throws<ArgumentException>(CreateInstance);
  38. }
  39. [TestCase(100, "v1.0")]
  40. [TestCase(102, "v1.0.2")]
  41. [TestCase(130, "v1.3")]
  42. [TestCase(145, "v1.4.5")]
  43. [TestCase(1670, "v16.7")]
  44. [TestCase(1800, "v18.0")]
  45. public void VerifyVersion(int version, string expectedVersion)
  46. {
  47. // Arrange - nothing
  48. // Act
  49. var targetFramework = new TargetFramework(identifier: null, version, profile: null);
  50. // Assert
  51. Assert.AreEqual(version, targetFramework.VersionNumber);
  52. Assert.AreEqual(expectedVersion, targetFramework.VersionString);
  53. }
  54. [Test]
  55. public void VerifyPortableLibrary()
  56. {
  57. // Arrange
  58. const string identifier = ".NETPortable";
  59. // Act
  60. var targetFramework = new TargetFramework(identifier, 100, profile: null);
  61. // Assert
  62. Assert.IsTrue(targetFramework.IsPortableClassLibrary);
  63. Assert.AreEqual(identifier, targetFramework.Identifier);
  64. }
  65. [Test]
  66. [Pairwise]
  67. public void VerifyIdentifierAndProfile(
  68. [Values(null, "", ".NETFramework")] string identifier,
  69. [Values(null, "", ".Client")] string profile)
  70. {
  71. // Arrange - nothing
  72. // Act
  73. var targetFramework = new TargetFramework(identifier, 100, profile);
  74. // Assert
  75. Assert.AreEqual(identifier, targetFramework.Identifier);
  76. Assert.AreEqual(profile, targetFramework.Profile);
  77. }
  78. [TestCase(null, 350, "net35")]
  79. [TestCase(".NETFramework", 350, "net35")]
  80. [TestCase(".NETFramework", 400, "net40")]
  81. [TestCase(".NETFramework", 451, "net451")]
  82. [TestCase(".NETCoreApp", 200, "netcoreapp2.0")]
  83. [TestCase(".NETCoreApp", 310, "netcoreapp3.1")]
  84. [TestCase(".NETStandard", 130, "netstandard1.3")]
  85. [TestCase(".NETStandard", 200, "netstandard2.0")]
  86. [TestCase("Silverlight", 400, "sl4")]
  87. [TestCase("Silverlight", 550, "sl5")]
  88. [TestCase(".NETCore", 450, "netcore45")]
  89. [TestCase(".NETCore", 451, "netcore451")]
  90. [TestCase("WindowsPhone", 700, "wp7")]
  91. [TestCase("WindowsPhone", 810, "wp81")]
  92. [TestCase(".NETMicroFramework", 100, "netmf")]
  93. [TestCase(".NETMicroFramework", 210, "netmf")]
  94. [TestCase(".NETPortable", 100, null)]
  95. [TestCase("Unsupported", 100, null)]
  96. public void VerifyMoniker(string identifier, int version, string expectedMoniker)
  97. {
  98. // Arrange - nothing
  99. // Act
  100. var targetFramework = new TargetFramework(identifier, version, profile: null);
  101. // Assert
  102. Assert.AreEqual(expectedMoniker, targetFramework.Moniker);
  103. }
  104. }
  105. }