예제 #1
0
        public async Task ReturnSuccess_ForMarkDone()
        {
            // Arrange
            var mockTodoItemService = Substitute.For <ITodoItemService>();
            var mockUserManager     = MockUserManager.Create();

            // Make the mockUserManager return a fake user
            var fakeUser = new ApplicationUser();

            mockUserManager.GetUserAsync(Arg.Any <ClaimsPrincipal>())
            .Returns(Task.FromResult(fakeUser));

            // Make the mockTodoItemService always succeed
            mockTodoItemService.MarkDoneAsync(Arg.Any <Guid>(), Arg.Any <ApplicationUser>())
            .Returns(Task.FromResult(true));

            var controller = new TodoController(mockTodoItemService, mockUserManager);

            // Act
            var randomId = Guid.NewGuid();
            var result   = await controller.MarkDone(randomId);

            var redirectResult = result as RedirectToActionResult;

            // Assert
            Assert.NotNull(redirectResult);
            Assert.Equal("Index", redirectResult.ActionName);
        }
예제 #2
0
        public async Task ReturnBadRequest_ForMarkDoneWithBadId()
        {
            // Arrange
            var mockTodoItemService = Substitute.For <ITodoItemService>();
            var mockUserManager     = MockUserManager.Create();

            var controller = new TodoController(mockTodoItemService, mockUserManager);

            // Act
            var result = await controller.MarkDone(Guid.Empty);

            var statusCodeResult = result as StatusCodeResult;

            // Assert
            Assert.NotNull(statusCodeResult);
            Assert.Equal(400, statusCodeResult.StatusCode);
        }
예제 #3
0
        public async Task ReturnBadRequest_ForMarkDoneWithBadId()
        {
            // Arrange
            var mockTodoItemService = Substitute.For <ITodoItemService>();
            var mockUserManager     = MockUserManager.Create();

            var controller = new TodoController(mockTodoItemService, mockUserManager);

            // Act
            var result = await controller.MarkDone(Guid.Empty);

            var redirectResult = result as RedirectToActionResult;

            // Assert
            Assert.NotNull(redirectResult);
            Assert.Equal("Index", redirectResult.ActionName);
        }
예제 #4
0
        public async Task ReturnUnauthorized_ForMarkDoneWithNoUser()
        {
            // Arrange
            var mockTodoItemService = Substitute.For <ITodoItemService>();
            var mockUserManager     = MockUserManager.Create();

            // Make the mockUserManager always return null for GetUserAsync
            mockUserManager.GetUserAsync(Arg.Any <ClaimsPrincipal>())
            .Returns(Task.FromResult <ApplicationUser>(null));

            var controller = new TodoController(mockTodoItemService, mockUserManager);

            // Act
            var randomId = Guid.NewGuid();
            var result   = await controller.MarkDone(randomId);

            var redirectResult = result as RedirectToActionResult;

            // Assert
            Assert.NotNull(redirectResult);
            Assert.Equal("Index", redirectResult.ActionName);
        }
예제 #5
0
 public TodoControllerTests()
 {
     mockTodoItemService = new Mock <ITodoItemService>();
     mockCategoryService = new Mock <ICategoryService>();
     mockUserManager     = MockUserManager.Create();
 }