PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Grundy/Grundy.Entity.Tests/LicenseManagerTests.cs

#
C# | 64 lines | 57 code | 7 blank | 0 comment | 0 complexity | 0a1f5f1aacdfab671daae05cd13b9ae2 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using Grundy.Common;
  6. using Grundy.CryptographicServices;
  7. using Grundy.Message;
  8. using Grundy.TestHelpers;
  9. using Microsoft.VisualStudio.TestTools.UnitTesting;
  10. using FluentAssertions;
  11. namespace Grundy.Entity.Tests
  12. {
  13. [TestClass]
  14. public class LicenseManagerTests
  15. {
  16. private CryptographicServicesProvider cryptographicServicesProvider;
  17. private ObjectMother _objectMother = new ObjectMother();
  18. [TestInitialize]
  19. public void Setup()
  20. {
  21. var provider = new RSACryptoServiceProvider();
  22. var aliceKeyPair = provider.ToXmlString(true);
  23. var alicePublicKey = provider.ToXmlString(false);
  24. cryptographicServicesProvider = new RsaProvider(aliceKeyPair);
  25. }
  26. [TestMethod]
  27. public void Should_Create_License_For_Entitlement()
  28. {
  29. var customerEntitlement = _objectMother.GetCustomerEntitlement(new List<LicenseEntitlement>
  30. {
  31. _objectMother.GetLicenseEntitlement(_objectMother.GetProduct("Product Name 1", new [] {"Feature1", "Feature2"}),_objectMother.GetCountedFloatingLicense(12345)),
  32. _objectMother.GetLicenseEntitlement(_objectMother.GetProduct("Product Name 2", new string[] {"Feature1", "Feature2"}), _objectMother.GetNodeLockedLicense())
  33. }, _objectMother.GetCustomer("Ashish Sharma"));
  34. var licenseManager = new LicenseManager(cryptographicServicesProvider);
  35. var license = licenseManager.CreateLicenseForEntitlement(customerEntitlement);
  36. license.Payload.Should().NotBeBlank();
  37. license.Signature.Should().NotBeBlank();
  38. license.Provider.Should().NotBeBlank();
  39. license.Algorithm.Should().NotBeBlank();
  40. }
  41. [TestMethod]
  42. public void Should_Create_Entitlement_For_License()
  43. {
  44. var customerEntitlement = _objectMother.GetCustomerEntitlement(new List<LicenseEntitlement>
  45. {
  46. _objectMother.GetLicenseEntitlement(_objectMother.GetProduct("Product Name 1", new [] {"Feature1", "Feature2"}),_objectMother.GetCountedFloatingLicense(12345)),
  47. _objectMother.GetLicenseEntitlement(_objectMother.GetProduct("Product Name 2", new [] {"Feature1", "Feature2"}), _objectMother.GetNodeLockedLicense())
  48. }, _objectMother.GetCustomer("Ashish Sharma"));
  49. var licenseManager = new LicenseManager(cryptographicServicesProvider);
  50. var licenseForEntitlement = licenseManager.CreateLicenseForEntitlement(customerEntitlement);
  51. var entitlement = licenseManager.CreateCustomerEntitlementFromLicense(licenseForEntitlement);
  52. entitlement.Should().NotBeNull();
  53. entitlement.Customer.Name.Should().Be("Ashish Sharma");
  54. entitlement.LicenseEntitlements.Count().Should().Be(2);
  55. }
  56. }
  57. }