public DetailsQueryHandlerShould()
        {
            task = new AllReadyTask
            {
                Id = 1,
                Name = "TaskName",
                Description = "TaskDescription",
                StartDateTime = DateTimeOffset.Now,
                EndDateTime = DateTimeOffset.Now,
                NumberOfVolunteersRequired = 5,
                Event = new Event
                {
                    Id = 2,
                    Name = "EventName",
                    CampaignId = 3,
                    Campaign = new Campaign { Id = 3, Name = "CampaignName", TimeZoneId = "Central Standard Time" }
                },
                RequiredSkills = new List<TaskSkill> { new TaskSkill { SkillId = 4, TaskId = 1 } },
                AssignedVolunteers = new List<TaskSignup> { new TaskSignup { User = new ApplicationUser { Id = "UserId", UserName = "******" } } }
            };

            Context.Tasks.Add(task);
            Context.SaveChanges();

            message = new DetailsQuery { TaskId = task.Id };
            sut = new DetailsQueryHandler(Context);
        }
Exemplo n.º 2
0
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();
            Organization htb = new Organization()
            {
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };
            Campaign firePrev = new Campaign()
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb
            };
            Activity queenAnne = new Activity()
            {
                Id = 1,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<ActivitySkill>(),
            };

            var username1 = $"*****@*****.**";
            var username2 = $"*****@*****.**";

            var user1 = new ApplicationUser { UserName = username1, Email = username1, EmailConfirmed = true };
            context.Users.Add(user1);

            htb.Campaigns.Add(firePrev);
            context.Organizations.Add(htb);
            context.Activities.Add(queenAnne);

            var activitySignups = new List<ActivitySignup>();
            activitySignups.Add(new ActivitySignup { Activity = queenAnne, User = user1, SignupDateTime = DateTime.UtcNow });

            context.ActivitySignup.AddRange(activitySignups);

            var newTask = new AllReadyTask()
            {
                Activity = queenAnne,
                Description = "Description of a very important task",
                Name = "Task # 1",
                EndDateTime = DateTime.Now.AddDays(5),
                StartDateTime = DateTime.Now.AddDays(3),
                Organization = htb
            };
            newTask.AssignedVolunteers.Add(new TaskSignup()
            {
                Task = newTask,
                User = user1
            });
            context.Tasks.Add(newTask);

            context.SaveChanges();
        }
Exemplo n.º 3
0
        private async Task<bool> HasTaskEditPermissions(AllReadyTask task)
        {
            ApplicationUser currentUser = await _userManager.GetCurrentUser(Context);
            IList<Claim> claims = await _userManager.GetClaimsForCurrentUser(Context);
            if (claims.IsUserType(UserType.SiteAdmin))
            {
                return true;
            }

            if (claims.IsUserType(UserType.TenantAdmin))
            {
                //TODO: Modify to check that user is tenant admin for tenant of task
                return true;
            }

            if (task.Activity != null && task.Activity.Organizer != null && task.Activity.Organizer.Id == currentUser.Id)
            {
                return true;
            }

            if (task.Activity != null && task.Activity.Campaign != null && task.Activity.Campaign.Organizer != null && task.Activity.Campaign.Organizer.Id == currentUser.Id)
            {
                return true;
            }

            return false;
        }
        public EditTaskQueryHandlerShould()
        {
            task = new AllReadyTask
            {
                Id = 1,
                Name = "Taskname",
                Description = "Description",
                StartDateTime = DateTimeOffset.Now,
                EndDateTime = DateTimeOffset.Now,
                NumberOfVolunteersRequired = 5,
                RequiredSkills = new List<TaskSkill> { new TaskSkill { SkillId = 2, Skill = new Skill(), TaskId = 1 } },
                Event = new Event
                {
                    Id = 3,
                    Name = "EventName",
                    CampaignId = 4,
                    Campaign = new Campaign
                    {
                        StartDateTime = DateTimeOffset.Now,
                        EndDateTime = DateTimeOffset.Now,
                        Name = "CampaignName",
                        ManagingOrganizationId = 5,
                        TimeZoneId = "Central Standard Time"
                    }
                }
            };

            Context.Tasks.Add(task);
            Context.SaveChanges();

            message = new EditTaskQuery { TaskId = task.Id };
            sut = new EditTaskQueryHandler(Context);

        }
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();
            var htb = new Organization
            {
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb
            };

            var queenAnne = new Event
            {
                Id = 1,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<EventSkill>(),
            };

            var username1 = $"*****@*****.**";
            var username2 = $"*****@*****.**";

            var user1 = new ApplicationUser { UserName = username1, Email = username1, EmailConfirmed = true };
            context.Users.Add(user1);
            var user2 = new ApplicationUser { UserName = username2, Email = username2, EmailConfirmed = true };
            context.Users.Add(user2);

            htb.Campaigns.Add(firePrev);            
            context.Organizations.Add(htb);
            
            var task = new AllReadyTask
            {
                Event = queenAnne,
                Description = "Description of a very important task",
                Name = "Task # ",
                EndDateTime = DateTime.Now.AddDays(1),
                StartDateTime = DateTime.Now.AddDays(-3)
            };
            queenAnne.Tasks.Add(task);
            context.Events.Add(queenAnne);

            var taskSignups = new List<TaskSignup>
            {
                new TaskSignup { Task = task, User = user1 },
                new TaskSignup { Task = task, User = user2 }
            };
            context.TaskSignups.AddRange(taskSignups);

            context.SaveChanges();
        }
