public SkillViewModel(Skill skill) { this.Id = skill.Id; this.Name = skill.Name; this.Description = skill.Description; this.HierarchicalName = skill.HierarchicalName; }
public SkillViewModel(Skill skill) { Id = skill.Id; Name = skill.Name; Description = skill.Description; HierarchicalName = skill.HierarchicalName; }
public IActionResult Edit(Skill skill) { if (ModelState.IsValid) { _dataAccess.UpdateSkill(skill).Wait(); return RedirectToAction("Index", new { area = "Admin" }); } return View(skill).WithSkills(_dataAccess); }
public IActionResult Create(Skill skill) { if (ModelState.IsValid) { _dataAccess.AddSkill(skill).Wait(); return RedirectToAction("Index", new { area = "Admin" }); } return View("Edit", skill).WithSkills(_dataAccess, s => s); }
public void HierarchicalName_ReturnsCorrectName_WhenSkillHasNoChildren() { // Arrange var parentSkill = new Skill { Name = "Parent", Id = 1 }; // Act var result = parentSkill.HierarchicalName; // Assert result.ShouldBe("Parent"); }
public void HierarchicalName_ReturnsCorrectNameForAChildSkill() { // Arrange var parentSkill = new Skill { Name = "Parent", Id = 1 }; var childSkill = new Skill { Name = "Child Skill", ParentSkill = parentSkill, Id = 2, ParentSkillId = 1 }; // Act var result = childSkill.HierarchicalName; // Assert result.ShouldBe("Parent > Child Skill"); }
public void HierarchicalName_ReturnsCorrectNameForAThirdLevelAncestor() { // Arrange var parentSkill = new Skill { Name = "Parent", Id = 1 }; var childSkill = new Skill { Name = "Child Skill", ParentSkill = parentSkill, Id = 2, ParentSkillId = 1 }; var thridAncestorSkills = new Skill { Name = "Final Skill", ParentSkill = childSkill, Id = 3, ParentSkillId = 2 }; // Act var result = thridAncestorSkills.HierarchicalName; // Assert result.ShouldBe("Parent > Child Skill > Final Skill"); }
public void HierarchicalName_ShouldReturnInvalidHierarchy_WhenAChildParentLoopIsDetected() { // DESCRIPTION: It's possible to get an infinite loop with the data so we need to ensure we short circuit that when evaluating the hierarchical name // NOTE: by sgordon - If the code we're testing still creates a loop this will cause this test to also run infinitely - not ideal! // Arrange var parentSkill = new Skill {Name = "Parent", Id = 1 }; var childSkill = new Skill {Name = "Child Skill", ParentSkill = parentSkill, Id = 2, ParentSkillId = 1 }; parentSkill.ParentSkill = childSkill; // Act var parentResult = parentSkill.HierarchicalName; var childResult = childSkill.HierarchicalName; // Assert parentResult.ShouldBe(Skill.InvalidHierarchy); childResult.ShouldBe(Skill.InvalidHierarchy); }
public void DescendantIds_ReturnsNull_WhenThereIsALoopInTheHierarchy() { // Arrange var parentSkill = new Skill { Name = "Parent", Id = 1 }; var childSkill = new Skill { Name = "Child Skill", ParentSkill = parentSkill, Id = 2, ParentSkillId = 1 }; parentSkill.ParentSkill = childSkill; // Act var result = parentSkill.DescendantIds; result.ShouldBeNull(); }
public void DescendantIds_ReturnsCorrectIds_WhenChildrenATMultipleLevels() { // Arrange var sut = new Skill { Id = 1, Name = "Skill", ChildSkills = new List<Skill> { new Skill { Id = 2, Name = "Child", ChildSkills = new List<Skill> { new Skill { Id = 3, Name = "Child 2", ChildSkills = new List<Skill> { new Skill { Id = 4, Name = "Child 3" } } } }}}}; // Act var result = sut.DescendantIds; result.ShouldNotBeEmpty(); result.Count.ShouldBe(3); result.Contains(2).ShouldBeTrue(); result.Contains(3).ShouldBeTrue(); result.Contains(4).ShouldBeTrue(); }
public void DescendantIds_ReturnsCorrectIds_WhenTwoChild_AtSameLevel() { // Arrange var sut = new Skill { Id = 1, Name = "Skill", ChildSkills = new List<Skill> { new Skill { Id = 2, Name = "Child" }, new Skill { Id = 3, Name= "Child 2"} } }; // Act var result = sut.DescendantIds; result.ShouldNotBeEmpty(); result.Count.ShouldBe(2); result.Contains(2).ShouldBeTrue(); result.Contains(3).ShouldBeTrue(); }
public void DescendantIds_ReturnsCorrectId_WhenSingleChild() { // Arrange var sut = new Skill { Id = 1, Name = "Skill", ChildSkills = new List<Skill> { new Skill() { Id = 2, Name = "Child" } } }; // Act var result = sut.DescendantIds; result.ShouldNotBeEmpty(); result.Count.ShouldBe(1); result.Contains(2).ShouldBeTrue(); }
//private static ITaskIdProvider _taskIdProvider = new TaskIdProvider(); public void InsertTestData() { // Avoid polluting the database if there's already something in there. if (_context.Locations.Any() || _context.Organizations.Any() || _context.Tasks.Any() || _context.Campaigns.Any() || _context.Events.Any() || _context.EventSkills.Any() || _context.Skills.Any() || _context.Resources.Any()) { return; } #region postalCodes var existingPostalCode = _context.PostalCodes.ToList(); _context.PostalCodes.AddRange(GetPostalCodes(existingPostalCode)); #endregion List <Organization> organizations = new List <Organization>(); List <Skill> organizationSkills = new List <Skill>(); List <Location> locations = GetLocations(); List <ApplicationUser> users = new List <ApplicationUser>(); List <TaskSignup> taskSignups = new List <TaskSignup>(); List <Event> events = new List <Event>(); List <EventSkill> eventSkills = new List <EventSkill>(); List <Campaign> campaigns = new List <Campaign>(); List <AllReadyTask> tasks = new List <AllReadyTask>(); List <Resource> resources = new List <Resource>(); List <EventSignup> eventSignups = new List <EventSignup>(); List <Contact> contacts = GetContacts(); var skills = new List <Skill>(); #region Skills var medical = new Skill() { Name = "Medical", Description = "specific enough, right?" }; var cprCertified = new Skill() { Name = "CPR Certified", ParentSkill = medical, Description = "ha ha ha ha, stayin alive" }; var md = new Skill() { Name = "MD", ParentSkill = medical, Description = "Trust me, I'm a doctor" }; var surgeon = new Skill() { Name = "Surgeon", ParentSkill = md, Description = "cut open; sew shut; play 18 holes" }; skills.AddRange(new[] { medical, cprCertified, md, surgeon }); #endregion #region Organization Organization htb = new Organization() { Name = "Humanitarian Toolbox", LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png", WebUrl = "http://www.htbox.org", Location = locations.FirstOrDefault(), Campaigns = new List <Campaign>(), OrganizationContacts = new List <OrganizationContact>(), }; #endregion #region Organization Skills organizationSkills.Add(new Skill() { Name = "Code Ninja", Description = "Ability to commit flawless code without review or testing", OwningOrganization = htb }); #endregion #region Campaign Campaign firePrev = new Campaign() { Name = "Neighborhood Fire Prevention Days", ManagingOrganization = htb, TimeZoneId = "Central Standard Time" }; htb.Campaigns.Add(firePrev); var smokeDetImpact = new CampaignImpact { ImpactType = ImpactType.Numeric, NumericImpactGoal = 10000, CurrentImpactLevel = 6722, Display = true, TextualImpactGoal = "Total number of smoke detectors installed." }; _context.CampaignImpacts.Add(smokeDetImpact); Campaign smokeDet = new Campaign() { Name = "Working Smoke Detectors Save Lives", ManagingOrganization = htb, StartDateTime = DateTime.Today.AddMonths(-1), EndDateTime = DateTime.Today.AddMonths(1), CampaignImpact = smokeDetImpact, TimeZoneId = "Central Standard Time" }; htb.Campaigns.Add(smokeDet); Campaign financial = new Campaign() { Name = "Everyday Financial Safety", ManagingOrganization = htb, TimeZoneId = "Central Standard Time" }; htb.Campaigns.Add(financial); Campaign safetyKit = new Campaign() { Name = "Simple Safety Kit Building", ManagingOrganization = htb, TimeZoneId = "Central Standard Time" }; htb.Campaigns.Add(safetyKit); Campaign carSafe = new Campaign() { Name = "Family Safety In the Car", ManagingOrganization = htb, TimeZoneId = "Central Standard Time" }; htb.Campaigns.Add(carSafe); Campaign escapePlan = new Campaign() { Name = "Be Ready to Get Out: Have a Home Escape Plan", ManagingOrganization = htb, TimeZoneId = "Central Standard Time" }; htb.Campaigns.Add(escapePlan); #endregion #region Event Event queenAnne = new Event() { Name = "Queen Anne Fire Prevention Day", StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), RequiredSkills = new List <EventSkill>() }; queenAnne.Tasks = GetSomeTasks(queenAnne, htb); var ask = new EventSkill() { Skill = surgeon, Event = queenAnne }; queenAnne.RequiredSkills.Add(ask); eventSkills.Add(ask); ask = new EventSkill() { Skill = cprCertified, Event = queenAnne }; queenAnne.RequiredSkills.Add(ask); eventSkills.Add(ask); tasks.AddRange(queenAnne.Tasks); Event ballard = new Event() { Name = "Ballard Fire Prevention Day", StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 31, 14, 0, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = firePrev }; ballard.Tasks = GetSomeTasks(ballard, htb); tasks.AddRange(ballard.Tasks); Event madrona = new Event() { Name = "Madrona Fire Prevention Day", StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 31, 14, 0, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = firePrev }; madrona.Tasks = GetSomeTasks(madrona, htb); tasks.AddRange(madrona.Tasks); Event southLoopSmoke = new Event() { Name = "Smoke Detector Installation and Testing-South Loop", StartDateTime = DateTime.Today.AddMonths(-1), EndDateTime = DateTime.Today.AddMonths(1), Location = GetRandom <Location>(locations), Campaign = smokeDet }; southLoopSmoke.Tasks = GetSomeTasks(southLoopSmoke, htb); tasks.AddRange(southLoopSmoke.Tasks); Event northLoopSmoke = new Event() { Name = "Smoke Detector Installation and Testing-Near North Side", StartDateTime = DateTime.Today.AddMonths(-1), EndDateTime = DateTime.Today.AddMonths(1), Location = GetRandom <Location>(locations), Campaign = smokeDet }; northLoopSmoke.Tasks = GetSomeTasks(northLoopSmoke, htb); tasks.AddRange(northLoopSmoke.Tasks); Event rentersInsurance = new Event() { Name = "Renters Insurance Education Door to Door and a bag of chips", Description = "description for the win", StartDateTime = new DateTime(2015, 7, 11, 8, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 7, 11, 17, 0, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = financial }; rentersInsurance.Tasks = GetSomeTasks(rentersInsurance, htb); tasks.AddRange(rentersInsurance.Tasks); Event rentersInsuranceEd = new Event() { Name = "Renters Insurance Education Door to Door (woop woop)", Description = "another great description", StartDateTime = new DateTime(2015, 7, 12, 8, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 12, 17, 0, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = financial }; rentersInsuranceEd.Tasks = GetSomeTasks(rentersInsuranceEd, htb); tasks.AddRange(rentersInsuranceEd.Tasks); Event safetyKitBuild = new Event() { Name = "Safety Kit Assembly Volunteer Day", Description = "Full day of volunteers building kits", StartDateTime = new DateTime(2015, 7, 11, 8, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 11, 16, 30, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = safetyKit }; safetyKitBuild.Tasks = GetSomeTasks(safetyKitBuild, htb); tasks.AddRange(safetyKitBuild.Tasks); Event safetyKitHandout = new Event() { Name = "Safety Kit Distribution Weekend", Description = "Handing out kits at local fire stations", StartDateTime = new DateTime(2015, 7, 11, 8, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 11, 16, 30, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = safetyKit }; safetyKitHandout.Tasks = GetSomeTasks(safetyKitHandout, htb); tasks.AddRange(safetyKitHandout.Tasks); Event carSeatTest1 = new Event() { Name = "Car Seat Testing-Naperville", Description = "Checking car seats at local fire stations after last day of school year", StartDateTime = new DateTime(2015, 7, 10, 9, 30, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 10, 15, 30, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = carSafe }; carSeatTest1.Tasks = GetSomeTasks(carSeatTest1, htb); tasks.AddRange(carSeatTest1.Tasks); Event carSeatTest2 = new Event() { Name = "Car Seat and Tire Pressure Checking Volunteer Day", Description = "Checking those things all day at downtown train station parking", StartDateTime = new DateTime(2015, 7, 11, 8, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 11, 19, 30, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = carSafe }; carSeatTest2.Tasks = GetSomeTasks(carSeatTest2, htb); tasks.AddRange(carSeatTest2.Tasks); Event homeFestival = new Event() { Name = "Park District Home Safety Festival", Description = "At downtown park district(adjacent to pool)", StartDateTime = new DateTime(2015, 7, 11, 12, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 11, 16, 30, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = safetyKit }; homeFestival.Tasks = GetSomeTasks(homeFestival, htb); tasks.AddRange(homeFestival.Tasks); Event homeEscape = new Event() { Name = "Home Escape Plan Flyer Distribution", Description = "Handing out flyers door to door in several areas of town after school/ work hours.Streets / blocks will vary but number of volunteers.", StartDateTime = new DateTime(2015, 7, 15, 15, 30, 0).ToUniversalTime(), EndDateTime = new DateTime(2015, 12, 15, 20, 30, 0).ToUniversalTime(), Location = GetRandom <Location>(locations), Campaign = escapePlan }; homeEscape.Tasks = GetSomeTasks(homeEscape, htb); tasks.AddRange(homeEscape.Tasks); #endregion #region Link campaign and event firePrev.Events = new List <Event>(); firePrev.Events.Add(queenAnne); firePrev.Events.Add(ballard); firePrev.Events.Add(madrona); smokeDet.Events = new List <Event>(); smokeDet.Events.Add(southLoopSmoke); smokeDet.Events.Add(northLoopSmoke); financial.Events = new List <Event>(); financial.Events.Add(rentersInsurance); financial.Events.Add(rentersInsuranceEd); safetyKit.Events = new List <Event>(); safetyKit.Events.Add(safetyKitBuild); safetyKit.Events.Add(safetyKitHandout); carSafe.Events = new List <Event>(); carSafe.Events.Add(carSeatTest1); carSafe.Events.Add(carSeatTest2); escapePlan.Events = new List <Event>(); escapePlan.Events.Add(homeFestival); escapePlan.Events.Add(homeEscape); #endregion #region Add Campaigns and Events organizations.Add(htb); campaigns.Add(firePrev); campaigns.Add(smokeDet); campaigns.Add(financial); campaigns.Add(escapePlan); campaigns.Add(safetyKit); campaigns.Add(carSafe); events.AddRange(firePrev.Events); events.AddRange(smokeDet.Events); events.AddRange(financial.Events); events.AddRange(escapePlan.Events); events.AddRange(safetyKit.Events); events.AddRange(carSafe.Events); #endregion #region Insert Resource items into Resources resources.Add(new Resource { Name = "allReady Partner Name", Description = "allready Partner Description", PublishDateBegin = DateTime.Today, PublishDateEnd = DateTime.Today.AddDays(14), MediaUrl = "", ResourceUrl = "", CategoryTag = "Partners" }); resources.Add(new Resource { Name = "allReady Partner Name 2", Description = "allready Partner Description 2", PublishDateBegin = DateTime.Today.AddDays(-3), PublishDateEnd = DateTime.Today.AddDays(-1), MediaUrl = "", ResourceUrl = "", CategoryTag = "Partners" }); #endregion #region Insert into DB _context.Skills.AddRange(skills); _context.Contacts.AddRange(contacts); _context.EventSkills.AddRange(eventSkills); _context.Locations.AddRange(locations); _context.Organizations.AddRange(organizations); _context.Tasks.AddRange(tasks); _context.Campaigns.AddRange(campaigns); _context.Events.AddRange(events); _context.Resources.AddRange(resources); //_context.SaveChanges(); #endregion #region Users for Events var username1 = $"{_settings.DefaultUsername}1.com"; var username2 = $"{_settings.DefaultUsername}2.com"; var username3 = $"{_settings.DefaultUsername}3.com"; var user1 = new ApplicationUser { UserName = username1, Email = username1, EmailConfirmed = true, TimeZoneId = _generalSettings.DefaultTimeZone }; _userManager.CreateAsync(user1, _settings.DefaultAdminPassword).GetAwaiter().GetResult(); users.Add(user1); var user2 = new ApplicationUser { UserName = username2, Email = username2, EmailConfirmed = true, TimeZoneId = _generalSettings.DefaultTimeZone }; _userManager.CreateAsync(user2, _settings.DefaultAdminPassword).GetAwaiter().GetResult(); users.Add(user2); var user3 = new ApplicationUser { UserName = username3, Email = username3, EmailConfirmed = true, TimeZoneId = _generalSettings.DefaultTimeZone }; _userManager.CreateAsync(user3, _settings.DefaultAdminPassword).GetAwaiter().GetResult(); users.Add(user3); #endregion #region ActvitySignups eventSignups.Add(new EventSignup { Event = madrona, User = user1, SignupDateTime = DateTime.UtcNow }); eventSignups.Add(new EventSignup { Event = madrona, User = user2, SignupDateTime = DateTime.UtcNow }); eventSignups.Add(new EventSignup { Event = madrona, User = user3, SignupDateTime = DateTime.UtcNow }); #endregion #region TaskSignups int i = 0; foreach (var task in tasks.Where(t => t.Event == madrona)) { for (var j = 0; j < i; j++) { taskSignups.Add(new TaskSignup() { Task = task, User = users[j], Status = Areas.Admin.Features.Tasks.TaskStatus.Assigned.ToString() }); } i = (i + 1) % users.Count; } _context.TaskSignups.AddRange(taskSignups); #endregion #region TennatContacts htb.OrganizationContacts.Add(new OrganizationContact { Contact = contacts.First(), Organization = htb, ContactType = 1 /*Primary*/ }); #endregion #region Wrap Up DB _context.EventSignup.AddRange(eventSignups); _context.SaveChanges(); #endregion }
protected override void LoadTestData() { var skillOne = new Skill() { Name = "Skill One" }; var skillTwo = new Skill() { Name = "Skill Two" }; Context.AddRange(skillOne, skillTwo); var @event = new Event() { Campaign = new Campaign(), Name = "Name", Description = "Description", EventType = EventType.Itinerary, NumberOfVolunteersRequired = 10, StartDateTime = new DateTimeOffset(2016, 1, 1, 0, 0, 0, new TimeSpan()), EndDateTime = new DateTimeOffset(2016, 1, 31, 0, 0, 0, new TimeSpan()), Location = new Location() { Address1 = "Address1", Address2 = "Address2", City = "City", State = "State", PostalCode = "PostalCode", Name = "Name", PhoneNumber = "PhoneNumber", Country = "Country" }, Tasks = new List<AllReadyTask>() { new AllReadyTask() { StartDateTime = new DateTimeOffset(2016, 1, 1, 9, 0, 0, new TimeSpan()), EndDateTime = new DateTimeOffset(2016, 1, 1, 17, 0, 0, new TimeSpan()), AssignedVolunteers = new List<TaskSignup>() { new TaskSignup(), new TaskSignup() }, RequiredSkills = new List<TaskSkill>() { new TaskSkill() { Skill = skillOne }, new TaskSkill() { Skill = skillTwo }, }, }, new AllReadyTask() { StartDateTime = new DateTimeOffset(2016, 1, 2, 10, 0, 0, new TimeSpan()), EndDateTime = new DateTimeOffset(2016, 1, 2, 16, 0, 0, new TimeSpan()), AssignedVolunteers = new List<TaskSignup>() { new TaskSignup(), new TaskSignup() } }, }, UsersSignedUp = new List<EventSignup>() { new EventSignup(), new EventSignup(), }, Organizer = new ApplicationUser() { Id = "Organizer" }, ImageUrl = "ImageUrl", RequiredSkills = new List<EventSkill>() { new EventSkill() { Skill = skillOne }, new EventSkill() { Skill = skillTwo }, }, IsLimitVolunteers = false, IsAllowWaitList = true }; Context.Add(@event.Campaign); Context.Add(@event.Location); Context.Add(@event.Organizer); Context.Add(@event); Context.SaveChanges(); }
Task IAllReadyDataAccess.UpdateSkill(Skill value) { _dbContext.Skills.Update(value); return _dbContext.SaveChangesAsync(); }
public void DescendantIds_ReturnsEmptyList_WhenChildSkillsIsEmpty() { // Arrange var sut = new Skill { Id = 1, Name = "Skill", ChildSkills = new List<Skill>()}; // Act var result = sut.DescendantIds; result.ShouldBeEmpty(); }
public void DescendantIds_ReturnsNull_WhenChildSkillsIsNull() { // Arrange var sut = new Skill { Id = 1, Name = "Skill" }; // Act var result = sut.DescendantIds; result.ShouldBeNull(); }
private List<int> EvaluateDescendantIds(Skill skill, List<int> descendantIds = null, List<int> priorSkills = null) { // NOTE: by sgordon - Whilst we have limited skills in the system this is okay. In time, depending on the growth of skills we should review more efficient ways to get this information // and caching of the resulting data to reduce the impact of this requirement. if (skill == null) { throw new ArgumentNullException(nameof(skill)); } if (priorSkills == null) { priorSkills = new List<int> { skill.Id }; } else { if (priorSkills.Any(x => x == skill.Id)) { return null; // we safety check we aren't in a perpetual loop caused by an invalid hierarchy using the iteration count } } if (descendantIds == null) { descendantIds = new List<int>(); } if (skill.ChildSkills != null) { foreach (var childSkill in skill.ChildSkills) { descendantIds.Add(childSkill.Id); EvaluateDescendantIds(childSkill, descendantIds, priorSkills); priorSkills.Add(childSkill.Id); } } return descendantIds; }