Example #1
0
        public void Deletes_specified_definition()
        {
            DISetup.SetupContainer();
            var defs = new List <IDefinition>();

            for (int i = 0; i < 10; i++)
            {
                defs.Add(new Definition()
                {
                    Code         = i.ToString(),
                    ContentSHA   = i.ToString(),
                    Dependencies = new List <string> {
                        i.ToString()
                    },
                    File    = i.ToString(),
                    Id      = i.ToString(),
                    ModName = i.ToString(),
                    Type    = i.ToString()
                });
            }
            var service = new IndexedDefinitions();

            service.InitMap(defs, true);
            service.Remove(defs.First());
            var result = service.GetAll();

            result.Count().Should().Be(defs.Count - 1);
            result.FirstOrDefault(p => p.Id == "0").Should().BeNull();
            var hierarchalResult = service.GetHierarchicalDefinitions();

            hierarchalResult.First().Children.Count.Should().Be(defs.Count - 1);
            hierarchalResult.First().Children.FirstOrDefault(p => p.Key.StartsWith("0")).Should().BeNull();
            service.GetByTypeAndId(defs.First().TypeAndId).Count().Should().Be(0);
        }
Example #2
0
        public void Returns_by_type_and_id_non_constructed_key()
        {
            DISetup.SetupContainer();
            var defs = new List <IDefinition>();

            for (int i = 0; i < 10; i++)
            {
                defs.Add(new Definition()
                {
                    Code         = i.ToString(),
                    ContentSHA   = i.ToString(),
                    Dependencies = new List <string> {
                        i.ToString()
                    },
                    File    = i < 3 ? "file" : i.ToString(),
                    Id      = i > 4 && i < 7 ? "id" : i.ToString(),
                    ModName = i.ToString(),
                    Type    = i > 3 && i < 6 ? "type" : i.ToString()
                });
            }
            var service = new IndexedDefinitions();

            service.InitMap(defs);
            var results = service.GetByTypeAndId("type-id");

            results.Count().Should().Be(defs.Where(s => s.Type == "type" && s.Id == "id").Count());
            int match = 0;

            foreach (var item in defs.Where(s => s.Type == "type" && s.Id == "id"))
            {
                if (results.Contains(item))
                {
                    match++;
                }
            }
            match.Should().Be(defs.Where(s => s.Type == "type" && s.Id == "id").Count());
        }