PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Grundy/Grundy.Licensing.Server.Tests/FeatureIdentificationKeyMatchScoreEvaluatorTests.cs

#
C# | 103 lines | 87 code | 16 blank | 0 comment | 0 complexity | cf6edbbf881b51ae4d209060933dbaee MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using FluentAssertions;
  3. using Grundy.Common;
  4. using Grundy.Entity;
  5. using Grundy.Message;
  6. using Microsoft.VisualStudio.TestTools.UnitTesting;
  7. namespace Grundy.Licensing.Server.Tests
  8. {
  9. [TestClass]
  10. public class FeatureIdentificationKeyMatchScoreEvaluatorTests
  11. {
  12. private FeatureIdentificationKeyMatchScoreEvaluator evaluator;
  13. [TestInitialize]
  14. public void Setup()
  15. {
  16. evaluator = new FeatureIdentificationKeyMatchScoreEvaluator();
  17. }
  18. [TestMethod]
  19. public void Should_return_0_for_null_fik()
  20. {
  21. var fik1 = FeatureIdentificationKey.Null;
  22. var fik2 = FeatureIdentificationKey.Null;
  23. evaluator.GetMatchScore(fik1, fik2).Should().Be(0);
  24. }
  25. [TestMethod]
  26. public void Should_return_less_than_0_for_none_matching()
  27. {
  28. var fik1 = new FeatureIdentificationKey{LicenseEntitlementId = Guid.NewGuid()};
  29. var fik2 = new FeatureIdentificationKey{LicenseEntitlementId = Guid.NewGuid()};
  30. evaluator.GetMatchScore(fik1, fik2).Should().BeLessOrEqualTo(0);
  31. }
  32. [TestMethod]
  33. public void Should_return_1_for_feature_matching_but_something_else_a_is_not_default_and_b_is_default()
  34. {
  35. var featureId = Guid.NewGuid();
  36. var fik1 = new FeatureIdentificationKey { FeatureId = featureId, LicenseEntitlementId = Guid.NewGuid()};
  37. var fik2 = new FeatureIdentificationKey { FeatureId = featureId };
  38. evaluator.GetMatchScore(fik1, fik2).Should().Be(1);
  39. fik1 = new FeatureIdentificationKey { FeatureName = "F1", LicenseEntitlementId = Guid.NewGuid() };
  40. fik2 = new FeatureIdentificationKey{FeatureName = "F1"};
  41. evaluator.GetMatchScore(fik1, fik2).Should().Be(1);
  42. }
  43. [TestMethod]
  44. public void Should_return_less_than_0_for_feature_matching_but_something_else_different_and_not_default()
  45. {
  46. var featureId = Guid.NewGuid();
  47. var fik1 = new FeatureIdentificationKey { FeatureName = "F1", FeatureId = Guid.NewGuid(), LicenseEntitlementId = Guid.NewGuid() };
  48. var fik2 = new FeatureIdentificationKey { FeatureName = "F1", FeatureId = Guid.NewGuid() };
  49. evaluator.GetMatchScore(fik1, fik2).Should().BeNegative();
  50. fik1 = new FeatureIdentificationKey { FeatureName = "F1A", FeatureId = featureId, LicenseEntitlementId = Guid.NewGuid() };
  51. fik2 = new FeatureIdentificationKey { FeatureName = "F1B", FeatureId = featureId };
  52. evaluator.GetMatchScore(fik1, fik2).Should().BeNegative();
  53. }
  54. [TestMethod]
  55. public void Should_return_greater_than_0_for_feature_matching()
  56. {
  57. var featureId = Guid.NewGuid();
  58. var fik1 = new FeatureIdentificationKey { FeatureId = featureId };
  59. var fik2 = new FeatureIdentificationKey { FeatureId = featureId };
  60. evaluator.GetMatchScore(fik1, fik2).Should().BeGreaterThan(0);
  61. fik1 = new FeatureIdentificationKey { FeatureName = "F1" };
  62. fik2 = new FeatureIdentificationKey { FeatureName = "F1" };
  63. evaluator.GetMatchScore(fik1, fik2).Should().BeGreaterThan(0);
  64. fik1 = new FeatureIdentificationKey { FeatureName = "F1", FeatureId = featureId };
  65. fik2 = new FeatureIdentificationKey { FeatureName = "F1", FeatureId = featureId };
  66. evaluator.GetMatchScore(fik1, fik2).Should().BeGreaterThan(0);
  67. }
  68. [TestMethod]
  69. public void Should_return_2()
  70. {
  71. var id1 = Guid.NewGuid();
  72. var id2 = Guid.NewGuid();
  73. var fik1 = new FeatureIdentificationKey { FeatureId = id1, LicenseEntitlementId = id2};
  74. var fik2 = new FeatureIdentificationKey { FeatureId = id1, LicenseEntitlementId = id2};
  75. evaluator.GetMatchScore(fik1, fik2).Should().Be(2);
  76. fik1 = new FeatureIdentificationKey { FeatureName = "F1", ProductId = id1 };
  77. fik2 = new FeatureIdentificationKey { FeatureName = "F1", ProductId = id1};
  78. evaluator.GetMatchScore(fik1, fik2).Should().Be(2);
  79. fik1 = new FeatureIdentificationKey { FeatureName = "F1", ProductName = "P1" };
  80. fik2 = new FeatureIdentificationKey { FeatureName = "F1", ProductName = "P1"};
  81. evaluator.GetMatchScore(fik1, fik2).Should().Be(2);
  82. fik1 = new FeatureIdentificationKey { FeatureName = "F1", LicenseName = "L1" };
  83. fik2 = new FeatureIdentificationKey { FeatureName = "F1", LicenseName = "L1" };
  84. evaluator.GetMatchScore(fik1, fik2).Should().Be(2);
  85. }
  86. }
  87. }