public void ReadQuestionTest()
        {
            Repository.Default.DeleteDatabase();
            Repository.Default.CreateDatabase();

            Category category = new Category();
            category.Name = "bob";
            Category.Save(category);

            Question question = new Question();
            question.Title = "Is Fiona going to the baby?";
            question.Answer = "Yes, of course within seconds";
            question.AskCount = 60;
            question.Category = Category.Read(1);
            question.EasinessFactor = 70.50;
            question.Interval = 80;
            question.LastAsked = DateTime.Today.AddDays(-2);
            question.NextAskOn = DateTime.Today.AddDays(2);
            question.Order = 90;
            question.PreviousInterval = 100;
            question.ResponseQuality = 110;
            Question.Save(question);

            question = Question.Read(1);
            Assert.AreEqual("Is Fiona going to the baby?", question.Title);
            Assert.AreEqual("Yes, of course within seconds", question.Answer);
            Assert.AreEqual(60, question.AskCount);
            Assert.AreEqual(1, question.Category.Id);
            Assert.AreEqual(70.50, question.EasinessFactor);
            Assert.AreEqual(DateTime.Today.AddDays(-2), question.LastAsked);
            Assert.AreEqual(DateTime.Today.AddDays(2), question.NextAskOn);
            Assert.AreEqual(90, question.Order);
            Assert.AreEqual(100, question.PreviousInterval);
            Assert.AreEqual(110, question.ResponseQuality);
        }
        /// <summary>
        /// Creates a new instance of <see cref="AnswerQuestionsController"/>
        /// </summary>
        /// <param name="category"></param>
        public AnswerQuestionsController(Category category)
        {
            _questionIndex = 0;
            _category = category;

            _questions = Question.DueToday(Question.ForCategory(category)).OrderBy(q => q.Order).ToList();

            // Assume it's the first time of asking if there's none due today (todo:test)
            if (_questions.Count < 1)
                _questions = Question.ForCategory(_category).ToList();
        }
        public void AddCategoryTest()
        {
            Repository.Default.DeleteDatabase();
            Repository.Default.CreateDatabase();

            Category category = new Category();
            category.Name = "bob";
            Category.Save(category);

            Assert.AreEqual(1, category.Id);
        }
        public void ReadCategoryTest()
        {
            Repository.Default.DeleteDatabase();
            Repository.Default.CreateDatabase();

            // Create
            Category category = new Category();
            category.Name = "bob";
            Category.Save(category);

            // Read back
            category = Category.Read(1);
            Assert.AreEqual(1, category.Id);
            Assert.AreEqual("bob", category.Name);

            //var s = Category.List(false, "@name", "bob", "@id", 2);
        }
        public void UpdateCategoryTest()
        {
            Repository.Default.DeleteDatabase();
            Repository.Default.CreateDatabase();

            // Create
            Category category = new Category();
            category.Name = "bob";
            Category.Save(category);

            // Update
            category = Category.Read(1);
            category.Name = "bob two";
            Category.Save(category);

            // Read back
            category = Category.Read(1);
            Assert.AreEqual(1, category.Id);
            Assert.AreEqual("bob two", category.Name);
        }
 public void DeleteRow(Category category)
 {
     Categories.Remove(category);
 }
 /// <summary>
 /// Creates a new instance of <see cref="CalendarController"/>
 /// </summary>
 /// <param name="category"></param>
 public CalendarController(Category category)
 {
     _category = category;
 }
Beispiel #8
0
 /// <summary>
 /// Saves the category to the default repository, returning its id.
 /// </summary>
 public static int Save(Category category)
 {
     return Repository.Default.SaveCategory(category);
 }
 /// <summary>
 /// Creates a new instance of <see cref="CategoryHubController"/>
 /// </summary>
 /// <param name="category"></param>
 public CategoryHubController(Category category)
 {
     _category = category;
 }
 /// <summary>
 /// Creates a new instance of <see cref="QuestionsController"/>
 /// </summary>
 /// <param name="category"></param>
 public QuestionsController(Category category)
     : base(UITableViewStyle.Grouped)
 {
     _data = new QuestionsData(category);
     _category = category;
 }
 public QuestionsData(Category category)
 {
     Category = category;
     Questions = Question.ForCategory(category).OrderBy(q => q.Order).ToList();
 }
 public AddEditQuestionController(Question question,Category category)
 {
     // Null means new category
     _question = question;
     _category = category;
 }
