public async Task AddTeamMemberRedirectsToCorrectActionWithCorrectRouteValuesWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin_AndIdOrSelectedTeamMemberIsNotZero() { const int itineraryId = 1; const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.AddTeamMember(itineraryId, 1) as RedirectToActionResult; Assert.Equal(result.ActionName, nameof(ItineraryController.Details)); Assert.Equal(result.RouteValues, new Dictionary<string, object> { ["id"] = itineraryId }); }
public async Task AddTeamMemberDoesNotCallAddTeamMemberCommand_WhenSelectedTeamMemberIsZero() { var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(1); var sut = new ItineraryController(mockMediator.Object, null); sut.SetClaims(new List<Claim> { new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()) }); await sut.AddTeamMember(1, 0); mockMediator.Verify(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>()), Times.Never); }
public async Task AddTeamMemberSendsOrganizationIdQueryWithCorrectItineraryId() { const int itineraryId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(1); var sut = new ItineraryController(mockMediator.Object, null); sut.SetClaims(new List<Claim> { new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()) }); await sut.AddTeamMember(itineraryId, 0); mockMediator.Verify(x => x.SendAsync(It.Is<OrganizationIdQuery>(y => y.ItineraryId == itineraryId)), Times.Once); }
public async Task AddTeamMemberSendsAddTeamMemberCommandWithCorrectParameters() { const int itineraryId = 1; const int selectedTeamMember = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(1); var sut = new ItineraryController(mockMediator.Object, MockSuccessValidation().Object); sut.SetClaims(new List<Claim> { new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()) }); await sut.AddTeamMember(1, 1); mockMediator.Verify(x => x.SendAsync(It.Is<AddTeamMemberCommand>(y => y.ItineraryId == itineraryId && y.TaskSignupId == selectedTeamMember)), Times.Once); }
public async Task AddTeamMemberRedirectsToCorrectActionWithCorrectRouteValuesWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin_AndIdOrSelectedTeamMemberIsNotZero() { const int id = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(1); var sut = new ItineraryController(mockMediator.Object, MockSuccessValidation().Object); sut.SetClaims(new List<Claim> { new Claim(AllReady.Security.ClaimTypes.UserType, UserType.OrgAdmin.ToString()), new Claim(AllReady.Security.ClaimTypes.Organization, "1") }); var result = await sut.AddTeamMember(id, 1) as RedirectToActionResult; Assert.Equal(result.ActionName, nameof(ItineraryController.Details)); Assert.Equal(result.RouteValues, new Dictionary<string, object> { ["id"] = id }); }
public async Task AddTeamMemberDoesNotCallAddTeamMemberCommand_WhenSelectedTeamMemberIsZero() { var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); var sut = new ItineraryController(mockMediator.Object, MockSuccessValidation().Object); await sut.AddTeamMember(1, 0); mockMediator.Verify(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>()), Times.Never); }
public async Task AddTeamMemberCallsAddTeamMemberCommand() { var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); var sut = new ItineraryController(mockMediator.Object, MockSuccessValidation().Object); await sut.AddTeamMember(1, 1); mockMediator.Verify(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>()), Times.Once); }
public async Task AddTeamMemberReturnsCorrectJsonWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin_AndIdOrSelectedTeamMemberIsNotZero() { const int itineraryId = 1; const int orgId = 1; const int teamMemberId = 1; string volunteerEmail = "*****@*****.**"; var mockMediator = new Mock<IMediator>(); var itineraryDetailsViewModel = new ItineraryDetailsViewModel { PotentialTeamMembers = new List<SelectListItem>(), TeamMembers = new List<TeamListViewModel> { new TeamListViewModel {VolunteerEmail = volunteerEmail} } }; mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); mockMediator.Setup(x => x.SendAsync(It.IsAny<ItineraryDetailQuery>())).ReturnsAsync(itineraryDetailsViewModel); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var jsonResult = await sut.AddTeamMember(itineraryId, teamMemberId) as JsonResult; var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess"); var teamMembers = jsonResult.GetValueForProperty<IEnumerable<TeamListViewModel>>("teamMembers").ToList(); var potentialMembers = jsonResult.GetValueForProperty<IEnumerable<SelectListItem>>("potentialTeamMembers").ToList(); Assert.True(successStatus); Assert.NotNull(teamMembers); Assert.NotNull(potentialMembers); Assert.Equal(1, teamMembers.Count); Assert.Equal(volunteerEmail, teamMembers[0].VolunteerEmail); }
public async Task AddTeamMemberReturnsCorrectJsonWhenIdIsZeroOrSelectedTeamMemberIsZero() { const int itineraryId = 0; const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var jsonResult = await sut.AddTeamMember(itineraryId, 0) as JsonResult; var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess"); var errors = jsonResult.GetValueForProperty<string[]>("errors"); Assert.False(successStatus); Assert.NotNull(errors); Assert.Equal(1, errors.Length); Assert.Equal("Invalid selection.", errors[0]); }
public async Task AddTeamMemberSendsAddTeamMemberCommandWithCorrectParameters() { const int itineraryId = 1; const int selectedTeamMember = 1; string volunteerEmail = "*****@*****.**"; var mockMediator = new Mock<IMediator>(); var itineraryDetailsViewModel = new ItineraryDetailsViewModel { PotentialTeamMembers = new List<SelectListItem>(), TeamMembers = new List<TeamListViewModel> { new TeamListViewModel {VolunteerEmail = volunteerEmail} } }; mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(1); mockMediator.Setup(x => x.SendAsync(It.IsAny<ItineraryDetailQuery>())).ReturnsAsync(itineraryDetailsViewModel); var sut = new ItineraryController(mockMediator.Object, null); sut.SetClaims(new List<Claim> { new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()) }); await sut.AddTeamMember(1, 1); mockMediator.Verify(x => x.SendAsync(It.Is<AddTeamMemberCommand>(y => y.ItineraryId == itineraryId && y.TaskSignupId == selectedTeamMember)), Times.Once); mockMediator.Verify(x => x.SendAsync(It.Is<ItineraryDetailQuery>(y => y.ItineraryId == itineraryId)), Times.Once); }