Ejemplo n.º 1
0
        public async Task Register_ReturnsCorrectJson_WhenApiResult_IsSuccess()
        {
            const string taskSignUpResultStatus = TaskSignupResult.SUCCESS;
            var          model    = new EventSignupViewModel();
            var          mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.Is <TaskSignupCommandAsync>(y => y.TaskSignupModel == model)))
            .Returns(Task.FromResult(new TaskSignupResult
            {
                Status = taskSignUpResultStatus,
                Task   = new AllReadyTask {
                    Id = 1, Name = "Task"
                }
            }));

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

            var jsonResult = await sut.RegisterTask(model) as JsonResult;

            var successStatus = jsonResult.GetValueForProperty <bool>("isSuccess");
            var taskModel     = jsonResult.GetValueForProperty <TaskViewModel>("task");

            Assert.True(successStatus);
            Assert.NotNull(taskModel);
        }
Ejemplo n.º 2
0
        public async Task Register_ReturnsCorrectJson_WhenTaskIsClosed()
        {
            const string taskSignUpResultStatus = TaskSignupResult.FAILURE_CLOSEDTASK;

            var model    = new EventSignupViewModel();
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.Is <TaskSignupCommandAsync>(y => y.TaskSignupModel == model)))
            .Returns(Task.FromResult(new TaskSignupResult
            {
                Status = taskSignUpResultStatus
            }));

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

            var jsonResult = await sut.RegisterTask(model) as JsonResult;

            var successStatus = jsonResult.GetValueForProperty <bool>("isSuccess");
            var errors        = jsonResult.GetValueForProperty <string[]>("errors");

            Assert.False(successStatus);
            Assert.NotNull(errors);
            Assert.Equal(1, errors.Count());
            Assert.Equal("Signup failed - Task is closed", errors[0]);
        }
Ejemplo n.º 3
0
        public async Task RegisterEventSendsEventSignupCommandAsyncWithCorrectData()
        {
            var model    = new EventSignupViewModel();
            var mediator = new Mock <IMediator>();

            var sut = new EventApiController(mediator.Object);
            await sut.RegisterEvent(model);

            mediator.Verify(x => x.SendAsync(It.Is <EventSignupCommand>(command => command.EventSignup.Equals(model))));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> RegisterTask(EventSignupViewModel signupModel)
        {
            if (signupModel == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                // this condition should never be hit because client side validation is being performed
                // but just to cover the bases, if this does happen send the erros to the client
                return(Json(new { errors = ModelState.GetErrorMessages() }));
            }

            var result = await _mediator.SendAsync(new TaskSignupCommandAsync { TaskSignupModel = signupModel });

            switch (result.Status)
            {
            case TaskSignupResult.SUCCESS:
                return(Json(new
                {
                    isSuccess = true,
                    task = result.Task == null ? null : new TaskViewModel(result.Task, signupModel.UserId)
                }));

            case TaskSignupResult.FAILURE_CLOSEDTASK:
                return(Json(new
                {
                    isSuccess = false,
                    errors = new[] { "Signup failed - Task is closed" },
                }));

            case TaskSignupResult.FAILURE_EVENTNOTFOUND:
                return(Json(new
                {
                    isSuccess = false,
                    errors = new[] { "Signup failed - The event could not be found" },
                }));

            case TaskSignupResult.FAILURE_TASKNOTFOUND:
                return(Json(new
                {
                    isSuccess = false,
                    errors = new[] { "Signup failed - The task could not be found" },
                }));

            default:
                return(Json(new
                {
                    isSuccess = false,
                    errors = new[] { "Unkown error" },
                }));
            }
        }
Ejemplo n.º 5
0
        public async Task RegisterTaskSendsTaskSignupCommandWithCorrectTaskSignupModel()
        {
            var model    = new EventSignupViewModel();
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.Is <TaskSignupCommandAsync>(y => y.TaskSignupModel == model))).Returns(Task.FromResult(new TaskSignupResult()));

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

            mediator.Verify(x => x.SendAsync(It.Is <TaskSignupCommandAsync>(command => command.TaskSignupModel.Equals(model))));
        }
Ejemplo n.º 6
0
        public async Task SignupSendsAsyncEventSignupCommandWithCorrrectDataWhenViewModelIsNotNull()
        {
            var builder = EventControllerBuilder.Instance();
            var sut     = builder.WithMediator().Build();

            var model = new EventSignupViewModel();
            await sut.Signup(model);

            builder
            .MediatorMock
            .Verify(x => x.SendAsync(It.Is <EventSignupCommand>(y => y.EventSignup == model)));
        }
