コード例 #1
0
        public void ControllerHasAreaAtttributeWithTheCorrectAreaName()
        {
            var sut = new VolunteerTaskController(null, null);

            sut.SetDefaultHttpContext();
            var attribute = sut.GetAttributes().OfType <AreaAttribute>().SingleOrDefault();

            Assert.NotNull(attribute);
            Assert.Equal(AreaNames.Admin, attribute.RouteValue);
        }
コード例 #2
0
        public async Task MessageAllVolunteersReturnsForbidResultWhenUserIsNotAuthorized()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByVolunteerTaskIdQuery>())).ReturnsAsync(It.IsAny <int>());
            mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableTaskQuery>())).ReturnsAsync(new FakeAuthorizableTask(false, false, false, false));

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

            sut.SetDefaultHttpContext();
            var result = await sut.MessageAllVolunteers(new MessageTaskVolunteersViewModel());

            Assert.IsType <ForbidResult>(result);
        }
コード例 #3
0
        public async Task DeleteConfirmedReturnsForbidResultWhenUserIsNotAuthorized()
        {
            var model = new DeleteViewModel {
                UserIsOrgAdmin = false
            };

            var sut = new VolunteerTaskController(null, null);

            sut.SetDefaultHttpContext();

            var result = await sut.DeleteConfirmed(model);

            Assert.IsType <ForbidResult>(result);
        }
コード例 #4
0
        public async Task DeleteReturnsForbidResultWhenUserIsNotAuthorized()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <DeleteQuery>())).ReturnsAsync(new DeleteViewModel());
            mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableTaskQuery>())).ReturnsAsync(new FakeAuthorizableTask(false, false, false, false));

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

            sut.SetDefaultHttpContext();
            var result = await sut.Delete(It.IsAny <int>());

            Assert.IsType <ForbidResult>(result);
        }
コード例 #5
0
        public async Task AssignSendsOrganizationIdByTaskIdQueryWithCorrectTaskId()
        {
            const int volunteerTaskId = 1;

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByVolunteerTaskIdQuery>())).ReturnsAsync(It.IsAny <int>());
            mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableTaskQuery>())).ReturnsAsync(new FakeAuthorizableTask(false, true, false, false));

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

            sut.SetDefaultHttpContext();
            await sut.Assign(volunteerTaskId, null);

            mediator.Verify(x => x.SendAsync(It.Is <OrganizationIdByVolunteerTaskIdQuery>(y => y.VolunteerTaskId == volunteerTaskId)), Times.Once);
        }
コード例 #6
0
        public async Task CreateGetReturnsForbidResultWhenUserIsNotAuthorized()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <CreateVolunteerTaskQuery>())).ReturnsAsync(new EditViewModel());
            mediator.Setup(x => x.SendAsync(It.IsAny <AllReady.Areas.Admin.Features.Events.AuthorizableEventQuery>()))
            .ReturnsAsync(new FakeAuthorizableEvent(false, false, false, false));

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

            sut.SetDefaultHttpContext();

            var result = await sut.Create(It.IsAny <int>());

            Assert.IsType <ForbidResult>(result);
        }
コード例 #7
0
        public async Task EditPostReturnsForbidResultWhenModelStateIsValidAndUserIsNotAuthorized()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <AllReady.Areas.Admin.Features.Events.AuthorizableEventQuery>()))
            .ReturnsAsync(new FakeAuthorizableEvent(false, false, false, false));
            mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableTaskQuery>())).ReturnsAsync(new FakeAuthorizableTask(false, false, false, false));

            var validator = new Mock <IValidateVolunteerTaskEditViewModelValidator>();

            validator.Setup(x => x.Validate(It.IsAny <EditViewModel>())).ReturnsAsync(new List <KeyValuePair <string, string> >());

            var sut = new VolunteerTaskController(mediator.Object, validator.Object);

            sut.SetDefaultHttpContext();

            var result = await sut.Edit(new EditViewModel());

            Assert.IsType <ForbidResult>(result);
        }