public async Task ScheduleISendRequestConfirmationMessagesSevenDaysBeforeAnItineraryDateWithTheCorrectMethodSignatureAndTheCorrectDate() { var dateTimeNow = DateTime.Today; var dateTimeNowUnspecified = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Unspecified); var requestId = Guid.NewGuid(); var message = new InitialRequestConfirmationsSent { ItineraryId = 1, RequestIds = new List<Guid> { requestId } }; var @event = new Event { Id = 1, TimeZoneId = "Eastern Standard Time" }; var itinerary = new Itinerary { Id = 1, Date = dateTimeNowUnspecified, EventId = @event.Id, Event = @event }; Context.Requests.Add(new Request { RequestId = requestId }); Context.Itineraries.Add(itinerary); Context.Events.Add(@event); Context.SaveChanges(); var backgroundJobClient = new Mock<IBackgroundJobClient>(); var sut = new InitialRequestConfirmationsSentHandler(Context, backgroundJobClient.Object); await sut.Handle(message); backgroundJobClient.Verify(x => x.Create(It.Is<Job>(job => job.Type == typeof(ISendRequestConfirmationMessagesSevenDaysBeforeAnItineraryDate) && job.Method.Name == nameof(ISendRequestConfirmationMessagesSevenDaysBeforeAnItineraryDate.SendSms) && job.Args[0] == message.RequestIds && (int)job.Args[1] == message.ItineraryId), It.Is<ScheduledState>(ss => ss.EnqueueAt.Date.AddHours(12) == itinerary.Date.Date.AddDays(-7).AddHours(12))), Times.Once); }
public void SendRequestConfirmationsToTheCorrectPhoneNumberWithTheCorrectMessage_WhenRequestIdsMatchExistingRequests_AndThoseRequestsHaveAStatusOfPendingConfirmation_AndTodayIsTheSameDateAsTheItineraryDate() { var dateTimeNow = DateTime.Today; var dateTimeNowUnspecified = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Unspecified); var dateTimeUtcNow = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Utc); var requestorPhoneNumbers = new List<string> { "111-111-1111" }; var @event = new Event { Id = 1, TimeZoneId = "Eastern Standard Time" }; var itinerary = new Itinerary { Id = 1, Date = dateTimeNowUnspecified.Date, EventId = @event.Id, Event = @event }; var request = new Request { RequestId = Guid.NewGuid(), Status = RequestStatus.PendingConfirmation, Phone = requestorPhoneNumbers[0] }; var requestIds = new List<Guid> { request.RequestId }; var smsSender = new Mock<ISmsSender>(); Context.Requests.Add(request); Context.Itineraries.Add(itinerary); Context.Events.Add(@event); Context.SaveChanges(); var sut = new SendRequestConfirmationMessagesTheDayOfAnItineraryDate(Context, smsSender.Object, Mock.Of<IMediator>()) { DateTimeUtcNow = () => dateTimeUtcNow.Date }; sut.SendSms(requestIds, itinerary.Id); smsSender.Verify(x => x.SendSmsAsync(requestorPhoneNumbers, "sorry you couldn't make it, we will reschedule.")); }
protected override void LoadTestData() { _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>() }; _firePrev = new Campaign() { Name = "Neighborhood Fire Prevention Days", ManagingOrganization = _htb, CampaignContacts = new List<CampaignContact>() }; _htb.Campaigns.Add(_firePrev); _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>(), Tasks = new List<AllReadyTask>() }; Context.Events.Add(_queenAnne); Context.SaveChanges(); }
public void GetCampaignsByPostalCodeReturnsCorrectResults() { var event1 = new Event { Id = 1, CampaignId = 1 }; event1.Campaign = new Campaign { Id = 1, Events = new List<Event> { event1 }, ManagingOrganization = new Organization() }; var event2 = new Event { Id = 2 }; var event3 = new Event { Id = 3 }; var campaign2 = new Campaign { Id = 2, Events = new List<Event> { event2, event3 }, ManagingOrganization = new Organization() }; event2.CampaignId = campaign2.Id; event2.Campaign = campaign2; event3.CampaignId = campaign2.Id; event3.Campaign = campaign2; var allEvents = new List<Event> { event1, event2, event3 }; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.Send(It.IsAny<EventsByPostalCodeQuery>())).Returns(allEvents); var sut = new CampaignApiController(mediator.Object); var results = sut.GetCampaignsByPostalCode(It.IsAny<string>(), It.IsAny<int>()); Assert.Equal(results.Count(), allEvents.Count); }
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 }; htb.Campaigns.Add(firePrev); 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>() }; context.Organizations.Add(htb); context.Events.Add(queenAnne); context.SaveChanges(); }
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(); }
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(); }
Task IAllReadyDataAccess.UpdateEvent(Event value) { //First remove any skills that are no longer associated with this event var acsksToRemove = _dbContext.EventSkills.Where(acsk => acsk.EventId == value.Id && (value.RequiredSkills == null || !value.RequiredSkills.Any(acsk1 => acsk1.SkillId == acsk.SkillId))); _dbContext.EventSkills.RemoveRange(acsksToRemove); _dbContext.Events.Update(value); return _dbContext.SaveChangesAsync(); }
public void SetOrganizationIdAndOrganizationName_WhenConstructingWithNonNullCampaignAndNonNullManagingOrganization() { var campaign = new Campaign { ManagingOrganization = new Organization { Id = 1, Name = "OrgName" } }; var @event = new Event { Campaign = campaign }; var sut = new EventViewModel(@event); Assert.Equal(sut.OrganizationId, campaign.ManagingOrganization.Id); Assert.Equal(sut.OrganizationName, campaign.ManagingOrganization.Name); }
public void SetCampaignIdCampaignNameAndTimeZoneId_WhenConstructingWithNonNullCampaign() { var campaign = new Campaign { Id = 1, Name = "Campaignname", TimeZoneId = "CampaignTimeZoneId" }; var @event = new Event { Campaign = campaign, TimeZoneId = "EventTimeZoneId" }; var sut = new EventViewModel(@event); Assert.Equal(sut.CampaignId, campaign.Id); Assert.Equal(sut.CampaignName, campaign.Name); Assert.Equal(sut.TimeZoneId, @event.TimeZoneId); }
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 EventsByApplicationUserIdQueryHandlerShould() { message = new EventsByApplicationUserIdQuery { ApplicationUserId = Guid.NewGuid().ToString() }; @event = new Event { Organizer = new ApplicationUser {Id = message.ApplicationUserId } }; Context.Add(@event); Context.SaveChanges(); sut = new EventsByApplicationUserIdQueryHandler(Context); }
protected override void LoadTestData() { Context.Users.Add(new ApplicationUser { Id = "abc" }); var campaignEvent = new Event { Id = 1, Name = "Some Event" }; Context.Events.Add(campaignEvent); Context.Tasks.Add(new AllReadyTask { Id = 1, Name = "Closed Task", EndDateTime = DateTime.UtcNow.AddDays(-100), Event = campaignEvent }); Context.Tasks.Add(new AllReadyTask { Id = 2, Name = "Open Task", EndDateTime = DateTime.UtcNow.AddDays(100), Event = campaignEvent }); Context.SaveChanges(); }
protected override void LoadTestData() { var context = ServiceProvider.GetService<AllReadyContext>(); var seattlePostalCode = new PostalCodeGeo { City = "Seattle", PostalCode = "98117", State = "WA" }; var seattle = new Location { Id = 1, Address1 = "123 Main Street", Address2 = "Unit 2", City = "Seattle", PostalCode = seattlePostalCode, Country = "USA", State = "WA", Name = "Organizer name", PhoneNumber = "555-555-5555" }; 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 }; htb.Campaigns.Add(firePrev); 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>() }; context.PostalCodes.Add(seattlePostalCode); context.Locations.Add(seattle); context.Organizations.Add(htb); context.Events.Add(queenAnne); context.SaveChanges(); }
public async Task ReturnCorrectViewModel() { var @event = new Event { Campaign = new Campaign { ManagingOrganization = new Organization { Id = 1 }}}; Context.Events.Add(@event); await Context.SaveChangesAsync(); var message = new OrganizationIdByEventIdQuery { EventId = @event.Id }; var sut = new OrganizationIdByEventIdQueryHandler(Context); var result = await sut.Handle(message); Assert.Equal(result, @event.Campaign.ManagingOrganization.Id); }
public async System.Threading.Tasks.Task ReturnCorrectErrorWhenModelsStartDateTimeIsLessThanParentEventStartDate() { var now = DateTimeOffset.Now; var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC", }, TimeZoneId = "UTC", StartDateTime = now.AddDays(1), EndDateTime = now.AddDays(-1) }; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event); var validator = new TaskEditViewModelValidator(mockMediator.Object); var errors = await validator.Validate(new EditViewModel()); Assert.True(errors.Exists(x => x.Key.Equals("StartDateTime"))); Assert.Equal(errors.Find(x => x.Key == "StartDateTime").Value, String.Format("Start date cannot be earlier than the event start date {0:g}.", @event.StartDateTime)); }
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(); }
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 }; htb.Campaigns.Add(firePrev); 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>(), EventType = EventType.Itinerary }; var itinerary = new Itinerary { Event = queenAnne, Name = "1st Itinerary", Id = 1, Date = new DateTime(2016, 07, 01) }; var taskSignUp = new TaskSignup { Id = 1, ItineraryId = 2, TaskId = 1 }; Context.Organizations.Add(htb); Context.Campaigns.Add(firePrev); Context.Events.Add(queenAnne); Context.Itineraries.Add(itinerary); Context.TaskSignups.Add(taskSignUp); Context.SaveChanges(); }
public async Task ReturnCorrectData() { var @event = new Event { Id = 1, Campaign = new Campaign { Id = 1, Name = "CampaignName", ManagingOrganization = new Organization { Id = 1 }}}; Context.Events.Add(@event); Context.SaveChanges(); var sut = new DeleteQueryHandler(Context); var result = await sut.Handle(new DeleteQuery { EventId = @event.Id }); Assert.Equal(result.Id, @event.Id); Assert.Equal(result.Name, @event.Name); Assert.Equal(result.CampaignId, @event.Campaign.Id); Assert.Equal(result.CampaignName, @event.Campaign.Name); Assert.Equal(result.OrganizationId, @event.Campaign.ManagingOrganization.Id); Assert.Equal(result.StartDateTime, @event.StartDateTime); Assert.Equal(result.EndDateTime, @event.EndDateTime); }
public CreateTaskQueryHandlerAsyncShould() { @event = new Event { Id = 1, Name = "EventName", StartDateTime = DateTimeOffset.Now, EndDateTime = DateTimeOffset.Now, Campaign = new Campaign { StartDateTime = DateTimeOffset.Now, EndDateTime = DateTimeOffset.Now, Name = "CampaignName", ManagingOrganizationId = 2, TimeZoneId = "Central Standard Time" } }; Context.Add(@event); Context.SaveChanges(); message = new CreateTaskQueryAsync { EventId = @event.Id }; sut = new CreateTaskQueryHandlerAsync(Context); }
public async System.Threading.Tasks.Task InvokeGetDateTimeOffsetWithCorrectParametersForEndDate() { var now = DateTimeOffset.Now; var model = new EditViewModel { EventId = 1, StartDateTime = now, EndDateTime = now }; var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC" } }; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event); var dateTimeOffsetProvider = new Mock<IConvertDateTimeOffset>(); var sut = new TaskEditViewModelValidator(mediator.Object, dateTimeOffsetProvider.Object); await sut.Validate(model); dateTimeOffsetProvider.Verify(x => x.ConvertDateTimeOffsetTo(@event.Campaign.TimeZoneId, model.EndDateTime, model.EndDateTime.Hour, model.EndDateTime.Minute, 0)); }
public void ConstructEventViewModel_WithTheCorrectData() { var campaign = new Campaign { Id = 1, Name = "Campaignname", TimeZoneId = "CampaignTimeZoneId" }; var location = new AllReady.ViewModels.Shared.LocationViewModel { City = "Amsterdam" }; var skills = new List<SkillViewModel> { new SkillViewModel { Name = "F sharp" } }; var userSkills = new List<SkillViewModel> { new SkillViewModel { Name = "Medic", Description = "first aid helper", HierarchicalName = "med01", Id = 1 } }; var signup = new AllReady.ViewModels.Shared.TaskSignupViewModel { Name = "task1", TaskId = 1 }; var @event = new Event { Campaign = campaign, TimeZoneId = "EventTimeZoneId" }; var sut = new EventViewModel(@event); var @task = new TaskViewModel { CampaignName = sut.CampaignName, CampaignId = sut.CampaignId, eventName = sut.Title, Name = "tasks" }; var tasks = new List<TaskViewModel> { @task }; sut.Description = "Testing the allReady from htbox"; sut.EndDateTime = DateTimeOffset.Now.AddDays(3650); sut.EventType = EventType.Rally; sut.HasPrivacyPolicy = false; sut.Headline = "the Already test campaing"; sut.Id = 1; sut.ImageUrl = "http://www.htbox.org/"; sut.IsAllowWaitList = false; sut.IsClosed = false; sut.IsLimitVolunteers = true; sut.Location = location; sut.OrganizationId = 1; sut.OrganizationName = "TestOrg"; sut.RequiredSkills = skills; sut.SignupModel = signup; sut.StartDateTime = DateTimeOffset.Now.AddDays(365); sut.Tasks = tasks; sut.TimeZoneId = "US Mountain Standard Time"; sut.Title = "Test Event"; sut.UserId = "99"; sut.UserSkills = userSkills; sut.UserTasks = tasks; Assert.Equal(sut.CampaignId, campaign.Id); Assert.Equal(sut.CampaignName, campaign.Name); Assert.Equal(sut.Location, location); Assert.Equal(sut.UserSkills, userSkills); Assert.Equal(sut.UserTasks, tasks); Assert.Equal(sut.SignupModel, signup); Assert.Equal(sut.RequiredSkills, skills); }
public EventViewModel(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 => acsk.Skill).ToList(); IsLimitVolunteers = campaignEvent.IsLimitVolunteers; IsAllowWaitList = campaignEvent.IsAllowWaitList; }
public async System.Threading.Tasks.Task ReturnCorrectErrorWhenModelsEndDateTimeIsGreaterThanParentEventStartDate() { var now = DateTimeOffset.Now; var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC", }, StartDateTime = now, EndDateTime = now.AddDays(-1) }; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event); var validator = new TaskEditViewModelValidator(mediator.Object); var errors = await validator.Validate(new EditViewModel { EndDateTime = now.AddDays(-1).AddMinutes(15) }); Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime"))); Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, String.Format("The end date of this task cannot be after the end date of the event {0:g}", @event.EndDateTime)); }
public async System.Threading.Tasks.Task ReturnCorrectErrorWhenEndDateTimeIsLessThanStartDateTime() { var now = DateTimeOffset.Now; var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC" }}; var dateTimeOffsetProvider = new Mock<IConvertDateTimeOffset>(); dateTimeOffsetProvider.SetupSequence(x => x.ConvertDateTimeOffsetTo(It.IsAny<string>(), It.IsAny<DateTimeOffset>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) .Returns(now.AddDays(1)) .Returns(now.AddDays(-1)); var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event); var validator = new TaskEditViewModelValidator(mockMediator.Object, dateTimeOffsetProvider.Object); var errors = await validator.Validate(new EditViewModel()); Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime"))); Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, "End date cannot be earlier than the start date"); }
public void CreateGetReturnsCorrectViewModel() { const int organizationId = 1; const int campaignId = 1; var campaignStartDateTime = DateTime.Now.AddDays(-1); var campaignEndDateTime = DateTime.Now.AddDays(1); var campaignEvent = new Event { Id = 1, Name = "EventName", CampaignId = campaignId, Campaign = new Campaign { Id = campaignId, Name = "CampaignName", ManagingOrganizationId = organizationId, TimeZoneId = "EST", StartDateTime = campaignStartDateTime, EndDateTime = campaignEndDateTime } }; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(campaignEvent); var sut = new TaskController(mediator.Object, Mock.Of<ITaskSummaryModelValidator>()); MakeUserOrganizationAdminUser(sut, organizationId.ToString()); var result = sut.Create(It.IsAny<int>()) as ViewResult; var modelResult = result.ViewData.Model as TaskSummaryModel; Assert.Equal(modelResult.EventId, campaignEvent.Id); Assert.Equal(modelResult.EventName, campaignEvent.Name); Assert.Equal(modelResult.CampaignId, campaignEvent.CampaignId); Assert.Equal(modelResult.CampaignName, campaignEvent.Campaign.Name); Assert.Equal(modelResult.OrganizationId, campaignEvent.Campaign.ManagingOrganizationId); Assert.Equal(modelResult.TimeZoneId, campaignEvent.Campaign.TimeZoneId); Assert.Equal(modelResult.StartDateTime, campaignEvent.StartDateTime); Assert.Equal(modelResult.EndDateTime, campaignEvent.EndDateTime); }
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 System.Threading.Tasks.Task ReturnCorrectErrorWhenEndDateTimeIsLessThanStartDateTime() { var now = DateTimeOffset.Now; var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC" }, TimeZoneId = "UTC"}; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event); var validator = new TaskEditViewModelValidator(mockMediator.Object); var errors = await validator.Validate(new EditViewModel { StartDateTime = now, EndDateTime = now.AddMinutes(-30) }); Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime"))); Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, "End date cannot be earlier than the start date"); }
public async Task CreateNewTaskSuccessfully() { var @event = new Event { Id = 1, IsLimitVolunteers = true, IsAllowWaitList = false }; var organization = new Organization { Id = 2 }; var message = new EditTaskCommandAsync { Task = new EditViewModel { Name = "TaskName", Description = "TaskDescription", EventId = @event.Id, OrganizationId = organization.Id, TimeZoneId = "Central Standard Time", StartDateTime = DateTimeOffset.Now, EndDateTime = DateTimeOffset.Now, NumberOfVolunteersRequired = 5, RequiredSkills = new List<TaskSkill> { new TaskSkill { SkillId = 3, Skill = new Skill { Id = 3, Name = "SkillName", Description = "SkillDescription" } } } } }; Context.Database.EnsureDeleted(); Context.Events.Add(@event); Context.Organizations.Add(organization); Context.SaveChanges(); var sut = new EditTaskCommandHandlerAsync(Context); var taskId = await sut.Handle(message); var result = Context.Tasks.Single(x => x.Id == taskId); Assert.True(taskId > 0); 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 async Task UpdateRequestStatusToPendingConfirmation() { var dateTimeNow = DateTime.Today; var dateTimeNowUnspecified = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Unspecified); var requestId = Guid.NewGuid(); var message = new InitialRequestConfirmationsSent { ItineraryId = 1, RequestIds = new List<Guid> { requestId }}; var @event = new Event { Id = 1, TimeZoneId = "Eastern Standard Time" }; var itinerary = new Itinerary { Id = 1, Date = dateTimeNowUnspecified, EventId = @event.Id, Event = @event }; Context.Requests.Add(new Request { RequestId = requestId }); Context.Itineraries.Add(itinerary); Context.Events.Add(@event); Context.SaveChanges(); var backgroundJobClient = new Mock<IBackgroundJobClient>(); var sut = new InitialRequestConfirmationsSentHandler(Context, backgroundJobClient.Object); await sut.Handle(message); var result = Context.Requests.Single(x => x.RequestId == message.RequestIds.First()); Assert.True(result.Status == RequestStatus.PendingConfirmation); }
protected override void LoadTestData() { var user = new ApplicationUser(); var org = new Organization { Name = "Test Org" }; var campaign1 = new Campaign { Name = "Campaign 1", ManagingOrganization = org }; var campaign2 = new Campaign { Name = "Campaign 2", ManagingOrganization = org }; var campaignEvent1 = new AllReady.Models.Event { Name = "Event 1", Campaign = campaign1, TimeZoneId = "enGB" }; var campaignEvent2 = new AllReady.Models.Event { Name = "Event 2", Campaign = campaign2, TimeZoneId = "enGB" }; var itinerary1 = new Itinerary { Name = "Itinerary 1", Event = campaignEvent1, Date = DateTime.UtcNow }; var itinerary2 = new Itinerary { Name = "Itinerary 2", Event = campaignEvent1, Date = DateTime.UtcNow }; var itinerary3 = new Itinerary { Name = "Itinerary 3", Event = campaignEvent2, Date = DateTime.UtcNow }; var taskSignup1 = new VolunteerTaskSignup { User = user, Itinerary = itinerary1, IsTeamLead = true }; var taskSignup2 = new VolunteerTaskSignup { User = user, Itinerary = itinerary2, IsTeamLead = true }; var taskSignup3 = new VolunteerTaskSignup { User = user, Itinerary = itinerary3, IsTeamLead = true }; Context.VolunteerTaskSignups.Add(taskSignup1); Context.VolunteerTaskSignups.Add(taskSignup2); Context.VolunteerTaskSignups.Add(taskSignup3); Context.SaveChanges(); _user = user; }