Ejemplo n.º 1
0
        public void LicenseContainer_Serialization()
        {
            var hardwareId = Guid.NewGuid().ToString();
            var productId  = Guid.NewGuid().ToString();
            var lic        = new LicenseMock();//, DateTime.UtcNow, DateTime.UtcNow);

            lic.SetHarwareId(hardwareId);
            lic.SetProductId(productId);
            var con = new LicenseContainer
            {
                Signature = "signature"
            }.SetLicense(lic);

            output.WriteLine("ToJson:");
            var json = con.ToJson();

            output.WriteLine(json);

            output.WriteLine("FromJson:");
            var con2  = json.FromJson <LicenseContainer>();
            var json2 = con2.ToJson();

            output.WriteLine(json2);
            Assert.Equal(json, json2);
            Assert.True(con2.LicenseIs <LicenseMock>());
            var lic2 = con2.LicenseAs <LicenseMock>();

            Assert.NotNull(lic2);
            Assert.Equal(lic.HardwareId.Key, lic2.HardwareId.Key);
            Assert.Equal(lic.ProductId.Key, lic2.ProductId.Key);

            //Assert.Equal(con2.LicenseAs<LicenseMock>(), lic);

            var time = new Random((int)DateTime.Now.Ticks).Next(500, 1500);

            output.WriteLine("Time: " + time);
            Thread.Sleep(time);
            output.WriteLine("FromJson timed:");
            var con3  = json.FromJson <LicenseContainer>();
            var json3 = con3.ToJson();

            output.WriteLine(json3);

            Assert.Equal(json, json3);
            Assert.Equal(json2, json3);
            Assert.True(con3.LicenseIs <LicenseMock>());
            var lic3 = con3.LicenseAs <LicenseMock>();

            Assert.NotNull(lic3);
            Assert.Equal(lic.HardwareId.Key, lic3.HardwareId.Key);
            Assert.Equal(lic.ProductId.Key, lic3.ProductId.Key);

            //Assert.Equal(con3.LicenseAs<LicenseMock>(), lic);
        }
Ejemplo n.º 2
0
 public LicenseContainer Request(LicenseRequest request)
 {
     if (request is LicenseRequestMock)
     {
         var req = request as LicenseRequestMock;
         var lic = new LicenseMock();
         lic.SetHarwareId(req.HardwareId);
         lic.SetProductId(req.ProductId);
         return(Sign(lic, Const.FULL_KEY));
     }
     throw new NotSupportedException($"License request of type '{request.GetType().Name}' is not supported by this provider");
 }
Ejemplo n.º 3
0
        public void LicenseContainer_Signing()
        {
            var hardwareId = Guid.NewGuid().ToString();
            var productId  = Guid.NewGuid().ToString();
            var lic        = new LicenseMock();

            lic.SetHarwareId(hardwareId);
            lic.SetProductId(productId);
            var con = LicenseContainer.Sign(lic, Const.FULL_KEY);

            output.WriteLine("ToJson:");
            output.WriteLine(con.ToJson());
            output.WriteLine("License.ToJson:");
            output.WriteLine(con.License.ToJson());
            Assert.True(con.VerifySignature(Const.PUBLIC_KEY));
        }
Ejemplo n.º 4
0
        public void LicenseContainer_Comment()
        {
            var hardwareId = Guid.NewGuid().ToString();
            var productId  = Guid.NewGuid().ToString();
            var lic        = new LicenseMock();

            lic.SetHarwareId(hardwareId);
            lic.SetProductId(productId);
            var con = LicenseContainer.Sign(lic, Const.FULL_KEY);

            con.Comment = "Original comment";
            output.WriteLine("Original ToJson:");
            output.WriteLine(con.ToJson());
            Assert.True(con.VerifySignature(Const.PUBLIC_KEY));
            con.Comment = "Change comment";
            Assert.True(con.VerifySignature(Const.PUBLIC_KEY));
            output.WriteLine("Changed ToJson:");
            output.WriteLine(con.ToJson());
        }