Ejemplo n.º 1
0
 public async void WhenATodoIsAddedToTheUserWithTheTargetDateOfX(string date)
 {
     _todo = await _todoService.AddTodo(new AddTodoRequest()
     {
         UserId = _user.Id, Title = "test todo", TargetDate = DateTime.Parse(date), Text = "test todo body"
     });
 }
Ejemplo n.º 2
0
        void AppBarButton_Click_1(object sender, RoutedEventArgs e)
        {
            var start        = new DateTime(datepic.Date.Year, datepic.Date.Month, datepic.Date.Day, timepic.Time.Hours, timepic.Time.Minutes, timepic.Time.Seconds);
            int notiftStatus = 0;

            if (rbs.IsChecked == true)
            {
                notiftStatus = 0;
            }

            if (rbn.IsChecked == true)
            {
                notiftStatus = 1;
            }

            if (rba.IsChecked == true)
            {
                notiftStatus = 2;
            }
            var todo = new Todo()
            {
                Subject   = Title.Text,
                Detail    = Details.Text,
                StartTime = start,
                Notify    = notiftStatus,
                Status    = 2
            };

            TodoService.AddTodo(todo);
            Frame.GoBack();
        }
        public void AddTodo_TitleIsDuplicate_ExceptionThrown()
        {
            var now     = DateTime.Now;
            var unique  = Guid.NewGuid();
            var builder = new DbContextOptionsBuilder <DataContext>().UseSqlServer("Server=.;Database=SimpleTodo;Trusted_Connection=True;MultipleActiveResultSets=true");

            // arrange data
            using (var context = new DataContext(builder.Options))
            {
                context.TodoItems.Add(new TodoItem
                {
                    DueDate = now.AddDays(3),
                    IsDone  = false,
                    Title   = "TitleIsDuplicate_" + unique
                });
                context.SaveChanges();
            }

            // act
            using (var context = new DataContext(builder.Options))
            {
                var service = new TodoService(context);
                Assert.Throws <InvalidOperationException>(() => service.AddTodo(new TodoDto
                {
                    Title   = "TitleIsDuplicate_" + unique,
                    DueDate = DateTime.Now,
                    IsDone  = false
                }));
            }
        }
Ejemplo n.º 4
0
        public void AddTodo_DefaultIsDone_False()
        {
            // explain data. this test will fail if we ran the AddTodo_ItemIs11thItemForToday_ExceptionThrown test
            var now     = DateTime.Now;
            var unique  = Guid.NewGuid();
            var builder = new DbContextOptionsBuilder <DataContext>().UseSqlServer("Server=.;Database=SimpleTodo;Trusted_Connection=True;MultipleActiveResultSets=true");


            // act
            using (var context = new DataContext(builder.Options))
            {
                var service = new TodoService(context, new StubNotificationService());
                service.AddTodo(new TodoDto
                {
                    Title   = "DefaultIsDone_" + unique,
                    DueDate = DateTime.Now,
                });
            }

            // arrange data
            using (var context = new DataContext(builder.Options))
            {
                Assert.IsFalse(context.TodoItems.Single(ff => ff.Title == "DefaultIsDone_" + unique).IsDone);
            }
        }
Ejemplo n.º 5
0
        public void AddTodo_SendsNotification()
        {
            // explain data. this test may fail if we ran the AddTodo_ItemIs11thItemForToday_ExceptionThrown test
            var now               = DateTime.Now;
            var unique            = Guid.NewGuid();
            var builder           = new DbContextOptionsBuilder <DataContext>().UseSqlServer("Server=.;Database=SimpleTodo;Trusted_Connection=True;MultipleActiveResultSets=true");
            var mockNotifyService = new MockNotificationService();

            // explain this deletion
            using (var context = new DataContext(builder.Options))
            {
                context.TodoItems.RemoveRange(context.TodoItems);
                context.SaveChanges();
            }
            // arrange
            using (var context = new DataContext(builder.Options))
            {
                var service = new TodoService(context, mockNotifyService);
                service.AddTodo(new TodoDto
                {
                    Title   = "AddTodo_SendsNotification_" + unique,
                    DueDate = DateTime.Now.AddDays(1),
                });
            }

            // assert
            Assert.IsTrue(mockNotifyService.NotifyAddTodoItem_CalledOnce);
        }
Ejemplo n.º 6
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var start = datepic.Value;

            if (Title.Text == "")
            {
                ErrorText.Text = "Please set a title for this alarm.";
                return;
            }


            if (start < DateTime.Now)
            {
                ErrorText.Text = "Can't set a time in past.";
                return;
            }
            var todo = new Todo()
            {
                Subject   = Title.Text,
                Detail    = Details.Text,
                StartTime = start,
                Notify    = 0,
                Status    = 2
            };

            _service.AddTodo(todo);

            MainPage.current._NavigationFrame.Navigate(new TodoList());
        }
        public void AddTodo_ItemIs11thItemForToday_ExceptionThrown()
        {
            var now     = DateTime.Now;
            var builder = new DbContextOptionsBuilder <DataContext>().UseSqlServer("Server=.;Database=SimpleTodo;Trusted_Connection=True;MultipleActiveResultSets=true");

            // arrange data
            using (var context = new DataContext(builder.Options))
            {
                for (int i = 0; i <= 10; i++)
                {
                    context.TodoItems.Add(new TodoItem
                    {
                        DueDate      = now.AddDays(3),
                        IsDone       = false,
                        Title        = "ItemIs11thItemForToday_" + i,
                        CreationDate = now
                    });
                }
                context.SaveChanges();
            }

            // act
            using (var context = new DataContext(builder.Options))
            {
                var service = new TodoService(context);
                Assert.Throws <InvalidOperationException>(() => service.AddTodo(new TodoDto
                {
                    Title   = "ItemIs11thItemForToday_" + Guid.NewGuid(),
                    DueDate = DateTime.Now,
                    IsDone  = false
                }));
            }
        }
