public void Person_Get_External() { var externalId = "50"; var id = 1; var person = DataFactory.CreatePerson("John", "Smith", "middle"); using (var context = new RSMDB.RSMDataModelDataContext()) { context.Persons.InsertOnSubmit(person); context.SubmitChanges(); id = person.PersonID; var keys = DataFactory.CreateExternalApplicationKey(EntityType.Person, externalId, S2In.Id, id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); } var criteria = new Person { EntityType = EntityType.Person, ExternalSystemId = S2In.Id, ExternalId = externalId }; var result = criteria.Get(); Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); Assert.IsNotNull(result.Entity, "Missing entity"); Assert.IsNotNull(result.Entity.ExternalSystem, "Missing ExternalSystem entity"); Assert.IsTrue(result.Entity.EntityType == EntityType.Person, "EntityType mismatch"); Assert.IsTrue((result.Entity as ExternalEntity).InternalId == id, "Incorrect id for entity"); }
public Person CreateTestPerson(RSMDB.RSMDataModelDataContext context, string firstName, string middleName, string lastName, string employeeId, ExternalSystem system, Bitmap imageFile = null) { var key = context.ExternalApplicationKeys.FirstOrDefault(x => x.EntityType == "Person" && x.ExternalId == employeeId); if (key != null) { DeleteTestPerson(context, employeeId, system); } var person = StageFactory.CreatePerson(firstName, lastName, middleName); if (imageFile != null) { var ms = new MemoryStream(); imageFile.Save(ms, ImageFormat.Jpeg); person.Image = ms.ToArray(); } context.Persons.InsertOnSubmit(person); context.SubmitChanges(); var modelPerson = person.ToModel(); var keys = StageFactory.CreateExternalApplicationKey(EntityType.Person, employeeId, system.Id, person.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); keys.ToModel(modelPerson); return(modelPerson); }
public void AccessLog_Get_External() { var externalId = "Access50"; var id = 1; var locationId = 1; using (var context = new RSMDB.RSMDataModelDataContext()) { var person = DataFactory.CreatePerson("first", "last", "middle"); context.Persons.InsertOnSubmit(person); context.SubmitChanges(); var keys = DataFactory.CreateExternalApplicationKey(EntityType.Person, externalId, S2In.Id, person.PersonID); context.ExternalApplicationKeys.InsertOnSubmit(keys); var location = DataFactory.CreateLocation("Location1"); context.Locations.InsertOnSubmit(location); context.SubmitChanges(); locationId = location.LocationID; var portal = DataFactory.CreatePortal("Portal1", locationId); context.Portals.InsertOnSubmit(portal); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.Portal, externalId, S2In.Id, portal.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); var reader = DataFactory.CreateReader("Reader50", portal.Id); context.Readers.InsertOnSubmit(reader); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.Reader, externalId, S2In.Id, reader.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); var access = DataFactory.CreateAccessHistory("Access50", person.PersonID, portal.Id, reader.Id, 30); context.AccessHistories.InsertOnSubmit(access); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.AccessLog, externalId, S2In.Id, access.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); id = access.Id; } var criteria = new AccessLog { EntityType = EntityType.AccessLog, ExternalSystemId = S2In.Id, ExternalId = externalId }; var result = criteria.Get(); Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); Assert.IsNotNull(result.Entity, "Missing entity"); Assert.IsNotNull(result.Entity.ExternalSystem, "Missing ExternalSystem entity"); Assert.IsTrue(result.Entity.EntityType == EntityType.AccessLog, "EntityType mismatch"); Assert.IsTrue((result.Entity as ExternalEntity).InternalId == id, "Incorrect id for entity"); }
public void LubrizolEmployeeImport_Execute() { var taskName = "LubrizolImportAPIStub"; RSMModel.Person modelPerson; using (var context = new RSMDB.RSMDataModelDataContext()) { //Load settings. //Includes a field level filter on LoadLubrizolImportTestData(context, taskName); //Create an existing person that will be updated var person = StageFactory.CreatePerson("OrigFirst2", "OrigLast", "OrigMid"); context.Persons.InsertOnSubmit(person); context.SubmitChanges(); modelPerson = person.ToModel(); var keys = StageFactory.CreateExternalApplicationKey(EntityType.Person, "2", S2In.Id, person.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); keys.ToModel(modelPerson); } Task task = null; Result <string> result = Result <string> .Success(); try { task = Task.Create(taskName, new ServiceProfile()); var import = task as RSM.Integration.S2.Import.People; result = import.Execute(null); } catch (Exception e) { Assert.Fail("Test exception! {0}", e.ToString()); } Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); using (var context = new RSMDB.RSMDataModelDataContext()) { var newPerson = context.Persons.FirstOrDefault(x => x.PersonID == modelPerson.InternalId); Assert.IsTrue(newPerson.MiddleName == modelPerson.MiddleName, "Middle name updated but not in field list to update."); Assert.IsTrue(newPerson.FirstName != modelPerson.FirstName, "First name should have been updated."); Assert.IsTrue(newPerson.Image != modelPerson.Image, "Image should have been updated."); var newKeys = context.ExternalApplicationKeys.FirstOrDefault(x => x.ExternalId == modelPerson.ExternalId && x.InternalId == modelPerson.InternalId && x.SystemId == modelPerson.ExternalSystemId && x.EntityType == Enum.GetName(typeof(EntityType), EntityType.Person)); Assert.IsTrue(newKeys.ExternalEntityLastUpdated != null, "ExternalEntityLastUpdated should have been updated."); Assert.IsTrue(context.Persons.FirstOrDefault(x => x.UDF4 == null || x.UDF4.Length == 0) == null, "There should be no records with an empty UDF4 field due to field filter."); } }
public Person CreateTestPerson(RSMDB.RSMDataModelDataContext context, string firstName, string middleName, string lastName, string employeeId, ExternalSystem system) { var person = StageFactory.CreatePerson(firstName, lastName, middleName); context.Persons.InsertOnSubmit(person); context.SubmitChanges(); var modelPerson = person.ToModel(); var keys = StageFactory.CreateExternalApplicationKey(EntityType.Person, employeeId, system.Id, person.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); keys.ToModel(modelPerson); return(modelPerson); }
public void AccessLog_AddBadFilter() { var externalId = "Access50"; var id = 1; var locationId = 1; var criteria = new AccessLog { EntityType = EntityType.AccessLog, ExternalSystemId = S2In.Id, ExternalId = externalId }; using (var context = new RSMDB.RSMDataModelDataContext()) { var person = DataFactory.CreatePerson("first", "last", "middle", null, false, false, null, null, false, null, null, "Test", null, new Dictionary <int, string>() { { 4, "S & B" } }); context.Persons.InsertOnSubmit(person); context.SubmitChanges(); var keys = DataFactory.CreateExternalApplicationKey(EntityType.Person, externalId, S2In.Id, person.PersonID); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); var location = DataFactory.CreateLocation("Location1"); context.Locations.InsertOnSubmit(location); context.SubmitChanges(); locationId = location.LocationID; context.SubmitChanges(); var portal = DataFactory.CreatePortal("Portal1", locationId); context.Portals.InsertOnSubmit(portal); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.Portal, externalId, S2In.Id, portal.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); var reader = DataFactory.CreateReader("Reader50", portal.Id); context.Readers.InsertOnSubmit(reader); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.Reader, externalId, S2In.Id, reader.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); criteria.PersonId = person.PersonID; criteria.PortalId = portal.Id; criteria.ReaderId = reader.Id; criteria.AccessType = (int)AccessType.Valid; criteria.Accessed = DateTime.Now.Subtract(TimeSpan.FromMinutes(10)); } var result = criteria.Add(); result.Entity.Person.ExternalId = externalId; result.Entity.Reader.ExternalId = externalId; result.Entity.Portal.ExternalId = externalId; var filterTest = new Integration.S2.Import.AccessHistory(); // filterTest.Configuration = filterTest.Load(); Assert.IsFalse(filterTest.Filter(result.Entity), "Filter did not remove!"); }
public void AccessLog_Add() { var externalId = "Access50"; var id = 1; var locationId = 1; var criteria = new AccessLog { EntityType = EntityType.AccessLog, ExternalSystemId = S2In.Id, ExternalId = externalId }; using (var context = new RSMDB.RSMDataModelDataContext()) { var person = DataFactory.CreatePerson("first", "last", "middle"); context.Persons.InsertOnSubmit(person); context.SubmitChanges(); var keys = DataFactory.CreateExternalApplicationKey(EntityType.Person, externalId, S2In.Id, person.PersonID); context.ExternalApplicationKeys.InsertOnSubmit(keys); var location = DataFactory.CreateLocation("Location1"); context.Locations.InsertOnSubmit(location); context.SubmitChanges(); locationId = location.LocationID; var portal = DataFactory.CreatePortal("Portal1", locationId); context.Portals.InsertOnSubmit(portal); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.Portal, externalId, S2In.Id, portal.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); var reader = DataFactory.CreateReader("Reader50", portal.Id); context.Readers.InsertOnSubmit(reader); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.Reader, externalId, S2In.Id, reader.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); criteria.PersonId = person.PersonID; criteria.PortalId = portal.Id; criteria.ReaderId = reader.Id; criteria.AccessType = 123; criteria.Accessed = DateTime.Now.Subtract(TimeSpan.FromMinutes(10)); } var result = criteria.Add(); Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); Assert.IsNotNull(result.Entity, "Missing entity"); Assert.IsNotNull(result.Entity.ExternalSystem, "Missing ExternalSystem entity"); Assert.IsTrue(result.Entity.EntityType == EntityType.AccessLog, "EntityType mismatch"); Assert.IsTrue(result.Entity.InternalId > 0, "Invalid id"); using (var context = new RSMDB.RSMDataModelDataContext()) { var keys = context.ExternalApplicationKeys.FirstOrDefault(x => x.ExternalId == externalId && x.SystemId == S2In.Id && x.EntityType == Enum.GetName(typeof(EntityType), EntityType.AccessLog)); Assert.IsNotNull(keys, "Keys not created"); var row = context.AccessHistories.FirstOrDefault(x => x.Id == keys.InternalId); Assert.IsNotNull(row, "AccessHistory not created"); } }