Beispiel #13
0
 /// <summary>
 /// Gets a list of all questions for a category from the database repository.
 /// </summary>
 /// <param name="category"></param>
 /// <returns></returns>
 public static IList<Question> ForCategory(Category category)
 {
     return Repository.Default.QuestionsForCategory(category);
 }
        /// <summary>
        /// Sets up all controls on the view.
        /// </summary>
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.GroupTableViewBackgroundColor;

            if (_category == null)
            {
                _category = new Category();
                Title = "Add Category";
            }
            else
            {
                Title = "Edit Category";
            }

            // Name label
            _labelName = new UILabel();
            _labelName.Font = UIFont.BoldSystemFontOfSize(16f);
            _labelName.Text = "Category name";
            _labelName.Frame = new RectangleF(10, 10, 300, 25);
            _labelName.BackgroundColor = UIColor.Clear;
            View.AddSubview(_labelName);

            // Name textbox
            _textFieldName = new UITextField();
            _textFieldName.Text = _category.Name;
            _textFieldName.Frame = new RectangleF(10, 35, 300, 30);
            _textFieldName.BorderStyle = UITextBorderStyle.RoundedRect;
            _textFieldName.ShouldReturn = delegate
            {
                    _textFieldName.ResignFirstResponder();
                    return true;
            };
            View.AddSubview(_textFieldName);

            // Active label
            _labelActive = new UILabel();
            _labelActive.Font = UIFont.BoldSystemFontOfSize(16f);
            _labelActive.Text = "Active";
            _labelActive.Frame = new RectangleF(10, 75, 300, 25);
            _labelActive.BackgroundColor = UIColor.Clear;
            View.AddSubview(_labelActive);

            // Active switch
            _switchActive = new UISwitch();
            _switchActive.On = _category.Active;
            _switchActive.Frame = new RectangleF(10, 105, 300, 25);
            _switchActive.BackgroundColor = UIColor.Clear;
            View.AddSubview(_switchActive);

            // Info label
            _labelInfo = new UILabel();
            _labelInfo.Font = UIFont.SystemFontOfSize(14f);
            _labelInfo.Lines = 3;
            _labelInfo.Text = "Inactive categories aren't counted towards the number of questions due, so don't show "+
                              "on the application's badge on the homescreen.";
            _labelInfo.Frame = new RectangleF(10, 140, 300, 100);
            _labelInfo.TextColor = UIColor.Gray;
            _labelInfo.BackgroundColor = UIColor.Clear;
            View.AddSubview(_labelInfo);

            // Cancel
            _cancelButton = new UIBarButtonItem();
            _cancelButton.Title = "Cancel";
            _cancelButton.Clicked += delegate(object sender, EventArgs e)
            {
                NavigationController.PopViewControllerAnimated(true);
            };

            // Save button
            _saveButton = new UIBarButtonItem();
            _saveButton.Title = "Save";
            _saveButton.Clicked += SaveClick;

            // Hide the navigation bar, back button and toolbar.
            NavigationController.SetToolbarHidden(true, true);
            NavigationItem.HidesBackButton = true;
            NavigationItem.SetLeftBarButtonItem(_cancelButton, false);
            NavigationItem.SetRightBarButtonItem(_saveButton, false);
        }
 /// <summary>
 /// Creates a new instance of <see cref="AddEditCategoryController"/>
 /// </summary>
 /// <param name="category">If null, a new category is created.</param>
 public AddEditCategoryController(Category category)
 {
     _category = category;
 }