示例#1
0
        public async Task TestDelete()
        {
            using (var context = new SocialBackendContext(options))
            {
                // Given
                i = 0;                                                                                                            // exisiting user
                var dbTodo = await context.Todo.AsNoTracking().Where(t => t.user.username == usernames[i]).FirstOrDefaultAsync(); // existing todo

                //When
                ICookieService   fakeCookie     = new FakeCookieService();
                TodoesController todoController = new TodoesController(context, fakeCookie);
                var result = await todoController.DeleteTodo(dbTodo.id) as IActionResult;

                // Then
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(OkObjectResult));
                Assert.AreEqual(1, context.Todo.Count());
                Assert.AreEqual(2, context.User.Count());

                var okObject    = result as OkObjectResult;
                var deletedItem = okObject.Value as Todo;

                Assert.AreEqual(dbTodo.id, deletedItem.id);
                Assert.AreEqual(dbTodo.task, deletedItem.task);
                Assert.AreEqual(dbTodo.complete, deletedItem.complete);
                Assert.AreEqual(dbTodo.dueDate, deletedItem.dueDate);
            }
        }
示例#2
0
        public async Task TestNullCookieDelete()
        {
            using (var context = new SocialBackendContext(options))
            {
                // Given
                i = 3; //for null cookie

                //When
                ICookieService   fakeCookie     = new FakeCookieService();
                TodoesController todoController = new TodoesController(context, fakeCookie);
                var result = await todoController.DeleteTodo((await context.Todo.AsNoTracking().FirstOrDefaultAsync()).id) as IActionResult;

                // Then
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(UnauthorizedResult));
                Assert.AreEqual(2, context.Todo.Count());
            }
        }
示例#3
0
        public async Task TestDeleteNonDbAuthToken()
        {
            using (var context = new SocialBackendContext(options))
            {
                // Given
                i = 2; //for non existant user with a valid authtoken
                IQueryable <Todo> _todo = from t in context.Todo
                                          orderby t.id descending
                                          select t;
                var dbTodo = await _todo.AsNoTracking().FirstOrDefaultAsync();

                //When
                ICookieService   fakeCookie     = new FakeCookieService();
                TodoesController todoController = new TodoesController(context, fakeCookie);
                var result = await todoController.DeleteTodo(dbTodo.id) as IActionResult;

                // Then
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(UnauthorizedResult));
                Assert.AreEqual(2, context.Todo.Count());
            }
        }
示例#4
0
        public async Task TestDeleteOtherUsersTask()
        {
            using (var context = new SocialBackendContext(options))
            {
                // Given
                i = 0; //for authorised user
                IQueryable <Todo> _todo = from t in context.Todo
                                          orderby t.id descending
                                          select t;
                var dbTodo = await _todo.AsNoTracking().FirstOrDefaultAsync(); // todoItem belonging to different user

                //When
                ICookieService   fakeCookie     = new FakeCookieService();
                TodoesController todoController = new TodoesController(context, fakeCookie);
                var result = await todoController.DeleteTodo(dbTodo.id) as IActionResult;

                // Then
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(UnauthorizedResult));
                Assert.AreEqual(2, context.Todo.Count());
            }
        }