Ejemplo n.º 1
0
        public void WhenRepositoryIsRestarted_ShouldCreateNewIntervalOnActiveTask()
        {
            var task = new Task {
                IsActive = true
            };

            task.Intervals.Add(new Interval());
            var tasks = new ObservableCollection <Task> {
                task
            };

            _repositoryMock.Setup(mock => mock.GetOpenTasks()).Returns(tasks);

            LifetimeDefinition lifetimeDefinition = Lifetimes.Define("Test.lifetime");
            var viewModel = new TaskViewModel(_repositoryMock.Object, lifetimeDefinition.Lifetime, _settingsRepoMock.Object);

            viewModel.AddTask(task);
            viewModel.ActivateTask(task);

            lifetimeDefinition.Terminate();

            Assert.AreEqual(1, task.Intervals.Count);

            var viewModel2 = new TaskViewModel(_repositoryMock.Object, Lifetimes.Define("Test.lifetime").Lifetime,
                                               _settingsRepoMock.Object);
            var activeTask = viewModel2.ActiveTask;

            Assert.AreEqual(2, activeTask.Intervals.Count);
            Assert.IsTrue(activeTask.Intervals[1].IsActive);
        }
Ejemplo n.º 2
0
        public void WhenTaskIsCreated_FiresTaskCreateEvent()
        {
            _repositoryMock.Setup(mock => mock.AddTask(It.IsAny <Task>())).Returns("ID");
            _repositoryMock.Setup(mock => mock.GetOpenTasks()).Returns(new ObservableCollection <Task>());

            LifetimeDefinition lifetimeDefinition = Lifetimes.Define("Test.lifetime");
            var viewModel = new TaskViewModel(_repositoryMock.Object, lifetimeDefinition.Lifetime, _settingsRepoMock.Object);

            viewModel.TaskChange += OnReceiveEvent;
            var task = new Task()
            {
                Title = "Title"
            };

            viewModel.AddTask(task);

            Assert.AreEqual(TaskAction.Create, _eventArgs.Action);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {

                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

            string DBConnectionString = "Data Source=isostore:/Tasks_v3.sdf";
            bool createDB = false;

            using (TasksDataContext db = new TasksDataContext(DBConnectionString))
            {

                if (db.DatabaseExists() == false)
                {
                    db.CreateDatabase();

                    createDB = true;

                    db.SubmitChanges();
                }
                else
                {
                    //Create the database schema updater
                    DatabaseSchemaUpdater dbUpdate = db.CreateDatabaseSchemaUpdater();

                    //Get database version
                    int dbVersion = dbUpdate.DatabaseSchemaVersion;

                    Debug.WriteLine("Database version " + dbVersion);

                    if (dbVersion == 2)
                    {
                        dbUpdate.DatabaseSchemaVersion = 3;
                        dbUpdate.Execute();
                    }
                }
            }

            App.viewModel = new TaskViewModel(DBConnectionString);

            if (createDB)
            {
                //TODO: Update this with the new database
                //Add default Categorys
                viewModel.All = viewModel.AddCategory(new Category { Name = "All", Parent=null });
                Category health = viewModel.AddCategory(new Category { Name = "Health", Parent = ViewModel.All});
                Category fitness = viewModel.AddCategory(new Category { Name = "Fitness", Parent = health});
                Category organization = viewModel.AddCategory(new Category { Name = "Organization", Parent = ViewModel.All});

                //Add default tasks
                viewModel.AddTask(new Task
                {
                    Name = "Eat 2 servings of fruit",
                    Notes = "",
                    Reward = 5,
                    Category = health,
                    RecurringOption = Task.RecurringOptions.Days,
                    RecurringAmount = 1,
                    When = DateTime.Now.Date.AddSeconds(5),
                    IsComplete = false,
                    HasReminders = false,
                });

                viewModel.AddTask(new Task {
                    Name = "Take vitamins",
                    Notes = "",
                    Reward = 5,
                    Category = health,
                    RecurringOption = Task.RecurringOptions.Days,
                    RecurringAmount = 1,
                    When = DateTime.Now.Date.AddSeconds(5),
                    IsComplete = false,
                    HasReminders = false, });

                viewModel.AddTask(new Task
                {
                    Name = "Cardio",
                    Notes = "",
                    Reward = 5,
                    Category = fitness,
                    RecurringOption = Task.RecurringOptions.Days,
                    RecurringAmount = 1,
                    When = DateTime.Now.Date.AddSeconds(5),
                    IsComplete = false,
                    HasReminders = false,
                });

                viewModel.AddTask(new Task
                {
                    Name = "Weights",
                    Notes = "",
                    Reward = 5,
                    Category = fitness,
                    RecurringOption = Task.RecurringOptions.DaysOfWeek,
                    RecurringAmount = 17,
                    When = DateTime.Now.Date.AddSeconds(5),
                    IsComplete = false,
                    HasReminders = false,
                });

                viewModel.AddTask(new Task
                {
                    Name = "Sport",
                    Notes = "",
                    Reward = 5,
                    Category = fitness,
                    RecurringOption = Task.RecurringOptions.DaysOfWeek,
                    RecurringAmount = 4,
                    When = DateTime.Now.Date.AddSeconds(5),
                    IsComplete = false,
                    HasReminders = false,
                });

                viewModel.AddTask(new Task
                {
                    Name = "Add something to Reward Your Tasks",
                    Notes = "",
                    Reward = 5,
                    Category = organization,
                    RecurringOption = Task.RecurringOptions.Days,
                    RecurringAmount = 1,
                    When = DateTime.Now.Date.AddHours(18),
                    IsComplete = false,
                    HasReminders = true,
                });

                viewModel.AddTask(new Task
                {
                    Name = "Explore Reward Your Tasks",
                    Notes = "",
                    Reward = 15,
                    Category = organization,
                    RecurringOption = Task.RecurringOptions.Never,
                    RecurringAmount = 0,
                    When = DateTime.Now.Date.AddSeconds(5),
                    IsComplete = false,
                    HasReminders = false,
                });

                //Add default rewards
                viewModel.AddReward(new Reward { Name = "Satisfy that sweet tooth", Category = health, PointsPerReward = 40 });
            }

            viewModel.LoadCollectionsWorker.RunWorkerAsync();

            /*
            foreach (Task t in viewModel.AllTasks)
            {
                t.UpdateTask();
            }

            viewModel.AddFromChangedTasks();
            */
        }
Ejemplo n.º 4
0
 private void AddTaskToList(object sender, RoutedEventArgs e) =>
 _taskViewModel.AddTask();
Ejemplo n.º 5
0
 private void CreateTaskRequested()
 {
     _viewModel.AddTask(new Task {
         Title = "New Task"
     });
 }