Exemplo n.º 6
0
        private bool HasTaskEditPermissions(AllReadyTask task)
        {
            var userId = User.GetUserId();
            if (User.IsUserType(UserType.SiteAdmin))
            {
                return true;
            }

            if (User.IsUserType(UserType.OrgAdmin))
            {
                //TODO: Modify to check that user is organization admin for organization of task
                return true;
            }

            if (task.Activity?.Organizer != null && task.Activity.Organizer.Id == userId)
            {
                return true;
            }

            if (task.Activity?.Campaign != null && task.Activity.Campaign.Organizer != null && task.Activity.Campaign.Organizer.Id == userId)
            {
                return true;
            }

            return false;
        }
        public async Task SendNotificationToVolunteersWithCorrectMessage()
        {
            const string expectedMessage = "You've been assigned a task from AllReady.";
            var @task = new AllReadyTask { Id = 1 };
            var volunteer = new ApplicationUser
            {
                Id = "user1",
                Email = "*****@*****.**",
                PhoneNumber = "1234",
                EmailConfirmed = true,
                PhoneNumberConfirmed = true
            };

            Context.Add(volunteer);
            Context.Add(@task);
            Context.SaveChanges();

            var message = new TaskAssignedToVolunteersNotification { TaskId = @task.Id, NewlyAssignedVolunteers = new List<string> { volunteer.Id } };
            await sut.Handle(message);

            mediator.Verify(b => b.SendAsync(It.Is<NotifyVolunteersCommand>(notifyCommand =>
                   notifyCommand.ViewModel.EmailMessage == expectedMessage &&
                   notifyCommand.ViewModel.Subject == expectedMessage &&
                   notifyCommand.ViewModel.EmailRecipients.Contains(volunteer.Email) &&
                   notifyCommand.ViewModel.SmsRecipients.Contains(volunteer.PhoneNumber) &&
                   notifyCommand.ViewModel.SmsMessage == expectedMessage
            )), Times.Once());
        }
Exemplo n.º 8
0
        public void IsClosed_ShouldBeTrue_IfEndDatePriorToCurrentDate()
        {
            var sut = new AllReadyTask();

            sut.EndDateTime = DateTime.UtcNow.AddDays(-1);

            Assert.True(sut.IsClosed);
        }
