コード例 #1
0
        public void OnActivateCommand_Ok()
        {
            var path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "data", "test.license.xml");

            var service = Substitute.For <ILicenseService>();
            var ctx     = Substitute.For <IApplicationContext>();
            var model   = new LicenseViewModel(service, ctx);

            var license       = License.Load(File.OpenRead(path));
            var licenseResult = new LicenseResult(license, null, null);

            service.RegisterAsync(Arg.Any <Guid>()).Returns(licenseResult);
            service.ValidateAsync(Arg.Any <bool>()).Returns(licenseResult);

            var key = new Guid("D65321D5-B0F9-477D-828A-086F30E2BF89");

            model.RegisterKey = key.ToString();

            model.ActivateCommand.Execute(null);

            service.Received().RegisterAsync(key);
            service.Received().ValidateAsync(Arg.Any <bool>());
            ctx.Received().SetLicenseKeyAsync(key.ToString());
            Assert.Equal(AppLicense.Full, LicenseGlobals.Get());
            Assert.False(model.IsBusy);
        }
コード例 #2
0
        public async void Run_Test()
        {
            var mockHandler = new MockHttpMessageHandler();
            var client      = mockHandler.ToHttpClient();

            var actx  = Substitute.For <IApplicationContext>();
            var appId = Guid.NewGuid().ToString();

            actx.GetAppId().Returns(appId);

            var service = new TestLicenseService(actx, client);
            var path    = service.GetPath();

            service.AppId = "ae8cdf5f-26b3-4e2f-8e68-6ecc2e73720f";

            var dir = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Data", "test.license.xml");

            try
            {
                File.WriteAllText(path, File.ReadAllText(dir));

                await service.RunAsync();

                Assert.Equal(AppLicense.Full, LicenseGlobals.Get());
            }
            finally
            {
                File.Delete(path);
            }
        }
コード例 #3
0
        public void OnActivateCommand_Error()
        {
            var service = Substitute.For <ILicenseService>();
            var ctx     = Substitute.For <IApplicationContext>();
            var model   = new LicenseViewModel(service, ctx);

            var exception  = new Exception("Exception");
            var validation = new[]
            {
                new GeneralValidationFailure
                {
                    Message      = "Message",
                    HowToResolve = "HowToResolve"
                }
            };
            var licenseResult = new LicenseResult(null, exception, validation);

            service.RegisterAsync(Arg.Any <Guid>()).Returns(licenseResult);
            service.ValidateAsync(Arg.Any <bool>()).Returns(licenseResult);

            model.Initialize();

            var key = new Guid("ae8cdf5f-26b3-4e2f-8e68-6ecc2e73720f");

            model.RegisterKey = key.ToString();

            model.ActivateCommand.Execute(null);

            service.Received().RegisterAsync(key);
            ctx.DidNotReceive().SetLicenseKeyAsync(Arg.Any <string>());
            Assert.Equal(AppLicense.Demo, LicenseGlobals.Get());
            Assert.Equal("|Message|HowToResolve|Exception|", model.ErrorMessage.Replace("\r\n", "|"));
            Assert.True(model.ShowError);
            Assert.False(model.IsBusy);
        }
コード例 #4
0
        public async override void Initialize()
        {
            try
            {
                if (IsBusy)
                {
                    return;
                }

                IsBusy = true;

                _key         = Guid.Empty;
                RegisterKey  = null;
                ErrorMessage = null;
                LicenseKey   = null;
                ShowError    = false;
                LicenseGlobals.Set(AppLicense.Demo);
                Description = $"Product Name - {LicenseGlobals.Get()}"; // TODO: localize

                var result = await _licenseService.ValidateAsync(true);

                if (result.Successful)
                {
                    LicenseGlobals.Set(AppLicense.Full);
                    LicenseKey    = result.License.Id.ToString();
                    LicensedTo    = result.License.Customer.Name;
                    ShowActivated = true;
                }
                else
                {
                    ShowLicenseError(result);
                }
                Description = $"Product Name - {LicenseGlobals.Get()}"; // TODO: localize, second time???
            }
            finally
            {
                IsBusy = false;
            }
        }