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); } }
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()); } }
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()); } }
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()); } }