Ejemplo n.º 8
0
        void AppBarButton_Click_1(object sender, RoutedEventArgs e)
        {
            var start = new DateTime(datepic.Date.Year, datepic.Date.Month, datepic.Date.Day, timepic.Time.Hours, timepic.Time.Minutes, timepic.Time.Seconds);

            if (Title.Text == "")
            {
                ErrorText.Text = "Please set a title for this alarm.";
                return;
            }


            if (start < DateTime.Now)
            {
                ErrorText.Text = "Can't set a time in past.";
                return;
            }


            int notiftStatus = 0;

            if (rbs.IsChecked == true)
            {
                notiftStatus = 0;
            }

            if (rbn.IsChecked == true)
            {
                notiftStatus = 1;
            }

            if (rba.IsChecked == true)
            {
                notiftStatus = 2;
            }
            var todo = new Todo()
            {
                Subject   = Title.Text,
                Detail    = Details.Text,
                StartTime = start,
                Notify    = notiftStatus,
                Status    = 2
            };

            if (editmode)
            {
                todo.Id = editing.Id;
                _service.Edit(editing, todo);
            }
            else
            {
                _service.AddTodo(todo);
            }
            Frame.GoBack();
            this.Publish(new Classes.Header("Timeline"));
        }
Ejemplo n.º 9
0
 public async Task <IActionResult> AddTodo([FromBody] AddTodoRequest request)
 {
     try
     {
         return(Ok(await _todoService.AddTodo(request)));
     }
     catch (Exception e)
     {
         return(Problem(e.Message));
     }
 }
Ejemplo n.º 10
0
        public IActionResult Create(TodoDto model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var service = new TodoService(context);

            service.AddTodo(model);
            return(RedirectToAction("List"));
        }
        public void AddTodo_TitleIsEmpty_ExceptionThrown()
        {
            var builder = new DbContextOptionsBuilder <DataContext>().UseSqlServer("Server=.;Database=SimpleTodo;Trusted_Connection=True;MultipleActiveResultSets=true");

            using (var context = new DataContext(builder.Options))
            {
                var service = new TodoService(context);
                Assert.Throws <InvalidOperationException>(() => service.AddTodo(new TodoDto
                {
                    Title   = "",
                    DueDate = DateTime.Now,
                    IsDone  = false
                }));
            }
        }
Ejemplo n.º 12
0
        public void MigrateTodos()
        {
            var todos = GetTodos();

            foreach (var todo in todos)
            {
                _svc.AddTodo(new Todo()
                {
                    Detail    = todo.detail,
                    Notify    = todo.notify,
                    StartTime = todo.time,
                    Status    = ConvertToNewIsdone(todo.isdone),
                    Subject   = todo.title
                });
            }


            File.Delete(SQLPath);
        }
Ejemplo n.º 13
0
 public IActionResult Add(string title, int id)
 {
     TodoService.AddTodo(title, id);
     return(RedirectToAction("List"));
 }
Ejemplo n.º 14
0
        public IActionResult Post([FromBody] TodoModel Todo)
        {
            var created = TodoService.AddTodo(Mapper.Map <MakeYourJournal.DAL.Entities.Todo>(Todo));

            return(Ok(Mapper.Map <TodoModel>(created)));
        }
Ejemplo n.º 15
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("Hello From Quick actions bg");
            _deferal = taskInstance.GetDeferral();
            taskInstance.Canceled       += TaskInstance_Canceled;
            taskInstance.Task.Completed += Task_Completed;
            var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;

            if (details != null)
            {
                try
                {
                    string         arguments = details.Argument;
                    var            userInput = details.UserInput;
                    string         title     = (string)userInput["title"];
                    string         detail    = (string)userInput["detail"];
                    var            notify    = (byte)int.Parse(userInput["notification"].ToString());
                    var            Time      = int.Parse(userInput["snoozeTime"].ToString());
                    DateTimeOffset now       = DateTimeOffset.Now;

                    if (Time == 15)
                    {
                        DateTime nulll = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
                        now = now.AddMinutes(15);
                    }
                    else if (Time == 60)
                    {
                        DateTime nulll = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
                        now.AddHours(1);
                    }
                    else if (Time == 140)
                    {
                        DateTime nulll = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
                        now.AddHours(4);
                    }
                    else if (Time == 160)
                    {
                        DateTime nulll = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
                        now.AddHours(8);
                    }
                    else if (Time == 190)
                    {
                        DateTime nulll = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
                        now.AddDays(1);
                    }
                    DateTime pocker = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);

                    var todo = new Todo()
                    {
                        Subject   = title,
                        Detail    = detail,
                        StartTime = pocker,
                        Notify    = notify,
                        Status    = 2
                    };

                    _service.AddTodo(todo);
                }
                catch (Exception ex) { }
                try
                {
                    Update();
                }
                catch
                {
                }
            }
            _deferal.Complete();
        }
Ejemplo n.º 16
0
        public IActionResult AddTodo([FromBody] TodoItem todo)
        {
            var id = _todoService.AddTodo(todo);

            return(CreatedAtAction(nameof(GetTodo), new { id }, todo));
        }
 public Todo PostTodo([FromBody] Todo todo)
 {
     return(todoService.AddTodo(todo));
 }
Ejemplo n.º 18
0
 public IActionResult Add(Todo todoFromForm)
 {
     TodoService.AddTodo(todoFromForm);
     return(RedirectToAction("listTodos"));
 }