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 MarkCompleteReturnsRedirectToActionWhenOrganizationIsNotZero_AndUserIsOrgAdmin()
        {
            var itineraryId = It.IsAny <int>();
            var requestId   = It.IsAny <Guid>();

            var mockMediator = new Mock <IMediator>();

            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.MarkComplete(itineraryId, requestId);

            Assert.IsType <RedirectToActionResult>(result);
        }
        public async Task MarkCompleteSendsRequestStatusChangeCommandWithCorrectTaskSignupIdWhenOrganizationIsNotZero_AndUserIsOrgAdmin()
        {
            var itineraryId = It.IsAny <int>();
            var requestId   = It.IsAny <Guid>();

            var mockMediator = new Mock <IMediator>();

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

            await sut.MarkComplete(itineraryId, requestId);

            mockMediator.Verify(x => x.SendAsync(It.Is <RequestStatusChangeCommand>(y => y.RequestId == requestId)), Times.Once);
        }
        public async Task RemoveTeamMemberRedirectsToCorrectActionWithCorrectRouteValuesWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin()
        {
            var itineraryId  = It.IsAny <int>();
            var taskSignupId = It.IsAny <int>();

            var mockMediator = new Mock <IMediator>();

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

            await sut.RemoveTeamMember(itineraryId, taskSignupId);

            mockMediator.Verify(x => x.SendAsync(It.Is <RemoveTeamMemberCommand>(y => y.TaskSignupId == taskSignupId)), Times.Once);
        }
        public async Task AddRequestsSendsAddRequestsCommandWhenThereAreSelecteRequests()
        {
            var itineraryId      = It.IsAny <int>();
            var selectedRequests = new[] { "request1", "request2" };

            var mockMediator = new Mock <IMediator>();

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

            await sut.AddRequests(itineraryId, selectedRequests);

            mockMediator.Verify(x => x.SendAsync(It.Is <AddRequestsCommand>(y => y.ItineraryId == itineraryId)), Times.Once);
        }
Esempio n. 6
0
        public async Task CreateReturnsOkResultWhenUserIsSiteAdmin_AndModelIsValid_AndSuccessfulAdd()
        {
            const int orgId = 1;

            //var sut = GetItineraryControllerWithEventSummaryQuery(UserType.SiteAdmin.ToString(), 0);
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <EventSummaryQuery>())).ReturnsAsync(new EventSummaryViewModel {
                OrganizationId = orgId
            });
            mediator.Setup(x => x.SendAsync(It.IsAny <EditItineraryCommand>())).ReturnsAsync(orgId);

            var sut = new ItineraryController(mediator.Object, MockSuccessValidation().Object);

            sut.SetClaims(new List <Claim>
            {
                new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()),
                new Claim(AllReady.Security.ClaimTypes.Organization, "0")
            });

            Assert.IsType <OkObjectResult>(await sut.Create(new ItineraryEditViewModel()));
        }
        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 CreateReturnsHttpBadRequestResultWhenValidatonFails()
        {
            var model = new ItineraryEditModel
            {
                EventId = 1,
                Name    = "Test",
                Date    = new DateTime(2016, 06, 01)
            };

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <EventSummaryQuery>())).ReturnsAsync(new EventSummaryModel {
                Id = 1, Name = "Event", OrganizationId = 1, StartDateTime = new DateTimeOffset(new DateTime(2016, 01, 01)), EndDateTime = new DateTimeOffset(new DateTime(2016, 12, 31))
            });
            mediator.Setup(x => x.SendAsync(It.IsAny <EditItineraryCommand>())).ReturnsAsync(1);

            var validatorError = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("key", "value")
            };

            var mockValidator = new Mock <IItineraryEditModelValidator>();

            mockValidator.Setup(mock => mock.Validate(It.IsAny <ItineraryEditModel>(), It.IsAny <EventSummaryModel>())).Returns(validatorError).Verifiable();

            var sut = new ItineraryController(mediator.Object, mockValidator.Object);

            sut.SetClaims(new List <Claim>
            {
                new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()),
                new Claim(AllReady.Security.ClaimTypes.Organization, "1")
            });

            var result = await sut.Create(model);

            Assert.IsType <BadRequestObjectResult>(result);
        }
        public async Task AddRequestsRedirectsToCorrectActionWithCorrectRouteValuesWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin_AndThereAreSelectedRequests()
        {
            var itineraryId      = It.IsAny <int>();
            var selectedRequests = new[] { "request1", "request2" };

            var mockMediator = new Mock <IMediator>();

            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.AddRequests(itineraryId, selectedRequests) as RedirectToActionResult;

            Assert.Equal(result.ActionName, nameof(ItineraryController.Details));
            Assert.Equal(result.RouteValues, new Dictionary <string, object> {
                ["id"] = itineraryId
            });
        }