Example #1
0
        public void Replace_NonCompatibleType_Fails()
        {
            // Arrange
            var resolver     = new DefaultContractResolver();
            var targetObject = new List <int>()
            {
                10, 20
            };
            var listAdapter = new ListAdapter();

            // Act
            var replaceStatus = listAdapter.TryReplace(targetObject, "-", resolver, "James", out var message);

            // Assert
            Assert.False(replaceStatus);
            Assert.Equal("The value 'James' is invalid for target location.", message);
        }
Example #2
0
        public void Replace_ReplacesValue_AtGivenPosition(string position, List <int> expected)
        {
            // Arrange
            var resolver     = new DefaultContractResolver();
            var targetObject = new List <int>()
            {
                10, 20
            };
            var listAdapter = new ListAdapter();

            // Act
            var replaceStatus = listAdapter.TryReplace(targetObject, position, resolver, "30", out var message);

            // Assert
            Assert.True(replaceStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Equal(expected, targetObject);
        }
Example #3
0
        public void Replace_NonCompatibleType_Fails()
        {
            // Arrange
            var resolver     = new Mock <IContractResolver>(MockBehavior.Strict);
            var targetObject = new List <int>()
            {
                10, 20
            };
            var listAdapter = new ListAdapter();

            // Act
            var replaceStatus = listAdapter.TryReplace(targetObject, "-", resolver.Object, "James", out var message);

            // Assert
            Assert.False(replaceStatus);
            Assert.Equal(
                string.Format("The value '{0}' is invalid for target location.", "James"),
                message);
        }
Example #4
0
        public void Replace_ReplacesValue_AtTheEnd()
        {
            // Arrange
            var resolver     = new Mock <IContractResolver>(MockBehavior.Strict);
            var targetObject = new List <int>()
            {
                10, 20
            };
            var listAdapter = new ListAdapter();

            // Act
            var replaceStatus = listAdapter.TryReplace(targetObject, "-", resolver.Object, "30", out var message);

            // Assert
            Assert.True(replaceStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Equal(new List <int>()
            {
                10, 30
            }, targetObject);
        }