Exemplo n.º 9
0
        public void IsClosed_ShouldBeFalse_IfEndDateLaterThanCurrentDate()
        {
            var sut = new AllReadyTask();

            sut.EndDateTime = DateTime.UtcNow.AddDays(1);

            Assert.False(sut.IsClosed);
        }
        public OrganizationIdByTaskIdQueryHandlerShould()
        {
            task = new AllReadyTask { Id = TaskId, Organization = new Organization { Id = OrganizationId } };

            Context.Tasks.Add(task);
            Context.Tasks.Add(new AllReadyTask { Id = 2 });
            Context.SaveChanges();
        }
        protected override void LoadTestData()
        {
            var htb = new Organization()
            {
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign()
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb
            };

            var queenAnne = new Event()
            {
                Id = 1,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<EventSkill>(),
            };

            var username1 = $"*****@*****.**";
            var username2 = $"*****@*****.**";

            var user1 = new ApplicationUser { UserName = username1, Email = username1, EmailConfirmed = true };
            Context.Users.Add(user1);
            var user2 = new ApplicationUser { UserName = username2, Email = username2, EmailConfirmed = true };
            Context.Users.Add(user2);

            var task = new AllReadyTask
            {
                Id = 1,
                Name = "Task 1",
                Event = queenAnne,
            };

            var taskSignup = new TaskSignup
            {
                Id = 1,
                User = user1,
                Task = task
            };

            htb.Campaigns.Add(firePrev);            
            Context.Organizations.Add(htb);
            Context.Events.Add(queenAnne);
            Context.Tasks.Add(task);
            Context.TaskSignups.Add(taskSignup);

            Context.SaveChanges();
        }
Exemplo n.º 12
0
        public TaskViewModel(AllReadyTask task, string userId = null)
        {
            Id = task.Id;
            Name = task.Name;
            Description = task.Description;
            StartDateTime = task.StartDateTime;
            EndDateTime = task.EndDateTime;

            if (task.Event != null)
            {
                EventId = task.Event.Id;
                eventName = task.Event.Name;
            }

            if (task.Event?.Campaign != null)
            {
                CampaignId = task.Event.Campaign.Id;
                CampaignName = task.Event.Campaign.Name;
            }

            if (task.Organization != null)
            {
                OrganizationId = task.Organization.Id;
                OrganizationName = task.Organization.Name;
            }

            IsUserSignedUpForTask = false;

            if (task.AssignedVolunteers != null)
            {
                if (!string.IsNullOrWhiteSpace(userId))
                {
                    IsUserSignedUpForTask = task.AssignedVolunteers.Any(au => au.User.Id == userId);
                }

                AssignedVolunteers = new List<TaskSignupViewModel>();

                if (IsUserSignedUpForTask)
                {
                    foreach (var t in task.AssignedVolunteers.Where(au => au.User.Id == userId))
                    {
                        AssignedVolunteers.Add(new TaskSignupViewModel(t));
                    }
                }
            }

            if (task.RequiredSkills != null)
            {
                RequiredSkills = task.RequiredSkills.Select(t => t.SkillId);
                RequiredSkillObjects = task.RequiredSkills?.Select(t => t.Skill).Select(s => new SkillViewModel(s)).ToList();
            }

            NumberOfVolunteersRequired = task.NumberOfVolunteersRequired;
            NumberOfUsersSignedUp = task.NumberOfUsersSignedUp;
            IsLimitVolunteers = task.IsLimitVolunteers;
            IsAllowWaitList = task.IsAllowWaitList;
            IsClosed = task.IsClosed;
        }
 Task IAllReadyDataAccess.UpdateTaskAsync(AllReadyTask value)
 {
     //First remove any skills that are no longer associated with this task
     var tsToRemove = _dbContext.TaskSkills.Where(ts => ts.TaskId == value.Id && (value.RequiredSkills == null ||
         !value.RequiredSkills.Any(ts1 => ts1.SkillId == ts.SkillId)));
     _dbContext.TaskSkills.RemoveRange(tsToRemove);
     _dbContext.Tasks.Update(value);
     return _dbContext.SaveChangesAsync();
 }
 Task IAllReadyDataAccess.AddTaskAsync(AllReadyTask task)
 {
     if (task.Id == 0)
     {
         _dbContext.Add(task);
         return _dbContext.SaveChangesAsync();
     }
     else throw new InvalidOperationException("Added task that already has Id");
 }
