Beispiel #1
0
        public async Task UnregisterTaskReturnsCorrectStatus()
        {
            const string status = "status";

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <TaskUnenrollCommand>())).ReturnsAsync(new TaskUnenrollResult {
                Status = status
            });

            var userManager = MockHelper.CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(It.IsAny <ClaimsPrincipal>())).Returns(It.IsAny <string>());

            var sut = new TaskApiController(mediator.Object, null, userManager.Object);

            sut.SetDefaultHttpContext();

            var jsonResult = await sut.UnregisterTask(It.IsAny <int>());

            var result = jsonResult.GetValueForProperty <string>("Status");

            Assert.IsType <JsonResult>(jsonResult);
            Assert.IsType <string>(result);
            Assert.Equal(result, status);
        }
Beispiel #2
0
        public async Task UnregisterTaskReturnsNullForTaskWhenResultTaskIsNull()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <TaskUnenrollCommand>())).ReturnsAsync(new TaskUnenrollResult());

            var sut = new TaskApiController(null, mediator.Object, null);

            sut.SetDefaultHttpContext();

            var jsonResult = await sut.UnregisterTask(It.IsAny <int>());

            var result = jsonResult.GetValueForProperty <string>("Task");

            Assert.IsType <JsonResult>(jsonResult);
            Assert.Null(result);
        }
Beispiel #3
0
        public async Task UnregisterTaskSendsTaskUnenrollCommandAsyncWithCorrectTaskIdAndUserId()
        {
            const string userId = "1";
            const int    taskId = 1;

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <TaskUnenrollCommand>())).ReturnsAsync(new TaskUnenrollResult());

            var sut = new TaskApiController(null, mediator.Object, null);

            sut.SetFakeUser(userId);

            await sut.UnregisterTask(taskId);

            mediator.Verify(x => x.SendAsync(It.Is <TaskUnenrollCommand>(y => y.TaskId == taskId && y.UserId == userId)));
        }
Beispiel #4
0
        public async Task UnregisterTaskSendsTaskUnenrollCommandWithCorrectTaskIdAndUserId()
        {
            const string userId = "1";
            const int    taskId = 1;

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <TaskUnenrollCommand>())).ReturnsAsync(new TaskUnenrollResult());

            var userManager = MockHelper.CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(It.IsAny <ClaimsPrincipal>())).Returns(userId);

            var sut = new TaskApiController(mediator.Object, null, userManager.Object);

            sut.SetFakeUser(userId);

            await sut.UnregisterTask(taskId);

            mediator.Verify(x => x.SendAsync(It.Is <TaskUnenrollCommand>(y => y.TaskId == taskId && y.UserId == userId)));
        }
Beispiel #5
0
        public async Task UnregisterTaskReturnsNullForTaskWhenResultTaskIsNull()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <VolunteerTaskUnenrollCommand>())).ReturnsAsync(new VolunteerTaskUnenrollResult());

            var userManager = UserManagerMockHelper.CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(It.IsAny <ClaimsPrincipal>())).Returns(It.IsAny <string>());

            var sut = new TaskApiController(mediator.Object, null, userManager.Object);

            sut.SetDefaultHttpContext();

            var jsonResult = await sut.UnregisterTask(It.IsAny <int>());

            var result = jsonResult.GetValueForProperty <string>("Task");

            Assert.IsType <JsonResult>(jsonResult);
            Assert.Null(result);
        }