Ejemplo n.º 1
0
        public void TestDaoRepoHbGen()
        {
            Database      db   = DataProvider.Current.GetAppDatabaseFor(ProcessApplicationNameProvider.Current, this);
            DaoRepository repo = new DaoRepository(db)
            {
                BaseNamespace = typeof(ShellDescriptor).Namespace, RequireCuid = true
            };

            repo.AddType <ShellDescriptor>();
            ShellDescriptor d = new ShellDescriptor()
            {
                AssemblyName = "Ass", NameSpace = "Ns"
            };

            d = repo.Save(d);

            ShellDescriptor queried = repo.Query <ShellDescriptor>(c => c.Id == d.Id).FirstOrDefault();

            Expect.IsNotNull(queried);

            Expect.AreEqual(d, queried);

            ShellDescriptor retrieved = repo.Retrieve <ShellDescriptor>(d.Id);

            Expect.IsNotNull(retrieved);

            Expect.AreEqual(d, retrieved);

            Pass("yay");
        }
Ejemplo n.º 2
0
        public void CanSaveAndRetrieveAllCurrentAppDomainDescriptorsTest()
        {
            DaoRepository daoRepo = GetAssemblyManagementRepository(GetConsoleLogger());

            AssemblyDescriptor[] descriptors = AssemblyDescriptor.GetCurrentAppDomainDescriptors().ToArray();
            foreach (AssemblyDescriptor descriptor in descriptors)
            {
                OutLine("Before save");
                OutputInfo(descriptor);

                AssemblyDescriptor saved = daoRepo.Save(descriptor);
                OutLine("Original after save", ConsoleColor.Yellow);
                OutputInfo(descriptor);

                OutLine("Result after save", ConsoleColor.DarkYellow);
                OutputInfo(saved);

                Expect.AreEqual(descriptor.AssemblyFullName, saved.AssemblyFullName, "AssemlbyFullName didn't match");
                Expect.AreEqual(descriptor.AssemblyReferenceDescriptors?.Count, saved.AssemblyReferenceDescriptors?.Count, "AssemblyReferenceDescriptors count didn't match");

                AssemblyDescriptor retrieved = daoRepo.Retrieve <AssemblyDescriptor>(saved.Uuid);
                OutLine("Retrieved after save", ConsoleColor.DarkGreen);
                OutputInfo(saved);

                Expect.AreEqual(descriptor.AssemblyFullName, retrieved.AssemblyFullName, "AssemlbyFullName didn't match");
                Expect.AreEqual(descriptor.AssemblyReferenceDescriptors?.Count, retrieved.AssemblyReferenceDescriptors?.Count, "AssemblyReferenceDescriptors count didn't match");
            }
        }
Ejemplo n.º 3
0
        public void SavingParentXrefShouldSetChildXref()
        {
            DaoRepository repo = GetTestDaoRepository();

            repo.EnsureDaoAssemblyAndSchema();
            House house = new House {
                Name = "TestHouse", Parents = new List <Parent> {
                    new Parent {
                        Name = "TestParent"
                    }
                }
            };

            repo.Save(house);

            House  retrieved = repo.Retrieve <House>(house.Id);
            Parent parent    = repo.Retrieve <Parent>(retrieved.Parents[0].Id);

            Expect.AreEqual(1, parent.Houses.Length);
        }
Ejemplo n.º 4
0
        public void CanSaveAndRetrieveAssemblyDescriptorTest()
        {
            DaoRepository      daoRepo    = GetAssemblyManagementRepository(GetConsoleLogger());
            AssemblyDescriptor descriptor = new AssemblyDescriptor(Assembly.GetExecutingAssembly());

            Expect.IsTrue(descriptor.AssemblyReferenceDescriptors.Count > 0, "No references found");
            AssemblyDescriptor saved = daoRepo.Save(descriptor);

            Expect.AreEqual(descriptor.AssemblyReferenceDescriptors?.Count, saved.AssemblyReferenceDescriptors?.Count, "Saved references didn't match");
            AssemblyDescriptor retrieved = daoRepo.Retrieve <AssemblyDescriptor>(descriptor.Uuid);

            Expect.AreEqual(descriptor.AssemblyReferenceDescriptors?.Count, saved.AssemblyReferenceDescriptors?.Count, "Retrieved references didn't match");
        }
