// internal as well as protected it can be exercised by unit tests.
        protected internal string AddLogicalLocation(LogicalLocation logicalLocation, string delimiter)
        {
            if (logicalLocation == null)
            {
                throw new ArgumentNullException(nameof(logicalLocation));
            }

            int disambiguator = 0;

            string logicalLocationKey = logicalLocation.ParentKey == null ? logicalLocation.Name : logicalLocation.ParentKey + delimiter + logicalLocation.Name;
            string generatedKey = logicalLocationKey;

            while (LogicalLocationsDictionary.ContainsKey(generatedKey) && !logicalLocation.ValueEquals(LogicalLocationsDictionary[generatedKey]))
            {
                generatedKey = logicalLocationKey + "-" + disambiguator.ToString(CultureInfo.InvariantCulture);
                ++disambiguator;
            }

            if (!LogicalLocationsDictionary.ContainsKey(generatedKey))
            {
                LogicalLocationsDictionary.Add(generatedKey, logicalLocation);
            }

            return generatedKey;
        }
        public void ConverterBase_MultipleDistinctIdenticallyNamedLogicalLocations()
        {
            Location location1 = new Location
            {
                FullyQualifiedLogicalName = "a"
            };

            var logicalLocation1 = new LogicalLocation
            {
                Name = "a",
                Kind = LogicalLocationKind.Namespace
            };

            Location location2 = new Location
            {
                FullyQualifiedLogicalName = "a"
            };

            var logicalLocation2 = new LogicalLocation
            {
                Name = "a",
                Kind = LogicalLocationKind.Package
            };

            Location location3 = new Location
            {
                FullyQualifiedLogicalName = "a"
            };

            var logicalLocation3 = new LogicalLocation
            {
                Name = "a",
                Kind = LogicalLocationKind.Member
            };

            var converter = new LogicalLocationTestConverter();

            string logicalLocationKey = converter.AddLogicalLocation(logicalLocation1);
            logicalLocationKey.Should().Be("a");

            logicalLocationKey = converter.AddLogicalLocation(logicalLocation2);
            logicalLocationKey.Should().Be("a-0");

            logicalLocationKey = converter.AddLogicalLocation(logicalLocation3);
            logicalLocationKey.Should().Be("a-1");

            converter.LogicalLocationsDictionary.Keys.Count.Should().Be(3);
            converter.LogicalLocationsDictionary["a"].ValueEquals(logicalLocation1).Should().BeTrue();
            converter.LogicalLocationsDictionary.Keys.Should().Contain("a-0");
            converter.LogicalLocationsDictionary["a-0"].ValueEquals(logicalLocation2).Should().BeTrue();
            converter.LogicalLocationsDictionary.Keys.Should().Contain("a-1");
            converter.LogicalLocationsDictionary["a-1"].ValueEquals(logicalLocation3).Should().BeTrue();
        }
        public void ConverterBase_SingleLogicalLocation()
        {
            Location location = new Location
            {
                FullyQualifiedLogicalName = "a"
            };

            var logicalLocation = new LogicalLocation
            {
                Name = "a",
                Kind = LogicalLocationKind.Namespace
            };

            var converter = new LogicalLocationTestConverter();

            string logicalLocationKey = converter.AddLogicalLocation(logicalLocation);

            location.FullyQualifiedLogicalName.Should().Be(logicalLocationKey);

            converter.LogicalLocationsDictionary.Keys.Count.Should().Be(1);
            converter.LogicalLocationsDictionary.Keys.Should().Contain("a");
            converter.LogicalLocationsDictionary["a"].ValueEquals(logicalLocation).Should().BeTrue();
        }
Beispiel #4
0
        private string TryAddLogicalLocation(string parentKey, string value, string kind, string delimiter = ".")
        {
            var logicalLocation = new LogicalLocation
            {
                ParentKey = parentKey,
                Kind = kind,
                Name = value
            };

            return AddLogicalLocation(logicalLocation, delimiter);
        }
 protected internal string AddLogicalLocation(LogicalLocation logicalLocation)
 {
     return AddLogicalLocation(logicalLocation, delimiter: ".");
 }
        private string TryAddLogicalLocation(string parentKey, string value, string kind, string delimiter = @"\")
        {
            if (!String.IsNullOrEmpty(value))
            {
                var logicalLocation = new LogicalLocation
                {
                    ParentKey = parentKey,
                    Kind = kind,
                    Name = value
                };

                return AddLogicalLocation(logicalLocation, delimiter);
            }
            return parentKey;
        }
Beispiel #7
0
 private void Visit(LogicalLocation logicalLocation, string logicalLocationPointer)
 {
     Analyze(logicalLocation, logicalLocationPointer);
 }
Beispiel #8
0
 protected virtual void Analyze(LogicalLocation logicalLocation, string logicalLocationPointer)
 {
 }
Beispiel #9
0
        public void ConverterBase_MultipleDistinctIdenticallyNamedLogicalLocations()
        {
            Location location1 = new Location
            {
                LogicalLocation = new LogicalLocation
                {
                    FullyQualifiedName = "a"
                }
            };

            var logicalLocation1 = new LogicalLocation
            {
                Name = "a",
                Kind = LogicalLocationKind.Namespace
            };

            Location location2 = new Location
            {
                LogicalLocation = new LogicalLocation
                {
                    FullyQualifiedName = "a"
                }
            };

            var logicalLocation2 = new LogicalLocation
            {
                Name = "a",
                Kind = LogicalLocationKind.Package
            };

            Location location3 = new Location
            {
                LogicalLocation = new LogicalLocation
                {
                    FullyQualifiedName = "a"
                }
            };

            var logicalLocation3 = new LogicalLocation
            {
                Name = "a",
                Kind = LogicalLocationKind.Member
            };

            var converter = new LogicalLocationTestConverter();

            int index = converter.AddLogicalLocation(logicalLocation1);

            converter.LogicalLocations[index].Name.Should().Be("a");
            converter.LogicalLocations[index].FullyQualifiedName.Should().BeNull();

            index = converter.AddLogicalLocation(logicalLocation2);
            index.Should().Be(1);
            converter.LogicalLocations[index].Name.Should().Be("a");
            converter.LogicalLocations.Count.Should().Be(2);

            index = converter.AddLogicalLocation(logicalLocation3);
            index.Should().Be(2);
            converter.LogicalLocations[index].Name.Should().Be("a");
            converter.LogicalLocations.Count.Should().Be(3);
        }
 protected internal string AddLogicalLocation(LogicalLocation logicalLocation)
 {
     return(AddLogicalLocation(logicalLocation, delimiter: "."));
 }