public void Test_GetMirrorPropertyNameReverse_Multiple_Implicit_Sync() { TestUser user = new TestUser(); string mirrorPropertyName = EntitiesUtilities.GetMirrorPropertyNameReverse(user, "Roles", typeof(TestRole)); Assert.AreEqual("Users", mirrorPropertyName, "The mirror property name wasn't determined correctly."); }
public void Test_GetMirrorPropertyNameReverse_Multiple_Implicit_Async() { MockEntity entity = new MockEntity(); MockPublicEntity publicEntity = new MockPublicEntity(); string mirrorPropertyName = EntitiesUtilities.GetMirrorPropertyNameReverse(publicEntity, "", typeof(MockEntity)); Assert.AreEqual("PublicEntities", mirrorPropertyName, "The mirror property name wasn't determined correctly."); }
public bool Match(IEntity entity) { bool doesMatch = true; //using (LogGroup logGroup2 = LogGroup.Start("Querying entity.", NLog.LogLevel.Debug)) //{ //LogWriter.Debug("Checking type " + e.GetType().ToString()); //LogWriter.Debug("Entity ID: " + e.ID); try { string mirrorPropertyName = String.Empty; if (PropertyName != String.Empty) { mirrorPropertyName = EntitiesUtilities.GetMirrorPropertyName(entity, PropertyName); } else { mirrorPropertyName = EntitiesUtilities.GetMirrorPropertyNameReverse(entity, PropertyName, ReferencedEntityType); } bool foundReference = false; foreach (Guid id in ReferencedEntityIDs) { if (DataAccess.Data.Referencer.MatchReference(entity.GetType(), entity.ID, PropertyName, ReferencedEntityType, id, mirrorPropertyName)) { foundReference = true; } } // If references are provided then it matches if found if (ReferencedEntityIDs.Length > 0) { doesMatch = foundReference; } // Otherwise the calling code is trying to get entities where NO reference exists, therefore it matches when no reference is found else { doesMatch = !foundReference; } } catch (Exception ex) { LogWriter.Error(ex); throw ex; } //LogWriter.Debug("Matches: " + matches); //} return(doesMatch); }
public bool Match(IEntity entity) { bool doesMatch = true; //using (LogGroup logGroup = LogGroup.StartDebug("Querying entity.")) //{ // Catch and log errors otherwise they won't get caught as this is executed within db4o try { // LogWriter.Debug("Checking type " + entity.GetType().ToString()); // LogWriter.Debug("Entity ID: " + entity.ID); // LogWriter.Debug("Property name: " + PropertyName); string mirrorPropertyName = MirrorPropertyName; // If no mirror property name was specified by the calling code then detect it if (mirrorPropertyName == null || mirrorPropertyName == String.Empty) { if (PropertyName != String.Empty) { mirrorPropertyName = EntitiesUtilities.GetMirrorPropertyName(entity, PropertyName); } else { mirrorPropertyName = EntitiesUtilities.GetMirrorPropertyNameReverse(entity, PropertyName, ReferencedEntityType); } } // LogWriter.Debug("Mirror property name: " + mirrorPropertyName); bool referenceFound = false; if (ReferencedEntityID != Guid.Empty) { referenceFound = DataAccess.Data.Referencer.MatchReference(entity.GetType(), entity.ID, PropertyName, ReferencedEntityType, ReferencedEntityID, mirrorPropertyName); } else { referenceFound = DataAccess.Data.Referencer.MatchReference(entity.GetType(), entity.ID, PropertyName, ReferencedEntityType, mirrorPropertyName); } // LogWriter.Debug("Reference found: " + referenceFound); // If a reference entity ID is specified then it matches if a reference is found if (ReferencedEntityID != Guid.Empty) { // LogWriter.Debug("Referenced entity ID is specified. Will match if a reference is found."); doesMatch = referenceFound; } // Otherwise it matches if NO references are found, because the calling code wants to match an entity with no found references matching the one specified else { // LogWriter.Debug("Referenced entity ID is empty. Will match if no reference is found."); doesMatch = !referenceFound; } } catch (Exception ex) { // LogWriter.Error(ex); throw ex; } // LogWriter.Debug("Matches: " + doesMatch); //} return(doesMatch); }