Exemplo n.º 15
0
        public TaskViewModel(AllReadyTask task)
        {
            Id = task.Id;
            Name = task.Name;
            Description = task.Description;

            if (task.StartDateTimeUtc.HasValue)
            {
                DateTime startDateWithUtcKind = DateTime.SpecifyKind(
                    DateTime.Parse(task.StartDateTimeUtc.Value.ToString()),
                    DateTimeKind.Utc);
                StartDateTime = new DateTimeOffset(startDateWithUtcKind);
            }

            if (task.EndDateTimeUtc.HasValue)
            {
                DateTime endDateWithUtcKind = DateTime.SpecifyKind(
                    DateTime.Parse(task.EndDateTimeUtc.Value.ToString()),
                    DateTimeKind.Utc);
                EndDateTime = new DateTimeOffset(endDateWithUtcKind);
            }

            if (task.Activity != null)
            {
                ActivityId = task.Activity.Id;
                ActivityName = task.Activity.Name;
            }

            if (task.Activity != null && task.Activity.Campaign != null)
            {
                CampaignId = task.Activity.Campaign.Id;
                CampaignName = task.Activity.Campaign.Name;
            }

            if (task.Tenant != null)
            {
                TenantId = task.Tenant.Id;
                TenantName = task.Tenant.Name;
            }

            IsUserSignedUpForTask = false;

            if (task.AssignedVolunteers != null)
            {
                this.AssignedVolunteers = new List<TaskSignupViewModel>();
                foreach (var t in task.AssignedVolunteers)
                {
                    this.AssignedVolunteers.Add(new TaskSignupViewModel(t));
                }
            }

            if (task.RequiredSkills != null)
            {
                this.RequiredSkills = task.RequiredSkills.Select(t => t.SkillId);
            }
        }
        public async Task UpdateExistingTaskSuccessfully()
        {
            var @event = new Event { Id = 3 };
            var organization = new Organization { Id = 4 };
            var task = new AllReadyTask
            {
                Id = 2,
                Name = "TaskName",
                Description = "TaskDescription",
                Event = @event,
                Organization = organization,
                StartDateTime = DateTimeOffset.Now,
                EndDateTime = DateTimeOffset.Now,
                NumberOfVolunteersRequired = 5,
                RequiredSkills = new List<TaskSkill> { new TaskSkill { SkillId = 5, Skill = new Skill { Id = 5, Name = "SkillName", Description = "SkillDescription" } } }
            };

            Context.Database.EnsureDeleted();
            Context.Events.Add(@event);
            Context.Organizations.Add(organization);
            Context.Tasks.Add(task);
            Context.SaveChanges();

            var message = new EditTaskCommandAsync
            {
                Task = new EditViewModel
                {
                    Id = task.Id,
                    Name = "TaskNameUpdated",
                    Description = "TaskDescriptionUpdated",
                    EventId = @event.Id,
                    OrganizationId = organization.Id,
                    TimeZoneId = "Central Standard Time",
                    StartDateTime = DateTimeOffset.Now.AddDays(1),
                    EndDateTime = DateTimeOffset.Now.AddDays(2),
                    NumberOfVolunteersRequired = 6,
                    RequiredSkills = new List<TaskSkill> { new TaskSkill { SkillId = 6, Skill = new Skill { Id = 6, Name = "SkillNameOnMessage", Description = "SkillDescriptionOnMessage" } } }
                }
            };

            var sut = new EditTaskCommandHandlerAsync(Context);
            var taskId = await sut.Handle(message);
            var result = Context.Tasks.Single(x => x.Id == taskId);

            //can't test start and end date as they're tied to static classes
            Assert.Equal(taskId, message.Task.Id);
            Assert.Equal(result.Name, message.Task.Name);
            Assert.Equal(result.Description, message.Task.Description);
            Assert.Equal(result.Event, @event);
            Assert.Equal(result.Organization, organization);
            Assert.Equal(result.NumberOfVolunteersRequired, message.Task.NumberOfVolunteersRequired);
            Assert.Equal(result.IsLimitVolunteers, @event.IsLimitVolunteers);
            Assert.Equal(result.IsAllowWaitList, @event.IsAllowWaitList);
            Assert.Equal(result.RequiredSkills, message.Task.RequiredSkills);
        }
        public TasksByApplicationUserIdQueryHandlerShould()
        {
            message = new TasksByApplicationUserIdQuery { ApplicationUserId = Guid.NewGuid().ToString() };
            alreadyTask = new AllReadyTask { Name = "name" };
            task = new TaskSignup { User = new ApplicationUser { Id = message.ApplicationUserId }, Task = alreadyTask };

            Context.Add(alreadyTask);
            Context.Add(task);
            Context.SaveChanges();

            sut = new TasksByApplicationUserIdQueryHandler(Context);
        }
        public async Task AssignsVolunteersToTask()
        {
            var newVolunteer = new ApplicationUser { Id = "user1", Email = "*****@*****.**", PhoneNumber = "1234"};
            var task = new AllReadyTask { Id = 1 };
            Context.Add(newVolunteer);
            Context.Add(task);
            Context.SaveChanges();

            var message = new AssignTaskCommand { TaskId = task.Id, UserIds = new List<string> { newVolunteer.Id } };
            await sut.Handle(message);

            var taskSignup = Context.Tasks.Single(x => x.Id == task.Id).AssignedVolunteers.Single();
            Assert.Equal(taskSignup.User.Id, newVolunteer.Id);
            Assert.Equal(taskSignup.Status, TaskStatus.Assigned.ToString());
        }
        protected override void LoadTestData()
        {
            var user = new ApplicationUser { Id = "abc" };
            Context.Users.Add(user);

            var campaignEvent = new Event { Id = 1, Name = "Some Event" };
            Context.Events.Add(campaignEvent);

            var @task = new AllReadyTask { Id = 1, Name = "Some Task", EndDateTime = DateTime.UtcNow.AddDays(100), Event = campaignEvent };
            Context.Tasks.Add(@task);
           
            Context.TaskSignups.Add(new TaskSignup { Task = @task, User = user });
        
            Context.SaveChanges();
        }
