public void ObjectRepositoryMetaPropertyVersionTest()
        {
            ObjectRepository repo = GetTestObjectRepository(nameof(ObjectRepositoryMetaPropertyVersionTest));

            repo.AddType(typeof(Parent));

            Parent p = new Parent {
                Name = "Test Parent"
            };
            Parent saved = repo.Save(p);
            Meta   meta  = repo.MetaProvider.GetMeta(saved);

            meta.Property("Name", "Monkey");
            meta.Property("Name", "Orangutan");
            meta.Property("Name", "Gorilla");

            MetaProperty nameProp = meta.Property("Name");

            OutLineFormat("Version Count: {0}", nameProp.Versions.Length);
            foreach (MetaPropertyVersionInfo version in nameProp.GetVersionInfos())
            {
                OutLineFormat("Hash: {0}", ConsoleColor.Cyan, version.Hash);
                OutLineFormat("LastWrite: {0}, {1}", ConsoleColor.DarkCyan, version.LastWrite.ToShortDateString(), version.LastWrite.ToLongTimeString());
                OutLineFormat("Name: {0}", ConsoleColor.Cyan, version.Name);
                OutLineFormat("Version: {0}", ConsoleColor.Cyan, version.Version);
                OutLineFormat("Value: {0}", ConsoleColor.Cyan, version.Value);
            }
        }
        private static ObjectRepository GetTestMongoObjectRepository(string root = null)
        {
            ObjectRepository repo = string.IsNullOrEmpty(root) ? new ObjectRepository() : new ObjectRepository(root);

            repo.AddType(typeof(TestContainer));
            repo.Subscribe(new ConsoleLogger());
            repo.ObjectReaderWriter = new MongoObjectReaderWriter();
            return(repo);
        }
        internal static ObjectRepository GetTestObjectRepository(string root = null)
        {
            ConsoleLogger logger = new ConsoleLogger();

            logger.UseColors  = true;
            logger.AddDetails = false;
            logger.StartLoggingThread();

            ObjectRepository repo = string.IsNullOrEmpty(root) ? new ObjectRepository() : new ObjectRepository(root);

            repo.AddType(typeof(TestContainer));
            repo.BlockOnChildWrites = true;
            repo.Subscribe(logger);
            return(repo);
        }
        public void ObjectRepositoryCreateShouldSetId()
        {
            ObjectRepository repo = GetTestObjectRepository();

            repo.AddType(typeof(TestContainer));
            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);
            Expect.IsGreaterThan(toCreate.Id, 0);
            OutLineFormat("{0} passed", ConsoleColor.Green, repo.GetType().Name);
        }
        public void ObjectRepositoryMetaProviderTest()
        {
            ObjectRepository repo = GetTestObjectRepository();

            repo.AddType(typeof(Parent));

            Parent p = new Parent {
                Name = "Test Parent"
            };
            Parent saved = repo.Save(p);
            Meta   meta  = repo.MetaProvider.GetMeta(saved);

            Expect.IsFalse(string.IsNullOrEmpty(p.Uuid));
            Expect.AreEqual(meta.Uuid, p.Uuid);
            Expect.AreEqual(meta.Id, p.Id);
        }
        public void ObjectRepositoryMetaPropertyTest()
        {
            ObjectRepository repo = GetTestObjectRepository();

            repo.AddType(typeof(Parent));

            Parent p = new Parent {
                Name = "Test Parent"
            };
            Parent saved = repo.Save(p);
            Meta   meta  = repo.MetaProvider.GetMeta(saved);

            meta.Property("Name", "Monkey");
            Parent check = repo.Query <Parent>(q => q.Uuid.Equals(saved.Uuid)).FirstOrDefault();

            Expect.IsNotNull(check);
            Expect.AreEqual("Monkey", check.Name);
        }