예제 #1
0
        public void LoadYamlTest()
        {
            YamlRepository repo = GetYamlRepo(nameof(LoadYamlTest));
            // save some stuff to daorepo
            string details  = 10.RandomLetters();
            string testName = 8.RandomLetters();
            Parent parent   = new Parent {
                Details = details, Name = testName
            };

            parent = repo.DaoRepository.Save(parent);
            FileInfo yamlFile     = repo.GetYamlFile(typeof(Parent), parent.Name);
            string   yamlFilePath = repo.YamlDataDirectory.GetYamlFilePath(typeof(Parent), parent.Name);

            Expect.IsFalse(File.Exists(yamlFilePath), $"file existed but shouldn't have: {yamlFilePath}");
            Expect.IsNull(yamlFile);
            FileInfo loadNamesFile = repo.GetLoadNamesFile(typeof(Parent));

            // write names to sync file
            repo.AddNameToLoad <Parent>(parent.Name);
            // Call LoadYaml
            repo.WriteYaml();
            // expect yaml files to exist
            yamlFile = repo.GetYamlFile(typeof(Parent), parent.Name);
            Expect.IsNotNull(yamlFile);
            Parent fromYaml = repo.ReadYaml <Parent>(parent.Name);

            Expect.AreEqual(fromYaml.Cuid, parent.Cuid);
            Expect.AreEqual(fromYaml.Name, parent.Name);
            Expect.AreEqual(fromYaml.Uuid, parent.Uuid);
        }
예제 #2
0
        public void CanAddNameToLoad()
        {
            YamlRepository repo          = GetYamlRepo(nameof(CanAddNameToLoad));
            FileInfo       loadNamesFile = repo.GetLoadNamesFile(typeof(Parent));

            if (File.Exists(loadNamesFile.FullName))
            {
                File.Delete(loadNamesFile.FullName);
            }
            Expect.IsFalse(File.Exists(loadNamesFile.FullName));
            HashSet <string> names = repo.AddNameToLoad <Parent>("monkey");

            Expect.IsTrue(File.Exists(loadNamesFile.FullName));
            names = repo.AddNameToLoad <Parent>("monkey");
            names = repo.AddNameToLoad <Parent>("banana");
            Expect.AreEqual(2, names.Count);
            List <string> fromFile = File.ReadAllLines(loadNamesFile.FullName).ToList();

            Expect.AreEqual(2, fromFile.Count);
            Expect.IsTrue(fromFile.Contains("monkey"));
            Expect.IsTrue(fromFile.Contains("banana"));
        }
예제 #3
0
        public void YamlSyncFromDbTest()
        {
            YamlRepository repo           = GetYamlRepo(nameof(LoadYamlTest));
            string         details        = 10.RandomLetters();
            string         updatedDetails = 15.RandomLetters();
            string         testName       = 8.RandomLetters();
            Parent         parent         = new Parent {
                Details = details, Name = testName
            };

            parent = repo.DaoRepository.Save(parent);
            repo.AddNameToLoad <Parent>(parent.Name);
            repo.WriteYaml();
            Parent fromFile = repo.ReadYaml <Parent>(parent.Name);

            Expect.AreEqual(fromFile.Details, parent.Details);
            parent.Details = updatedDetails;
            parent         = repo.DaoRepository.Save(parent);
            repo.Synchronize();
            fromFile = repo.ReadYaml <Parent>(parent.Name);
            Expect.AreEqual(fromFile.Details, updatedDetails);
        }