Exemplo n.º 20
0
 private async Task<bool> HasTaskSignupEditPermissions(AllReadyTask task)
 {
     if (await HasTaskEditPermissions(task))
     {
         return true;
     }
     else
     {
         ApplicationUser currentUser = await _userManager.GetCurrentUser(Context);
         if (task.AssignedVolunteers != null && task.AssignedVolunteers.FirstOrDefault(x => x.User.Id == currentUser.Id) != null)
         {
             return true;
         }
         else { return false; }
     }
 }
Exemplo n.º 21
0
 private bool HasTaskSignupEditPermissions(AllReadyTask task)
 {
     if (HasTaskEditPermissions(task))
     {
         return true;
     }
     else
     {
         var userId = User.GetUserId();                
         if (task.AssignedVolunteers?.FirstOrDefault(x => x.User.Id == userId) != null)
         {
             return true;
         }
         else { return false; }
     }
 }
        public DeleteQueryHandlerAsyncShould()
        {
            task = new AllReadyTask
            {
                Id = 1,
                Name = "TaskName",
                StartDateTime = new DateTimeOffset().UtcDateTime,
                EndDateTime = new DateTimeOffset().UtcDateTime,
                Event = new Event { Id = 2, Name = "EventName", CampaignId = 3, Campaign = new Campaign { ManagingOrganizationId = 4, Name = "Campaign Name" } }
            };
            Context.Tasks.Add(task);

            var taskThatShouldNotBeReturnedFromQuery = new AllReadyTask { Id = 2 };
            Context.Tasks.Add(taskThatShouldNotBeReturnedFromQuery);
            Context.SaveChanges();
        }
Exemplo n.º 23
0
        public async Task EventSignUp_ShouldNotBe_Deleted_IfNotLastSignupForTheUser()
        {
            var secondTask = new AllReadyTask { Id = 2, Name = "Some Task 2", EndDateTime = DateTime.UtcNow.AddDays(100), Event = Context.Events.First() };
            Context.Tasks.Add(secondTask);

            Context.TaskSignups.Add(new TaskSignup { Task = secondTask, User = Context.Users.First() });
            Context.SaveChanges();

            var mockMediator = new Mock<IMediator>();
            var message = new TaskUnenrollCommand { TaskId = 1, UserId = "abc" };
            
            var sut = new TaskUnenrollHandlerAsync(mockMediator.Object, Context);
            var result = await sut.Handle(message);

            Assert.Equal(1, Context.TaskSignups.Count());
            Assert.Equal(1, Context.EventSignup.Count());
        }
        public void AllReadyTaskThatHasInstanceOfEventAndEventHasInstanceOfCampaignAndCampaignHasInstanceOfOrganizerAndOrganizerIdEqualsUserIdIsEditable()
        {
            const string userId = "1";

            var claimsPrincipal = new ClaimsPrincipal();
            claimsPrincipal.AddIdentity(new ClaimsIdentity(new List<Claim>
            {
                new Claim(ClaimTypes.NameIdentifier, "1"),
                new Claim(AllReady.Security.ClaimTypes.UserType, Enum.GetName(typeof (UserType), UserType.BasicUser))
            }));

            var allReadyTask = new AllReadyTask { Event = new Event { Campaign = new Campaign { Organizer = new ApplicationUser { Id = userId }}}};

            var sut = new DetermineIfATaskIsEditable();
            var result = sut.For(claimsPrincipal, allReadyTask, null);

            Assert.True(result);
        }