Ejemplo n.º 7
0
        public async Task RegisterTaskReturnsNullForTaskIfTaskIsNull()
        {
            var model    = new EventSignupViewModel();
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.Is <TaskSignupCommand>(y => y.TaskSignupModel == model))).Returns(Task.FromResult(new TaskSignupResult()));

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

            var jsonResult = await sut.RegisterTask(model) as JsonResult;

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

            Assert.Null(result);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Signup(EventSignupViewModel signupModel)
        {
            if (signupModel == null)
            {
                return(HttpBadRequest());
            }

            if (ModelState.IsValid)
            {
                await _mediator.SendAsync(new EventSignupCommand { EventSignup = signupModel });
            }

            //TODO: handle invalid event signup info (phone, email) in a useful way
            //  would be best to handle it in KO on the client side (prevent clicking Volunteer)

            return(RedirectToAction(nameof(ShowEvent), new { id = signupModel.EventId }));
        }
Ejemplo n.º 9
0
        public ActionResult LatestEvent()
        {
            var   db                = new HockeySignupsDb(_connectionString);
            Event latestEvent       = db.GetLatestEvent();
            EventSignupViewModel vm = new EventSignupViewModel();

            vm.Event       = latestEvent;
            vm.EventStatus = db.GetEventStatus(latestEvent);
            vm.Signup      = new EventSignup();
            if (Request.Cookies["firstName"] != null)
            {
                vm.Signup.FirstName = Request.Cookies["firstName"].Value;
                vm.Signup.LastName  = Request.Cookies["lastName"].Value;
                vm.Signup.Email     = Request.Cookies["email"].Value;
            }
            return(View(vm));
        }
Ejemplo n.º 10
0
        public EventViewModel(Models.Event @event)
        {
            Id = @event.Id;
            if (@event.Campaign != null)
            {
                CampaignId   = @event.Campaign.Id;
                CampaignName = @event.Campaign.Name;
                TimeZoneId   = @event.Campaign.TimeZoneId;
                if (@event.Campaign.ManagingOrganization != null)
                {
                    OrganizationId   = @event.Campaign.ManagingOrganization.Id;
                    OrganizationName = @event.Campaign.ManagingOrganization.Name;
                    HasPrivacyPolicy = !string.IsNullOrEmpty(@event.Campaign.ManagingOrganization.PrivacyPolicy);
                }
            }

            Title         = @event.Name;
            Description   = @event.Description;
            EventType     = @event.EventType;
            StartDateTime = @event.StartDateTime;
            EndDateTime   = @event.EndDateTime;

            if (@event.Location != null)
            {
                Location = new LocationViewModel(@event.Location);
            }

            IsClosed = EndDateTime.UtcDateTime < DateTimeOffset.UtcNow;

            ImageUrl = @event.ImageUrl;

            Tasks = @event.Tasks != null
                 ? new List <TaskViewModel>(@event.Tasks.Select(data => new TaskViewModel(data)).OrderBy(task => task.StartDateTime))
                 : new List <TaskViewModel>();

            SignupModel = new EventSignupViewModel();

            //mgmccarthy: this check doesn't make much sense unless you explicitly set @event.RequiredSkills to null. If you look at the Event model, you'll see that RequireSkills is instaniated with
            //a new empty list: "public List<EventSkill> RequiredSkills { get; set; } = new List<EventSkill>();". I think this can go away?
            RequiredSkills = @event.RequiredSkills?.Select(ek => new SkillViewModel(ek.Skill)).ToList();

            IsLimitVolunteers = @event.IsLimitVolunteers;
            IsAllowWaitList   = @event.IsAllowWaitList;
            Headline          = @event.Headline;
        }
Ejemplo n.º 11
0
        public async Task <object> RegisterEvent(EventSignupViewModel signupModel)
        {
            if (signupModel == null)
            {
                return(HttpBadRequest());
            }

            if (!ModelState.IsValid)
            {
                // this condition should never be hit because client side validation is being performed
                // but just to cover the bases, if this does happen send the erros to the client
                return(Json(new { errors = ModelState.GetErrorMessages() }));
            }

            await _mediator.SendAsync(new EventSignupCommand { EventSignup = signupModel });

            return(new { Status = "success" });
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> RegisterTask(EventSignupViewModel signupModel)
        {
            if (signupModel == null)
            {
                return(HttpBadRequest());
            }

            if (!ModelState.IsValid)
            {
                // this condition should never be hit because client side validation is being performed
                // but just to cover the bases, if this does happen send the erros to the client
                return(Json(new { errors = ModelState.GetErrorMessages() }));
            }

            var result = await _mediator.SendAsync(new TaskSignupCommand { TaskSignupModel = signupModel });

            return(Json(new { result.Status, Task = result.Task == null ? null : new TaskViewModel(result.Task, signupModel.UserId) }));
        }
Ejemplo n.º 13
0
        public async Task RegisterTaskReturnsCorrectValueForStatus()
        {
            const string taskSignUpResultStatus = "status";
            var          model    = new EventSignupViewModel();
            var          mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.Is <TaskSignupCommand>(y => y.TaskSignupModel == model))).Returns(Task.FromResult(new TaskSignupResult {
                Status = taskSignUpResultStatus
            }));

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

            var jsonResult = await sut.RegisterTask(model) as JsonResult;

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

            Assert.Equal(result, taskSignUpResultStatus);
        }
