void buttonEnsureSampleData_Click(object sender, EventArgs e)
        {
            this.labelMessage.Text = string.Empty;

            // get...
            string apiKey = this.textApiKey.Text.Trim();
            if (string.IsNullOrEmpty(apiKey))
            {
                this.labelMessage.Text = "You must enter the API key.";
                return;
            }
            string username = this.textUsername.Text.Trim();
            if (string.IsNullOrEmpty(username))
            {
                this.labelMessage.Text = "You must enter the username.";
                return;
            }

            // load the api...
            Entities.ApiUser api = Entities.ApiUser.GetOrCreateApiUser(new Guid(apiKey));
            if(api == null)
                throw new InvalidOperationException("'api' is null.");

            // get the user...
            Entities.User user = Entities.User.GetByUsername(api, username);
            if(user == null)
            {
                this.labelMessage.Text = string.Format("The user '{0}' could not be found.", username);
                return;
            }

            // input...
            JsonData input = new JsonData();
            input["apiKey"] = apiKey;
            input["logonToken"] = Entities.Token.CreateToken(api, user).TheToken;

            // create...
            HandleEnsureTestReports handler = new HandleEnsureTestReports();
            JsonData output = new JsonData();
            handler.DoRequest(input, output);

            // ok...
            if (output.GetValueSafe<bool>("isOk"))
                this.labelMessage.Text = string.Format("Sample data is available for '{0}'.", username);
            else
                this.labelMessage.Text = output.GetValueSafe<string>("error");
        }
Example #2
0
        public void TestEnsureTestReports()
        {
            ResetReports();

            // create some reports..
            User user = this.Creator.CreateUser();

            // check...
            Assert.AreEqual(0, user.GetReports(this).Count<Report>());

            // get...
            HandleEnsureTestReports handler = new HandleEnsureTestReports();
            JsonData output = new JsonData();
            handler.DoRequest(this.CreateJsonData(user), output);

            // check...
            string asString = output.GetValueSafe<string>("reports");
            IList reports = (IList)new JavaScriptSerializer().DeserializeObject(asString);
            Assert.AreEqual(50, reports.Count);
        }