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 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"); } }