private era_supplier CreateSupplier(EssContext essContext, string identifier, era_essteam?assignedTeam) { var supplier = new era_supplier() { era_supplierid = Guid.NewGuid(), era_name = testPrefix + "-supplier-" + identifier, era_suppliername = testPrefix + "-supplier-name-" + identifier, era_gstnumber = "R-" + testPrefix + "-" + identifier, era_addressline1 = testPrefix + "-line1", era_addressline2 = testPrefix + "-line2", era_postalcode = "v2v 2v2", }; essContext.AddToera_suppliers(supplier); essContext.SetLink(supplier, nameof(era_supplier.era_RelatedCity), jurisdictions.Skip(Random.Shared.Next(jurisdictions.Length - 1)).First()); essContext.SetLink(supplier, nameof(era_supplier.era_RelatedCountry), canada); essContext.SetLink(supplier, nameof(era_supplier.era_RelatedProvinceState), bc); if (assignedTeam != null) { AssignSupplierToTeam(essContext, supplier, testTeam); } return(supplier); }
private void AssignSupplierToTeam(EssContext essContext, era_supplier supplier, era_essteam team) { var ts = new era_essteamsupplier() { era_essteamsupplierid = Guid.NewGuid(), era_active = true, era_isprimarysupplier = true }; essContext.AddToera_essteamsuppliers(ts); essContext.AddLink(supplier, nameof(era_supplier.era_era_supplier_era_essteamsupplier_SupplierId), ts); essContext.SetLink(ts, nameof(era_essteamsupplier.era_SupplierId), supplier); essContext.AddLink(team, nameof(era_essteam.era_essteam_essteamsupplier_ESSTeamID), ts); essContext.SetLink(ts, nameof(era_essteamsupplier.era_ESSTeamID), team); }
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; }