Exemplo n.º 25
0
        public async Task PostSendsAddTaskCommandAsyncWithCorrectData()
        {
            var model = new TaskViewModel { EventId = 1, Id = 1 };
            var allReadyTask = new AllReadyTask();

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(new Event());
            mediator.SetupSequence(x => x.SendAsync(It.IsAny<TaskByTaskIdQuery>()))
                .ReturnsAsync(allReadyTask).ReturnsAsync(null);

            var determineIfATaskIsEditable = new Mock<IDetermineIfATaskIsEditable>();
            determineIfATaskIsEditable.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>(), null)).Returns(true);

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

            mediator.Verify(x => x.SendAsync(It.Is<AddTaskCommand>(y => y.AllReadyTask == allReadyTask)), Times.Once);
        }
        public async Task RemoveUsersThatAreNotInTheCurrentSignUpList()
        {
            var @task = new AllReadyTask { Id = 1 };
            Context.Add(new ApplicationUser {Id = "user2"});
            var previouslySignedupUser = new ApplicationUser
            {
                Id = "user1",
                Email = "*****@*****.**",
                PhoneNumber = "1234"
            };
            @task.AssignedVolunteers = new List<TaskSignup> { new TaskSignup { User =  previouslySignedupUser} };
            Context.Add(@task);
            Context.SaveChanges();

            var message = new AssignTaskCommand { TaskId = @task.Id, UserIds = new List<string> { "user2" } };
            await sut.Handle(message);

            Assert.True(Context.Tasks.Single(x => x.Id == @task.Id).AssignedVolunteers.Any(x => x.User.Id != previouslySignedupUser.Id ));
        }