Ejemplo n.º 14
0
        public async Task RegisterTaskReturnsTaskViewModelIfTaskIsNotNull()
        {
            var model = new EventSignupViewModel {
                UserId = "userId"
            };
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.Is <TaskSignupCommand>(y => y.TaskSignupModel == model))).Returns(Task.FromResult(new TaskSignupResult {
                Task = new AllReadyTask()
            }));

            var sut        = new TaskApiController(mediator.Object, null);
            var jsonResult = await sut.RegisterTask(model) as JsonResult;

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

            Assert.IsType <JsonResult>(jsonResult);
            Assert.IsType <TaskViewModel>(result);
        }
Ejemplo n.º 15
0
        public EventViewModel(Models.Event campaignEvent)
        {
            Id = campaignEvent.Id;
            if (campaignEvent.Campaign != null)
            {
                CampaignId   = campaignEvent.Campaign.Id;
                CampaignName = campaignEvent.Campaign.Name;
                TimeZoneId   = campaignEvent.Campaign.TimeZoneId;
                if (campaignEvent.Campaign.ManagingOrganization != null)
                {
                    OrganizationId   = campaignEvent.Campaign.ManagingOrganization.Id;
                    OrganizationName = campaignEvent.Campaign.ManagingOrganization.Name;
                    HasPrivacyPolicy = !string.IsNullOrEmpty(campaignEvent.Campaign.ManagingOrganization.PrivacyPolicy);
                }
            }

            Title         = campaignEvent.Name;
            Description   = campaignEvent.Description;
            EventType     = campaignEvent.EventType;
            StartDateTime = campaignEvent.StartDateTime;
            EndDateTime   = campaignEvent.EndDateTime;

            if (campaignEvent.Location != null)
            {
                Location = new LocationViewModel(campaignEvent.Location);
            }

            IsClosed = EndDateTime.UtcDateTime < DateTimeOffset.UtcNow;

            ImageUrl = campaignEvent.ImageUrl;

            //TODO Location
            Tasks = campaignEvent.Tasks != null
                 ? new List <TaskViewModel>(campaignEvent.Tasks.Select(data => new TaskViewModel(data)).OrderBy(task => task.StartDateTime))
                 : new List <TaskViewModel>();

            SignupModel = new EventSignupViewModel();

            RequiredSkills    = campaignEvent.RequiredSkills?.Select(acsk => new SkillViewModel(acsk.Skill)).ToList();
            IsLimitVolunteers = campaignEvent.IsLimitVolunteers;
            IsAllowWaitList   = campaignEvent.IsAllowWaitList;
            Headline          = campaignEvent.Headline;
        }
Ejemplo n.º 16
0
        public async Task RegisterTaskSendsTaskSignupCommandWithCorrectTaskSignupModel()
        {
            var model = new EventSignupViewModel();
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(y => y.TaskSignupModel == model))).Returns(Task.FromResult(new TaskSignupResult()));

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

            mediator.Verify(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(command => command.TaskSignupModel.Equals(model))));
        }
Ejemplo n.º 17
0
        public async Task Register_ReturnsCorrectJson_WhenTaskIsClosed()
        {
            const string taskSignUpResultStatus = TaskSignupResult.FAILURE_CLOSEDTASK;

            var model = new EventSignupViewModel();
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(y => y.TaskSignupModel == model)))
                .Returns(Task.FromResult(new TaskSignupResult
                {
                    Status = taskSignUpResultStatus
                }));

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

            var jsonResult = await sut.RegisterTask(model) as JsonResult;

            var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess");
            var errors = jsonResult.GetValueForProperty<string[]>("errors");

            Assert.False(successStatus);
            Assert.NotNull(errors);
            Assert.Equal(1, errors.Count());
            Assert.Equal(TaskApiController.FAILED_SIGNUP_TASK_CLOSED, errors[0]);
        }
Ejemplo n.º 18
0
        public async Task Register_ReturnsCorrectJson_WhenApiResult_IsSuccess()
        {
            const string taskSignUpResultStatus = TaskSignupResult.SUCCESS;
            var model = new EventSignupViewModel();
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(y => y.TaskSignupModel == model)))
                .Returns(Task.FromResult(new TaskSignupResult
                {
                    Status = taskSignUpResultStatus,
                    Task = new AllReadyTask { Id = 1, Name = "Task" }
                }));

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

            var jsonResult = await sut.RegisterTask(model) as JsonResult;

            var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess");
            var taskModel = jsonResult.GetValueForProperty<TaskViewModel>("task");

            Assert.True(successStatus);
            Assert.NotNull(taskModel);
        }
Ejemplo n.º 19
0
        public async Task RegisterEventSendsEventSignupCommandAsyncWithCorrectData()
        {
            var model = new EventSignupViewModel();
            var mediator = new Mock<IMediator>();

            var sut = new EventApiController(mediator.Object, null);
            await sut.RegisterEvent(model);

            mediator.Verify(x => x.SendAsync(It.Is<EventSignupCommand>(command => command.EventSignup.Equals(model))));
        }