public void WritesPropsInParallel()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("cars", mem);

            Parallel.For(0, Environment.ProcessorCount << 4, i =>
                    {
                    hive.Comb("2CV").Props().Refined("looping", "louie");
                });

            Assert.Equal("louie", hive.Comb("2CV").Props().Value("looping"));
        }
        public void RemembersCombs()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("in-memory", mem);

            hive.Catalog().Add("123");
            hive.Catalog().Add("456");

            hive.Comb("123", false)
            .Cell("my-cell")
            .Update(new InputOf("larva"));

            Assert.Equal(
                "larva",
                new TextOf(
                    new InputOf(
                        hive.Comb("123", false)
                        .Cell("my-cell")
                        .Content()
                        )
                    ).AsString()
                );
        }
        public void PrependsScopeToCombName()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("prepend-this", mem);

            hive.Catalog()
            .Add("123");

            var shifted = hive.Shifted("prepend-this");

            Assert.StartsWith("prepend-this",
                              hive.Comb("123", false).Name()
                              );
        }
        public void RemembersXocument()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("animal", mem);

            hive.Catalog().Add("123");
            hive.Catalog().Add("456");

            hive.Comb("456").Xocument("meatloaf.xml")
            .Modify(
                new Directives()
                .Xpath("/meatloaf")
                .Add("lines")
                .Add("line").Set("And I would do anything for love").Up()
                .Add("line").Set("But I won't do that").Up()
                );

            Assert.Contains(
                "But I won't do that",
                hive.Comb("456")
                .Xocument("meatloaf.xml")
                .Values("//line/text()")
                );
        }
        public void WorksAsyncWithCache()
        {
            using (var dir = new TempDirectory())
            {
                IHive hive =
                    new MemorizedHive(
                        "product",
                        new CachedMnemonic(
                            new FileMnemonic(dir.Value().FullName)
                            )
                        ).Shifted("machine");

                long elapsed = 0;

                Parallel.For(0, 256, (i) =>
                {
                    var id        = $"mech-{i}";
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    hive.Catalog().Add(id);
                    stopWatch.Stop();
                    elapsed += stopWatch.ElapsedMilliseconds;
                });

                Debug.WriteLine("Creation: " + elapsed);
                elapsed = 0;

                Parallel.For(0, 256, (i) =>
                {
                    var id        = $"mech-{i}";
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    var prop = hive.Comb(id).Props().Value("checksum", string.Empty);
                    stopWatch.Stop();
                    elapsed += stopWatch.ElapsedMilliseconds;
                });

                Debug.WriteLine("Read 1: " + elapsed);
                elapsed = 0;

                Parallel.For(0, 256, i =>
                {
                    var id        = $"mech-{i}";
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    hive.Comb(id)
                    .Props()
                    .Refined("checksum", id);
                    stopWatch.Stop();
                    elapsed += stopWatch.ElapsedMilliseconds;
                });

                Debug.WriteLine("Update props: " + elapsed);
                elapsed = 0;

                Parallel.For(0, 256, (i) =>
                {
                    var id        = $"mech-{i}";
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    var prop = hive.Comb(id).Props().Value("checksum", string.Empty);
                    stopWatch.Stop();
                    elapsed += stopWatch.ElapsedMilliseconds;
                });

                Debug.WriteLine("Read 2: " + elapsed);
                elapsed = 0;

                Parallel.For(0, 256, i =>
                {
                    var id   = $"mech-{i}";
                    var xoc  = hive.Comb(id).Xocument("stuff.xml");
                    var name = xoc.Value($"/stuff/thing/text()", "");
                    xoc.Modify(new Directives().Xpath("//name").Set(Guid.NewGuid()));

                    var xoc2  = hive.Comb(id).Xocument("stuff.xml");
                    var name2 = xoc.Value($"/stuff/thing/text()", "");
                    xoc2.Modify(new Directives().Xpath("/stuff").AddIf("thing").Set(Guid.NewGuid()));

                    var xoc3  = hive.Comb(id).Xocument("stuff.xml");
                    var name3 = xoc.Value($"/stuff/thing/text()", "");
                    xoc3.Modify(new Directives().Xpath("/stuff").AddIf("thing").Set(Guid.NewGuid()));

                    Assert.Equal(1, hive.Shifted("machine").Comb(id).Xocument("stuff.xml").Nodes("//thing").Count);
                });


                Debug.WriteLine("Read Stuff: " + elapsed);
                elapsed = 0;
            }
        }