Beispiel #1
0
        public void RepoQueryTest()
        {
            string nameOne = 32.RandomLetters();

            foreach (Repository repo in GetTestRepositories())
            {
                KeyHashRepoTestData one = new KeyHashRepoTestData {
                    Name = nameOne
                };
                one.Save <KeyHashRepoTestData>(repo);

                List <KeyHashRepoTestData> retrieved = repo.Query <KeyHashRepoTestData>(new { Name = nameOne }).ToList();
                retrieved = repo.Query <KeyHashRepoTestData>(d => d.Name.Equals(nameOne)).ToList();
                Expect.AreEqual(1, retrieved.Count);
                retrieved = repo.Query(typeof(KeyHashRepoTestData), o => o.Property("Name").Equals(nameOne)).CopyAs <KeyHashRepoTestData>().ToList();
                Expect.AreEqual(1, retrieved.Count);
                retrieved = repo.Query <KeyHashRepoTestData>(new Dictionary <string, object> {
                    { "Name", nameOne }
                }).ToList();
                Expect.AreEqual(1, retrieved.Count);
                retrieved = repo.Query(typeof(KeyHashRepoTestData), new Dictionary <string, object> {
                    { "Name", nameOne }
                }).CopyAs <KeyHashRepoTestData>().ToList();
                Expect.AreEqual(1, retrieved.Count);
                retrieved = repo.Query(typeof(KeyHashRepoTestData), new { Name = nameOne }).CopyAs <KeyHashRepoTestData>().ToList();
                Expect.AreEqual(1, retrieved.Count);
                retrieved = repo.Query("Name", nameOne).CopyAs <KeyHashRepoTestData>().ToList();
                Expect.AreEqual(1, retrieved.Count);
                retrieved = repo.Query(new { Type = typeof(KeyHashRepoTestData), Name = nameOne }).CopyAs <KeyHashRepoTestData>().ToList();
                Expect.AreEqual(1, retrieved.Count);

                Pass(repo.GetType().Name);
            }
        }
Beispiel #2
0
        public void GetHashReturnsSameValueForDifferentInstances()
        {
            string name             = 16.RandomLetters();
            string otherProp        = 32.RandomLetters();
            KeyHashRepoTestData one = new KeyHashRepoTestData {
                Name = name, SomeOtherUniqueProperty = otherProp
            };
            KeyHashRepoTestData two = new KeyHashRepoTestData {
                Name = name, SomeOtherUniqueProperty = otherProp
            };
            KeyHashRepoTestData three = new KeyHashRepoTestData {
                Name = name, SomeOtherUniqueProperty = "different"
            };

            Expect.IsFalse(one == two);
            Expect.AreEqual(one.GetHashCode(), two.GetHashCode());
            Expect.AreEqual(one.GetLongKeyHash(), two.GetLongKeyHash());

            Expect.IsFalse(one.GetHashCode().Equals(three.GetHashCode()));
            Expect.IsFalse(two.GetHashCode().Equals(three.GetHashCode()));

            OutLine(one.GetLongKeyHash().ToString());
        }
Beispiel #3
0
        public void SavingKeyHashRepoDataShouldntDuplicate()
        {
            ConsoleLogger logger = new ConsoleLogger {
                AddDetails = false, UseColors = true
            };

            logger.StartLoggingThread();
            string        schemaName = "TheSchemaName_".RandomLetters(5);
            DaoRepository repo       = new DaoRepository(new SQLiteDatabase(".", nameof(SavingKeyHashRepoDataShouldntDuplicate)), logger, schemaName);

            repo.WarningsAsErrors = false;
            repo.AddType(typeof(KeyHashRepoTestData));
            CachingRepository cachingRepo = new CachingRepository(repo, logger);

            string nameOne          = 32.RandomLetters();
            string valueOne         = 16.RandomLetters();
            KeyHashRepoTestData one = new KeyHashRepoTestData {
                Name = nameOne, SomeOtherUniqueProperty = valueOne
            };
            KeyHashRepoTestData two = new KeyHashRepoTestData {
                Name = nameOne, SomeOtherUniqueProperty = valueOne
            };

            Expect.AreEqual(one, two);

            one.Save <KeyHashRepoTestData>(cachingRepo);
            var queryParams = new { Name = nameOne };

            cachingRepo.Cache <KeyHashRepoTestData>(queryParams);
            List <KeyHashRepoTestData> retrieved = cachingRepo.Query <KeyHashRepoTestData>(queryParams).ToList();

            Expect.AreEqual(1, retrieved.Count);
            two.Save <KeyHashRepoTestData>(cachingRepo);
            retrieved = cachingRepo.Query <KeyHashRepoTestData>(queryParams).ToList();
            Expect.AreEqual(1, retrieved.Count);
        }