private Owner AddDogAndOwner(bool add = true) { var owner = new Owner { TopDog = new Dog { Name = DogName }, Name = OwnerName }; if (add) { _realm.Write(() => { _realm.Add(owner); }); } return owner; }
public void SearchComparingObjects() { var rex = new Dog { Name = "Rex" }; var peter = new Owner { Name = "Peter", TopDog = rex }; var george = new Owner { Name = "George", TopDog = rex }; var sharo = new Dog { Name = "Sharo" }; var ivan = new Owner { Name = "Ivan", TopDog = sharo }; _realm.Write(() => { _realm.Add(peter); _realm.Add(george); _realm.Add(ivan); }); var rexOwners = _realm.All<Owner>().Where(o => o.TopDog == rex); Assert.That(rexOwners.Count(), Is.EqualTo(2)); var sharoOwners = _realm.All<Owner>().Where(o => o.TopDog != rex); Assert.That(sharoOwners.Count(), Is.EqualTo(1)); Assert.That(sharoOwners.Single().Name, Is.EqualTo("Ivan")); }