public static void Indexer_WhenGivenNullKey_ThrowsArgumentNullException()
        {
            var dictionary          = new Dictionary <Identifier, string>();
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            Assert.That(() => _ = resolvingDictionary[null], Throws.ArgumentNullException);
        }
        public static void ContainsKey_WhenGivenNullKey_ThrowsArgumentNullException()
        {
            var dictionary          = new Dictionary <Identifier, string>();
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            Assert.That(() => resolvingDictionary.ContainsKey(null), Throws.ArgumentNullException);
        }
        public static void Enumerator_WhenInvoked_EnumeratesSameValuesAsCtorArg()
        {
            var dictionary = new Dictionary <Identifier, string>
            {
                ["B"] = "b",
                ["C"] = "c"
            };
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            Assert.That(resolvingDictionary, Is.EqualTo(dictionary));
        }
        public static void Count_PropertyGet_MatchesCountInCtorArg()
        {
            var dictionary = new Dictionary <Identifier, string>
            {
                ["B"] = "b",
                ["C"] = "c"
            };
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            Assert.That(dictionary.Count, Is.EqualTo(resolvingDictionary.Count));
        }
        public static void Indexer_WhenGivenKeyInNotDictionaryAndDoesNotResolveToOne_ThrowsKeyNotFoundException()
        {
            var dictionary = new Dictionary <Identifier, string>
            {
                ["X"] = "x",
                ["Y"] = "y",
                ["Z"] = "z"
            };
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            Assert.That(() => _ = resolvingDictionary["B"], Throws.TypeOf <KeyNotFoundException>());
        }
        public static void ContainsKey_WhenGivenKeyNotInDictionaryButResolvesToOne_ReturnsTrue()
        {
            var dictionary = new Dictionary <Identifier, string>
            {
                ["B"] = "b",
                ["C"] = "c"
            };
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            var keyPresent = resolvingDictionary.ContainsKey("Z");

            Assert.That(keyPresent, Is.True);
        }
        public static void Indexer_WhenGivenKeyInDictionary_ReturnsCorrectValue()
        {
            var dictionary = new Dictionary <Identifier, string>
            {
                ["B"] = "b",
                ["C"] = "c"
            };
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            var result = resolvingDictionary["B"];

            Assert.That(result, Is.EqualTo("b"));
        }
        public static void ContainsKey_WhenGivenKeyInNotDictionaryAndDoesNotResolveToOne_ReturnsFalse()
        {
            var dictionary = new Dictionary <Identifier, string>
            {
                ["X"] = "x",
                ["Y"] = "y",
                ["Z"] = "z"
            };
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            var keyPresent = resolvingDictionary.ContainsKey("B");

            Assert.That(keyPresent, Is.False);
        }
        public static void TryGetValue_WhenGivenKeyInDictionary_ReturnsTrueAndCorrectValue()
        {
            var dictionary = new Dictionary <Identifier, string>
            {
                ["B"] = "b",
                ["C"] = "c"
            };
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            var keyPresent = resolvingDictionary.TryGetValue("B", out var value);

            Assert.Multiple(() =>
            {
                Assert.That(keyPresent, Is.True);
                Assert.That(value, Is.EqualTo("b"));
            });
        }
        public static void TryGetValue_WhenGivenKeyInNotDictionaryAndDoesNotResolveToOne_ReturnsFalseAndNullValue()
        {
            var dictionary = new Dictionary <Identifier, string>
            {
                ["X"] = "x",
                ["Y"] = "y",
                ["Z"] = "z"
            };
            var resolver            = new FakeIdentifierResolver();
            var resolvingDictionary = new IdentifierResolvingDictionary <string>(dictionary, resolver);

            var keyPresent = resolvingDictionary.TryGetValue("B", out var value);

            Assert.Multiple(() =>
            {
                Assert.That(keyPresent, Is.False);
                Assert.That(value, Is.Null);
            });
        }