Exemplo n.º 27
0
        protected override void LoadTestData()
        {
            rnd = new Random();
            context = ServiceProvider.GetService<AllReadyContext>();
            var tasks = context.Tasks.ToList();
            _task = GenerateTask();

            var htb = new Organization
            {
                Name = "Humanitarian Test",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign
            {
                Name = "test Campaign",
                ManagingOrganization = htb
            };

            var myEvent = new Event
            {
                Id = rnd.Next(3,1000),
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<EventSkill>()
            };

            _task.Event = myEvent;
            context.Organizations.Add(htb);

            context.Campaigns.Add(firePrev);
            context.Events.Add(myEvent);
            context.Tasks.Add(_task);
            tasks = context.Tasks.ToList();
            context.SaveChanges();
        }
        public async Task DoesNotSendNotificationToUsersWhoHasntVerifiedEmail()
        {
            var @task = new AllReadyTask { Id = 1 };
            var volunteer = new ApplicationUser
            {
                Id = "user1",
                Email = "*****@*****.**",
                PhoneNumber = "1234",
                EmailConfirmed = false
            };

            Context.Add(volunteer);
            Context.Add(@task);
            Context.SaveChanges();

            var message = new TaskAssignedToVolunteersNotification { TaskId = @task.Id, NewlyAssignedVolunteers = new List<string> { volunteer.Id } };
            await sut.Handle(message);

            mediator.Verify(b => b.SendAsync(It.Is<NotifyVolunteersCommand>(notifyCommand =>
                   !notifyCommand.ViewModel.EmailRecipients.Contains(volunteer.Email)
            )), Times.Once());
        }
        public async Task PublishTaskAssignedToVolunteersNotification()
        {
            var @task = new AllReadyTask { Id = 1 };
            var volunteer = new ApplicationUser
            {
                Id = "user1",
                Email = "*****@*****.**",
                PhoneNumber = "1234",
                EmailConfirmed = true,
                PhoneNumberConfirmed = true
            };

            Context.Add(volunteer);
            Context.Add(@task);
            Context.SaveChanges();

            var message = new AssignTaskCommand { TaskId = @task.Id, UserIds = new List<string> { volunteer.Id } };
            await sut.Handle(message);

            mediator.Verify(b => b.PublishAsync(It.Is<TaskAssignedToVolunteersNotification>(notification =>
                   notification.TaskId == message.TaskId &&
                   notification.NewlyAssignedVolunteers.Contains(volunteer.Id)
            )), Times.Once());
        }
Exemplo n.º 30
0
 public static TaskViewModel ToViewModel(this AllReadyTask task)
 {
     return(new TaskViewModel(task));
 }
Exemplo n.º 31
0
        public static AllReadyTask ToModel(this TaskViewModel taskViewModel, IMediator mediator)
        {
            var campaignEvent = mediator.Send(new EventByIdQuery { EventId = taskViewModel.EventId });
            if (campaignEvent == null)
            {
                return null;
            }

            var newTask = true;
            AllReadyTask dbtask;
            if (taskViewModel.Id == 0)
            {
                dbtask = new AllReadyTask();
            }
            else
            {
                dbtask = mediator.Send(new TaskByTaskIdQuery { TaskId = taskViewModel.Id });
                newTask = false;
            }

            dbtask.Id = taskViewModel.Id;
            dbtask.Description = taskViewModel.Description;
            dbtask.Event = campaignEvent;
            dbtask.EndDateTime = taskViewModel.EndDateTime.HasValue ? taskViewModel.EndDateTime.Value.UtcDateTime : new DateTime?();
            dbtask.StartDateTime = taskViewModel.EndDateTime.HasValue ? taskViewModel.StartDateTime.Value.UtcDateTime : new DateTime?();
            dbtask.Name = taskViewModel.Name;
            dbtask.RequiredSkills = dbtask.RequiredSkills ?? new List<TaskSkill>();
            taskViewModel.RequiredSkills = taskViewModel.RequiredSkills ?? new List<int>();
            ////Remove old skills
            //dbtask.RequiredSkills.RemoveAll(ts => !taskViewModel.RequiredSkills.Any(s => ts.SkillId == s));
            ////Add new skills
            //dbtask.RequiredSkills.AddRange(taskViewModel.RequiredSkills
            //    .Where(rs => !dbtask.RequiredSkills.Any(ts => ts.SkillId == rs))
            //    .Select(rs => new TaskSkill() { SkillId = rs, TaskId = taskViewModel.Id }));

            // Workaround:  POST is bringing in empty AssignedVolunteers.  Clean this up. Discussing w/ Kiran Challa.
            // Workaround: the if statement is superflous, and should go away once we have the proper fix referenced above.
            if (taskViewModel.AssignedVolunteers != null)
            {
                var bogusAssignedVolunteers = (from assignedVolunteer in taskViewModel.AssignedVolunteers
                                               where string.IsNullOrEmpty(assignedVolunteer.UserId)
                                               select assignedVolunteer).ToList();
                foreach (var bogus in bogusAssignedVolunteers)
                {
                    taskViewModel.AssignedVolunteers.Remove(bogus);
                }
            }
            // end workaround

            if (taskViewModel.AssignedVolunteers != null && taskViewModel.AssignedVolunteers.Count > 0)
            {
                var taskUsersList = taskViewModel.AssignedVolunteers.Select(tvm => new TaskSignup
                {
                    Task = dbtask,
                    User = mediator.Send(new UserByUserIdQuery { UserId = tvm.UserId })
                }).ToList();

                // We may be updating an existing task
                if (newTask || dbtask.AssignedVolunteers.Count == 0)
                {
                    dbtask.AssignedVolunteers = taskUsersList;
                }
                else
                {
                    // Can probably rewrite this more efficiently.
                    foreach (var taskUsers in taskUsersList)
                    {
                        if (!(from entry in dbtask.AssignedVolunteers
                              where entry.User.Id == taskUsers.User.Id
                              select entry).Any())
                        {
                            dbtask.AssignedVolunteers.Add(taskUsers);
                        }
                    }
                }
            }

            return dbtask;
        }
Exemplo n.º 32
0
 Task IAllReadyDataAccess.UpdateTaskAsync(AllReadyTask value)
 {
     _dbContext.Tasks.Update(value);
     return(_dbContext.SaveChangesAsync());
 }