Exemplo n.º 1
0
        public void Can_fetch_the_oldest_element_in_the_cache()
        {
            var type  = DefinitionCacheItemType.Script;
            var time  = new DateTime(2012, 1, 1, 0, 0, 0);
            var cache = new DefinitionCache();

            cache
            .Add(type, "", DateTime.Now, false, true, "cmd1", "")
            .Append(type, "", DateTime.Now, false, true, "cmd2", "")
            .Append(type, "", DateTime.Now, false, true, "cmd3", "")
            .Append(type, "", time, false, false, "-g", "");
            cache
            .Add(type, "", DateTime.Now, false, true, "cmd1-1", "")
            .Append(type, "", DateTime.Now, false, true, "cmdAnother", "");
            Assert.That(cache.GetOldestItem().Name, Is.EqualTo("-g"));
        }
Exemplo n.º 2
0
        public void Can_get_built_in_command_hidden_by_override()
        {
            var cache = new DefinitionCache();

            cache
            .Add(DefinitionCacheItemType.BuiltIn, "l1", DateTime.Now, false, true, "cmd1", "")
            .Append(DefinitionCacheItemType.BuiltIn, "l1", DateTime.Now, false, true, "cmd1-1", "");
            cache
            .Add(DefinitionCacheItemType.Script, "l2", DateTime.Now, false, true, "cmd1", "")
            .Append(DefinitionCacheItemType.Script, "l2", DateTime.Now, false, true, "override-1", "");
            var item = cache.GetBuiltIn(new[]   {
                "cmd1"
            });

            Assert.That(item.Type, Is.EqualTo(DefinitionCacheItemType.BuiltIn));
            Assert.That(item.Location, Is.EqualTo("l1"));
            Assert.That(item.Parameters[0].Name, Is.EqualTo("cmd1-1"));
        }
Exemplo n.º 3
0
        public void Stops_at_first_user_defined_content_command()
        {
            var type  = DefinitionCacheItemType.Script;
            var time  = DateTime.Now;
            var cache = new DefinitionCache();

            cache
            .Add(type, "", time, false, true, "cmd1", "")
            .Append(type, "", time, false, true, "USER_DEFINED_ARE_UPPER_CASE", "")
            .Append(type, "", time, false, true, "cmd3", "");
            Assert.That(cache.Get(new[] { "cmd1", "bleh", "cmd3" }).Name, Is.EqualTo("cmd1"));
        }
Exemplo n.º 4
0
        public void Can_find_added_command()
        {
            var type  = DefinitionCacheItemType.Script;
            var time  = DateTime.Now;
            var cache = new DefinitionCache();

            cache
            .Add(type, "", time, false, true, "cmd1", "")
            .Append(type, "", time, false, true, "cmd2", "")
            .Append(type, "", time, false, true, "cmd3", "");
            Assert.That(cache.Get(new[] { "cmd1", "cmd2" }).Name, Is.EqualTo("cmd2"));
        }
Exemplo n.º 5
0
        public void Can_fetch_locations_in_the_cache()
        {
            var type  = DefinitionCacheItemType.Script;
            var cache = new DefinitionCache();

            cache
            .Add(type, "loc1", DateTime.Now, false, true, "cmd1", "")
            .Append(type, "loc1", DateTime.Now, false, true, "cmd2", "")
            .Append(DefinitionCacheItemType.Language, "loc3", new DateTime(2012, 10, 1, 0, 0, 0), false, true, "cmd3", "")
            .Append(type, "loc2", new DateTime(2012, 1, 1, 0, 0, 0), false, false, "-g", "");
            Assert.That(cache.GetLocations(DefinitionCacheItemType.Script).Length, Is.EqualTo(2));
        }
Exemplo n.º 6
0
        public void Can_fetch_the_oldest_element_of_a_spesific_location_in_the_cache()
        {
            var type  = DefinitionCacheItemType.Script;
            var cache = new DefinitionCache();

            cache
            .Add(type, "loc1", DateTime.Now, false, true, "cmd1", "")
            .Append(type, "loc1", DateTime.Now, false, true, "cmd2", "")
            .Append(type, "loc1", new DateTime(2012, 10, 1, 0, 0, 0), false, true, "cmd3", "")
            .Append(type, "loc2", new DateTime(2012, 1, 1, 0, 0, 0), false, false, "-g", "");
            Assert.That(cache.GetOldestItem("loc1").Name, Is.EqualTo("cmd3"));
        }
Exemplo n.º 7
0
        public void Stops_at_first_optional_argument()
        {
            var type  = DefinitionCacheItemType.Script;
            var time  = DateTime.Now;
            var cache = new DefinitionCache();

            cache
            .Add(type, "", time, false, true, "cmd1", "")
            .Append(type, "", time, false, true, "cmd2", "")
            .Append(type, "", time, false, true, "cmd3", "")
            .Append(type, "", time, false, false, "-g", "");
            Assert.That(cache.Get(new[] { "cmd1", "-g", "cmd2", "cmd3" }).Name, Is.EqualTo("cmd1"));
        }
Exemplo n.º 8
0
        public void When_merging_two_definition_caches_it_will_not_add_duplicate_commands()
        {
            var type  = DefinitionCacheItemType.Script;
            var time  = DateTime.Now;
            var cache = new DefinitionCache();

            cache
            .Add(type, "", time, false, true, "cmd1", "")
            .Append(type, "", time, false, true, "cmd2", "")
            .Append(type, "", time, false, true, "cmd3", "")
            .Append(type, "", time, false, false, "-g", "");
            var another = new DefinitionCache();

            another
            .Add(type, "", time, false, true, "cmd1", "")
            .Append(type, "", time, false, true, "cmdAnother", "");
            cache.Merge(new string[]   {
            }, another);
            Assert.That(cache.Definitions.Length, Is.EqualTo(1));
        }
Exemplo n.º 9
0
        public void Can_merge_two_definition_caches()
        {
            var type  = DefinitionCacheItemType.Script;
            var time  = DateTime.Now;
            var cache = new DefinitionCache();

            cache
            .Add(type, "", time, false, true, "cmd1", "")
            .Append(type, "", time, false, true, "cmd2", "")
            .Append(type, "", time, false, true, "cmd3", "")
            .Append(type, "", time, false, false, "-g", "");
            var another = new DefinitionCache();

            another
            .Add(type, "", time, false, true, "cmdAnother", "")
            .Append(type, "", time, false, true, "cmdAnother2", "");
            cache.Merge(new string[]   {
            }, another);
            Assert.That(cache.Definitions.Length, Is.EqualTo(2));
        }
Exemplo n.º 10
0
        public void Can_write_definition_cache()
        {
            string actualJSON = null;
            var    writer     =
                new DefinitionCacheWriter("/write/path")
                .WriteUsing((file, content) => actualJSON = content);

            var type   = DefinitionCacheItemType.Script;
            var script = "/my/script";
            var time   = new DateTime(2013, 1, 1, 2, 3, 1);
            var cache  = new DefinitionCache();

            cache
            .Add(type, script, time, false, true, "mycmd", "My command does my stuff.")
            .Append(type, script, time, false, true, "FILE", "another param")
            .Append(type, script, time, false, false, "optional", "This one is optional");

            writer.Write(cache);
            Assert.That(actualJSON, Is.EqualTo(expectedJSON()));
        }