public async Task UnregisterActivityPublishesUserUnenrollsWithCorrectData() { const int activityId = 1; const string applicationUserId = "applicationUserId"; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.Send(It.IsAny<ActivitySignupByActivityIdAndUserIdQuery>())) .Returns(new ActivitySignup { Activity = new Activity { Id = activityId }, User = new ApplicationUser { Id = applicationUserId }}); var controller = new ActivityApiController(mediator.Object); controller.SetDefaultHttpContext(); await controller.UnregisterActivity(activityId); mediator.Verify(mock => mock.PublishAsync(It.Is<UserUnenrolls>(ue => ue.ActivityId == activityId && ue.UserId == applicationUserId)), Times.Once); }
public async Task UnregisterActivitySendsDeleteActivityAndTaskSignupsCommandAsyncWithCorrectActivitySignupId() { const int activityId = 1; const int activitySignupId = 1; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.Send(It.IsAny<ActivitySignupByActivityIdAndUserIdQuery>())) .Returns(new ActivitySignup { Id = activitySignupId, Activity = new Activity(), User = new ApplicationUser() }); var controller = new ActivityApiController(mediator.Object); controller.SetDefaultHttpContext(); await controller.UnregisterActivity(activityId); mediator.Verify(x => x.SendAsync(It.Is<DeleteActivityAndTaskSignupsCommandAsync>(y => y.ActivitySignupId == activitySignupId))); }
public async Task UnregisterActivityReturnsHttpNotFoundWhenUnableToGetActivitySignupByActivitySignupIdAndUserId() { var controller = new ActivityApiController(Mock.Of<IMediator>()); controller.SetDefaultHttpContext(); var result = await controller.UnregisterActivity(It.IsAny<int>()); Assert.IsType<HttpNotFoundResult>(result); }