public void TestCreateAndFetchDogOwnerAndDogs() { System.Guid dogOwnerId = System.Guid.NewGuid(); System.Guid dog1Id = System.Guid.NewGuid(); System.Guid dog2Id = System.Guid.NewGuid(); System.Guid profileId = System.Guid.NewGuid(); System.Guid number1Id = System.Guid.NewGuid(); System.Guid number2Id = System.Guid.NewGuid(); IContext context = ContextFactory.GetContext(this, "DogOwner"); DogOwner dogOwner = (DogOwner)context.CreateObject(dogOwnerId, typeof(DogOwner)); dogOwner.Name = "Mats Helander"; Profile profile = (Profile)context.CreateObject(profileId, typeof(Profile)); profile.Email = "*****@*****.**"; dogOwner.Profile = profile; PhoneNumber number1 = (PhoneNumber)context.CreateObject(number1Id, typeof(PhoneNumber)); number1.Number = "555-1234"; profile.PhoneNumbers.Add(number1); PhoneNumber number2 = (PhoneNumber)context.CreateObject(number2Id, typeof(PhoneNumber)); number2.Number = "555-4321"; profile.PhoneNumbers.Add(number2); Dog dog1 = (Dog)context.CreateObject(dog1Id, typeof(Dog)); dog1.Name = "Karo"; dogOwner.Dogs.Add(dog1); Dog dog2 = (Dog)context.CreateObject(dog2Id, typeof(Dog)); dog2.Name = "Fido"; dogOwner.Dogs.Add(dog2); Assert.IsTrue(dog1.DogOwner == dogOwner); context.PersistAll(); context.Dispose(); IContext context2 = ContextFactory.GetContext(this, "DogOwner"); DogOwner dogOwner2 = (DogOwner)context2.GetObject(dogOwnerId, typeof(DogOwner)); Dog dog12 = (Dog)context2.GetObject(dog1Id, typeof(Dog)); Dog dog22 = (Dog)context2.GetObject(dog2Id, typeof(Dog)); Assert.IsTrue(dog12.DogOwner == dogOwner2); Assert.IsTrue(dog22.DogOwner == dogOwner2); Assert.IsTrue(dogOwner2.Dogs.Contains(dog12)); Assert.IsTrue(dogOwner2.Dogs.Contains(dog22)); context2.Dispose(); }
public void TestCreateAndFetchDogOwnerAndDogsWithLazyDogOwner() { System.Guid dogOwnerId = System.Guid.NewGuid(); System.Guid dog1Id = System.Guid.NewGuid(); System.Guid dog2Id = System.Guid.NewGuid(); IContext context = ContextFactory.GetContext(this, "DogOwner"); DogOwner dogOwner = (DogOwner)context.CreateObject(dogOwnerId, typeof(DogOwner)); dogOwner.Name = "Mats Helander"; Dog dog1 = (Dog)context.CreateObject(dog1Id, typeof(Dog)); dog1.Name = "Karo"; dogOwner.Dogs.Add(dog1); Dog dog2 = (Dog)context.CreateObject(dog2Id, typeof(Dog)); dog2.Name = "Fido"; dogOwner.Dogs.Add(dog2); context.PersistAll(); context.Dispose(); IContext context2 = ContextFactory.GetContext(this, "DogOwner"); Dog dog12 = (Dog)context2.GetObject(dog1Id, typeof(Dog)); Dog dog22 = (Dog)context2.GetObject(dog2Id, typeof(Dog)); Assert.IsTrue(context2.GetPropertyStatus(dog12, "DogOwner") == PropertyStatus.Clean); Assert.IsTrue(context2.GetPropertyStatus(dog22, "DogOwner") == PropertyStatus.Clean); Assert.IsTrue(context2.GetPropertyStatus(dog12.DogOwner, "Id") == PropertyStatus.Clean); Assert.IsTrue(context2.GetPropertyStatus(dog22.DogOwner, "Id") == PropertyStatus.Clean); Assert.IsTrue(dog12.DogOwner.Id == dogOwnerId); Assert.IsTrue(dog22.DogOwner.Id == dogOwnerId); Assert.IsTrue(dog12.DogOwner.Name == "Mats Helander"); context2.Dispose(); }
public void TestCreateDogOwnerAndDogs() { IContext context = ContextFactory.GetContext(this, "DogOwner"); DogOwner dogOwner = (DogOwner)context.CreateObject(System.Guid.NewGuid(), typeof(DogOwner)); dogOwner.Name = "Mats Helander"; Dog dog1 = (Dog)context.CreateObject(System.Guid.NewGuid(), typeof(Dog)); dog1.Name = "Karo"; dogOwner.Dogs.Add(dog1); Dog dog2 = (Dog)context.CreateObject(System.Guid.NewGuid(), typeof(Dog)); dog2.Name = "Fido"; dogOwner.Dogs.Add(dog2); context.PersistAll(); context.Dispose(); }
public void TestCreateAndFetchAllDogOwnerAndDogs() { string dir = @"C:\Test\Xml\ODMappingTests.Dog"; if (Directory.Exists(dir)) { Directory.Delete(dir, true); } dir = @"C:\Test\Xml\ODMappingTests.DogOwner"; if (Directory.Exists(dir)) { Directory.Delete(dir, true); } dir = @"C:\Test\Xml\ODMappingTests.PhoneNumber"; if (Directory.Exists(dir)) { Directory.Delete(dir, true); } System.Guid dogOwnerId = System.Guid.NewGuid(); System.Guid dog1Id = System.Guid.NewGuid(); System.Guid dog2Id = System.Guid.NewGuid(); System.Guid profileId = System.Guid.NewGuid(); System.Guid number1Id = System.Guid.NewGuid(); System.Guid number2Id = System.Guid.NewGuid(); IContext context = ContextFactory.GetContext(this, "DogOwner"); DogOwner dogOwner = (DogOwner)context.CreateObject(dogOwnerId, typeof(DogOwner)); dogOwner.Name = "Mats Helander"; Profile profile = (Profile)context.CreateObject(profileId, typeof(Profile)); profile.Email = "*****@*****.**"; dogOwner.Profile = profile; PhoneNumber number1 = (PhoneNumber)context.CreateObject(number1Id, typeof(PhoneNumber)); number1.Number = "555-1234"; profile.PhoneNumbers.Add(number1); PhoneNumber number2 = (PhoneNumber)context.CreateObject(number2Id, typeof(PhoneNumber)); number2.Number = "555-4321"; profile.PhoneNumbers.Add(number2); Dog dog1 = (Dog)context.CreateObject(dog1Id, typeof(Dog)); dog1.Name = "Karo"; dogOwner.Dogs.Add(dog1); Dog dog2 = (Dog)context.CreateObject(dog2Id, typeof(Dog)); dog2.Name = "Fido"; dogOwner.Dogs.Add(dog2); Assert.IsTrue(dog1.DogOwner == dogOwner); context.PersistAll(); context.Dispose(); IContext context2 = ContextFactory.GetContext(this, "DogOwner"); IList dogOwners = context2.GetObjects(typeof(DogOwner)); IList dogs = context2.GetObjects(typeof(Dog)); Assert.AreEqual(1, dogOwners.Count); Assert.AreEqual(2, dogs.Count); DogOwner dogOwner2 = (DogOwner)dogOwners[0]; Dog dog12 = (Dog)dogs[0]; Dog dog22 = (Dog)dogs[1]; Assert.IsTrue(dog12.DogOwner == dogOwner2); Assert.IsTrue(dog22.DogOwner == dogOwner2); Assert.IsTrue(dogOwner2.Dogs.Contains(dog12)); Assert.IsTrue(dogOwner2.Dogs.Contains(dog22)); context2.Dispose(); }