private era_task CreateTask(EssContext essContext, string taskId, DateTime startDate) { var task = new era_task { era_taskid = Guid.NewGuid(), era_name = taskId, era_taskstartdate = startDate, era_currentdateandtime = startDate.AddDays(3), }; essContext.AddToera_tasks(task); var jurisdiction = jurisdictions.SingleOrDefault(j => j.era_jurisdictionid == testTeam.era_ESSTeam_ESSTeamArea_ESSTeamID.FirstOrDefault()?._era_jurisdictionid_value); if (jurisdiction != null) { essContext.SetLink(task, nameof(era_task.era_JurisdictionID), jurisdiction); task._era_jurisdictionid_value = jurisdiction.era_jurisdictionid; } return(task); }
public DynamicsTestData(IEssContextFactory essContextFactory) { var essContext = essContextFactory.Create(); jurisdictions = essContext.era_jurisdictions.OrderBy(j => j.era_jurisdictionid).ToArray(); canada = essContext.era_countries.Where(c => c.era_countrycode == "CAN").Single(); bc = essContext.era_provinceterritorieses.Where(c => c.era_code == "BC").Single(); #if DEBUG this.testPrefix = $"autotest-dev"; #else this.testPrefix = $"autotest-{TestHelper.GenerateNewUniqueId(string.Empty)}"; #endif this.activeTaskId = testPrefix + "-active-task"; this.inactiveTaskId = testPrefix + "-inactive-task"; var existingTeam = essContext.era_essteams.Where(t => t.era_name == testPrefix + "-team").SingleOrDefault(); if (existingTeam != null) { essContext.LoadProperty(existingTeam, nameof(era_essteam.era_ESSTeam_ESSTeamArea_ESSTeamID)); this.testTeam = existingTeam; this.CreateTeamMember(essContext, testTeam, Guid.NewGuid(), "-second"); CreateTeamMember(essContext, testTeam, Guid.NewGuid(), "-third"); CreateTeamMember(essContext, testTeam, Guid.NewGuid(), "-fourth"); } else { this.testTeam = CreateTeam(essContext, Guid.NewGuid()); } var otherTeam = essContext.era_essteams.Where(t => t.era_name == testPrefix + "-team-other").SingleOrDefault(); if (otherTeam != null) { essContext.LoadProperty(otherTeam, nameof(era_essteam.era_ESSTeam_ESSTeamArea_ESSTeamID)); this.otherTestTeam = otherTeam; } else { this.otherTestTeam = CreateTeam(essContext, Guid.NewGuid(), "-other"); } this.activeTask = essContext.era_tasks.Where(t => t.era_name == activeTaskId).SingleOrDefault() ?? CreateTask(essContext, activeTaskId, DateTime.UtcNow); this.inactiveTask = essContext.era_tasks.Where(t => t.era_name == activeTaskId).SingleOrDefault() ?? CreateTask(essContext, inactiveTaskId, DateTime.UtcNow.AddDays(-7)); this.tier4TeamMember = essContext.era_essteamusers.Where(tu => tu.era_firstname == this.testPrefix + "-first" && tu.era_lastname == this.testPrefix + "-last").SingleOrDefault() ?? CreateTeamMember(essContext, testTeam, Guid.NewGuid()); this.otherTeamMember = essContext.era_essteamusers.Where(tu => tu.era_firstname == this.testPrefix + "-first-other" && tu.era_lastname == this.testPrefix + "-last-other").SingleOrDefault() ?? CreateTeamMember(essContext, this.otherTestTeam, Guid.NewGuid(), "-other", EMBC.ESS.Resources.Teams.TeamUserRoleOptionSet.Tier1); this.testContact = essContext.contacts.Where(c => c.firstname == this.testPrefix + "-first" && c.lastname == this.testPrefix + "-last").SingleOrDefault() ?? CreateContact(essContext); this.supplierA = essContext.era_suppliers.Where(c => c.era_name == testPrefix + "-supplier-A").SingleOrDefault() ?? CreateSupplier(essContext, "A", this.testTeam); this.supplierB = essContext.era_suppliers.Where(c => c.era_name == testPrefix + "-supplier-B").SingleOrDefault() ?? CreateSupplier(essContext, "B", this.testTeam); this.supplierC = essContext.era_suppliers.Where(c => c.era_name == testPrefix + "-supplier-C").SingleOrDefault() ?? CreateSupplier(essContext, "C", this.otherTestTeam); this.inactiveSupplier = essContext.era_suppliers.Where(c => c.era_name == testPrefix + "-supplier-inactive").SingleOrDefault() ?? CreateSupplier(essContext, "inactive", null); var evacuationfile = essContext.era_evacuationfiles .Expand(f => f.era_CurrentNeedsAssessmentid) .Expand(f => f.era_Registrant) .Where(f => f.era_name == testPrefix + "-digital").SingleOrDefault(); if (evacuationfile == null) { evacuationfile = CreateEvacuationFile(essContext, this.testContact, testPrefix + "-digital"); } else { essContext.LoadProperty(evacuationfile, nameof(era_evacuationfile.era_era_evacuationfile_era_householdmember_EvacuationFileid)); CreateEvacueeSupports(essContext, evacuationfile, this.testContact, this.tier4TeamMember, testPrefix); } var paperEvacuationfile = essContext.era_evacuationfiles .Expand(f => f.era_CurrentNeedsAssessmentid) .Expand(f => f.era_Registrant) .Where(f => f.era_name == testPrefix + "-paper").SingleOrDefault(); if (paperEvacuationfile == null) { paperEvacuationfile = CreateEvacuationFile(essContext, this.testContact, testPrefix + "-paper", testPrefix + "-paper"); CreateEvacueeSupports(essContext, paperEvacuationfile, this.testContact, this.tier4TeamMember, testPrefix); } else { essContext.LoadProperty(paperEvacuationfile, nameof(era_evacuationfile.era_era_evacuationfile_era_householdmember_EvacuationFileid)); } essContext.SaveChanges(); essContext.DeactivateObject(this.inactiveSupplier, 2); essContext.SaveChanges(); essContext.DetachAll(); this.testEvacuationfile = essContext.era_evacuationfiles .Expand(f => f.era_CurrentNeedsAssessmentid) .Expand(f => f.era_Registrant) .Where(f => f.era_evacuationfileid == evacuationfile.era_evacuationfileid).Single(); essContext.LoadProperty(this.testEvacuationfile, nameof(era_evacuationfile.era_era_evacuationfile_era_evacueesupport_ESSFileId)); essContext.LoadProperty(this.testEvacuationfile, nameof(era_evacuationfile.era_era_evacuationfile_era_householdmember_EvacuationFileid)); this.testPaperEvacuationFile = essContext.era_evacuationfiles .Expand(f => f.era_CurrentNeedsAssessmentid) .Expand(f => f.era_Registrant) .Where(f => f.era_evacuationfileid == paperEvacuationfile.era_evacuationfileid).Single(); essContext.LoadProperty(this.testPaperEvacuationFile, nameof(era_evacuationfile.era_era_evacuationfile_era_evacueesupport_ESSFileId)); essContext.LoadProperty(this.testPaperEvacuationFile, nameof(era_evacuationfile.era_era_evacuationfile_era_householdmember_EvacuationFileid)); essContext.DetachAll(); this.essContextFactory = essContextFactory; }