예제 #1
0
    public void Get_UsingCaseSensitiveKey_FailureScenario()
    {
        // Arrange
        var dictionaryAdapter = new DictionaryAdapter <string, object>();
        var resolver          = new DefaultContractResolver();
        var nameKey           = "Name";
        var dictionary        = new Dictionary <string, object>(StringComparer.Ordinal);

        // Act
        var addStatus = dictionaryAdapter.TryAdd(dictionary, nameKey, resolver, "James", out var message);

        // Assert
        Assert.True(addStatus);
        Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
        Assert.Single(dictionary);
        Assert.Equal("James", dictionary[nameKey]);

        // Act
        var getStatus = dictionaryAdapter.TryGet(dictionary, nameKey.ToUpperInvariant(), resolver, out var outValue, out message);

        // Assert
        Assert.False(getStatus);
        Assert.Equal("The target location specified by path segment 'NAME' was not found.", message);
        Assert.Null(outValue);
    }
예제 #2
0
    public void GetInvalidKey_ThrowsInvalidPathSegmentException()
    {
        // Arrange
        var dictionaryAdapter = new DictionaryAdapter <int, object>();
        var resolver          = new DefaultContractResolver();
        var key        = 1;
        var dictionary = new Dictionary <int, object>();

        // Act
        var addStatus = dictionaryAdapter.TryAdd(dictionary, key.ToString(CultureInfo.InvariantCulture), resolver, "James", out var message);

        // Assert
        Assert.True(addStatus);
        Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
        Assert.Single(dictionary);
        Assert.Equal("James", dictionary[key]);

        // Act
        var guidKey   = new Guid();
        var getStatus = dictionaryAdapter.TryGet(dictionary, guidKey.ToString(), resolver, out var outValue, out message);

        // Assert
        Assert.False(getStatus);
        Assert.Equal($"The provided path segment '{guidKey.ToString()}' cannot be converted to the target type.", message);
        Assert.Null(outValue);
    }
예제 #3
0
        public void GetInvalidKey_ThrowsInvalidPathSegmentException()
        {
            // Arrange
            var dictionaryAdapter = new DictionaryAdapter <int, object>();
            var key        = 1;
            var dictionary = new Dictionary <int, object>();
            var options    = new JsonSerializerOptions();

            // Act
            var addStatus = dictionaryAdapter.TryAdd(dictionary, typeof(Dictionary <int, object>), key.ToString(), options, "James", out var message);

            // Assert
            Assert.True(addStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Single(dictionary);
            Assert.Equal("James", dictionary[key]);

            // Act
            var guidKey   = new Guid();
            var getStatus = dictionaryAdapter.TryGet(dictionary, typeof(Dictionary <int, object>), guidKey.ToString(), options, out var outValue, out message);

            // Assert
            Assert.False(getStatus);
            Assert.Equal($"The provided path segment '{guidKey}' cannot be converted to the target type.", message);
            Assert.Null(outValue);
        }
예제 #4
0
    public void Get_UsingCaseSensitiveKey_SuccessScenario()
    {
        // Arrange
        var dictionaryAdapter = new DictionaryAdapter <string, object>();
        var resolver          = new DefaultContractResolver();
        var nameKey           = "Name";
        var dictionary        = new Dictionary <string, object>(StringComparer.Ordinal);

        // Act
        var addStatus = dictionaryAdapter.TryAdd(dictionary, nameKey, resolver, "James", out var message);

        // Assert
        Assert.True(addStatus);
        Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
        Assert.Single(dictionary);
        Assert.Equal("James", dictionary[nameKey]);

        // Act
        addStatus = dictionaryAdapter.TryGet(dictionary, nameKey, resolver, out var outValue, out message);

        // Assert
        Assert.True(addStatus);
        Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
        Assert.Equal("James", outValue?.ToString());
    }
예제 #5
0
        public void Get_UsingCaseSensitiveKey_SuccessScenario()
        {
            // Arrange
            var dictionaryAdapter = new DictionaryAdapter <string, object>();
            var nameKey           = "Name";
            var dictionary        = new Dictionary <string, object>(StringComparer.Ordinal);
            var options           = new JsonSerializerOptions();

            // Act
            var addStatus = dictionaryAdapter.TryAdd(dictionary, typeof(Dictionary <string, object>), nameKey, options, "James", out var message);

            // Assert
            Assert.True(addStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Single(dictionary);
            Assert.Equal("James", dictionary[nameKey]);

            // Act
            addStatus = dictionaryAdapter.TryGet(dictionary, typeof(Dictionary <string, object>), nameKey, options, out var outValue, out message);

            // Assert
            Assert.True(addStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Equal("James", outValue?.ToString());
        }