Ejemplo n.º 5
0
        public void RepositoryDeleteShouldDelete()
        {
            DaoRepository repo     = GetTestDaoRepository();
            TestContainer toDelete = new TestContainer();
            string        testName = "Test Name".RandomLetters(5);

            toDelete.Name     = testName;
            toDelete.BirthDay = DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0));
            toDelete          = repo.Create(toDelete);
            Expect.IsTrue(repo.Delete <TestContainer>(toDelete));
            TestContainer check = repo.Retrieve <TestContainer>(toDelete.Id);

            Expect.IsNull(check);
        }
Ejemplo n.º 6
0
        public void RepositoryUpdateShouldSetNewPropertyValues()
        {
            DaoRepository repo     = GetTestDaoRepository();
            TestContainer toCreate = new TestContainer();
            string        testName = "Test Name".RandomLetters(5);

            toCreate.Name     = testName;
            toCreate.BirthDay = DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0));
            toCreate          = repo.Create(toCreate);
            TestContainer toUpdate = repo.Retrieve <TestContainer>(toCreate.Id);
            string        newName  = "New Name".RandomLetters(8);

            toUpdate.Name = newName;
            DateTime newBirthDay = DateTime.Now.Subtract(new TimeSpan(14, 0, 0, 0));

            toUpdate.BirthDay = newBirthDay;
            toUpdate          = repo.Update(toUpdate);
            TestContainer check = repo.Retrieve <TestContainer>(toCreate.Id);

            Expect.AreEqual(newName, check.Name);
            Expect.AreEqual(newBirthDay.Trim(), check.BirthDay.Trim());
            Expect.AreEqual(toCreate.Id, check.Id);
        }
Ejemplo n.º 7
0
        public void ParentSaveShouldSaveChildren()
        {
            DaoRepository repo = GetTestDaoRepository();

            repo.EnsureDaoAssemblyAndSchema();
            Parent parent = new Parent();

            parent.Name = "Parent Name";
            Son sonOne = new Son();
            Son sonTwo = new Son();

            parent.Sons = new List <Son>(new Son[] { sonOne, sonTwo });

            parent = repo.Save(parent);
            Parent retrieved = repo.Retrieve <Parent>(parent.Id);

            Expect.AreEqual(2, retrieved.Sons.Count);
        }
Ejemplo n.º 8
0
        public void RepositoryRetrieveByIdTest()
        {
            DaoRepository repo     = GetTestDaoRepository();
            TestContainer toCreate = new TestContainer();

            Expect.AreEqual(0, toCreate.Id);
            string testName = "Test Name".RandomLetters(5);

            toCreate.Name     = testName;
            toCreate.BirthDay = DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0));
            toCreate          = repo.Create(toCreate);
            TestContainer retrieved = repo.Retrieve <TestContainer>(toCreate.Id);

            Expect.IsNotNull(retrieved);
            Expect.AreEqual(toCreate.Name, retrieved.Name);
            Expect.AreEqual(toCreate.BirthDay.Trim(), retrieved.BirthDay.Trim());
            Expect.AreEqual(toCreate.Id, retrieved.Id);
        }
Ejemplo n.º 9
0
        public void RetrieveShouldSetParentOnChildren()
        {
            DaoRepository repo = GetTestDaoRepository();

            repo.EnsureDaoAssemblyAndSchema();
            Parent parent = new Parent();

            parent.Name = "Test parent";
            Son one = new Son();

            one.Name    = "Son";
            parent.Sons = new List <Son>(new Son[] { one });
            parent      = repo.Save(parent);
            Son checkSon = repo.Retrieve <Son>(parent.Sons[0].Id);

            Expect.AreEqual(one.Name, checkSon.Name);
            Expect.AreEqual(parent.Id, checkSon.Parent.Id);
            Expect.AreEqual(parent.Name, checkSon.Parent.Name);
        }
Ejemplo n.º 10
0
        public void SavingParentShouldSaveChildLists()
        {
            DaoRepository repo = GetTestDaoRepository();

            repo.EnsureDaoAssemblyAndSchema();
            House house = new House {
                Name = "TestHouse", Parents = new List <Parent> {
                    new Parent {
                        Name = "TestParent"
                    }
                }
            };

            repo.Save(house);

            House retrieved = repo.Retrieve <House>(house.Id);

            Expect.AreEqual(1, retrieved.Parents.Count);
        }
Ejemplo n.º 11
0
        public override object Retrieve(Type objectType, string uuid)
        {
            object dao = DaoRepository.Retrieve(objectType, uuid);

            return(GetLatest(dao));
        }