public void Visit_ValidPathToArray_ReturnsListAdapter(object targetObject, string path, object expectedTargetObject) { // Arrange var visitor = new ObjectVisitor(new ParsedPath(path), new DefaultContractResolver()); // Act var visitStatus = visitor.TryVisit(ref targetObject, out var adapter, out var message); // Assert Assert.True(visitStatus); Assert.True(string.IsNullOrEmpty(message), "Expected no error message"); Assert.Same(expectedTargetObject, targetObject); Assert.IsType <ListAdapter>(adapter); }
public void Visit_ValidPathToDictionary_ReturnsDictionaryAdapter(object targetObject, string path, object expectedTargetObject) { // Arrange var visitor = new ObjectVisitor(new ParsedPath(path), new DefaultContractResolver()); // Act var visitStatus = visitor.TryVisit(ref targetObject, out var adapter, out var message); // Assert Assert.True(visitStatus); Assert.True(string.IsNullOrEmpty(message), "Expected no error message"); Assert.Same(expectedTargetObject, targetObject); Assert.Equal(typeof(DictionaryAdapter <string, string>), adapter.GetType()); }
public void Visit_NullTarget_ReturnsNullAdapter() { // Arrange var visitor = new ObjectVisitor(new ParsedPath("test"), new DefaultContractResolver()); // Act object target = null; var visitStatus = visitor.TryVisit(ref target, out var adapter, out var message); // Assert Assert.False(visitStatus); Assert.Null(adapter); Assert.Null(message); }
public void Visit_InvalidIndexFormatToArray_Fails(string position) { // Arrange var visitor = new ObjectVisitor(new ParsedPath($"/Customers/{position}/States/-"), new DefaultContractResolver()); var automobileDepartment = new Class1Nested(); object targetObject = automobileDepartment; // Act var visitStatus = visitor.TryVisit(ref targetObject, out var adapter, out var message); // Assert Assert.False(visitStatus); Assert.Equal($"The path segment '{position}' is invalid for an array index.", message); }
public void Visit_DoesNotValidate_FinalPathSegment() { // Arrange var visitor = new ObjectVisitor(new ParsedPath($"/NonExisting"), new DefaultContractResolver()); var model = new Class1(); object targetObject = model; // Act var visitStatus = visitor.TryVisit(ref targetObject, out var adapter, out var message); // Assert Assert.True(visitStatus); Assert.True(string.IsNullOrEmpty(message), "Expected no error message"); Assert.IsType <PocoAdapter>(adapter); }
public void Visit_InvalidIndexToArray_Fails(string position) { // Arrange var visitor = new ObjectVisitor(new ParsedPath($"/Customers/{position}/States/-"), new DefaultContractResolver()); var automobileDepartment = new Class1Nested(); object targetObject = automobileDepartment; // Act var visitStatus = visitor.TryVisit(ref targetObject, out var adapter, out var message); // Assert Assert.False(visitStatus); Assert.Equal( string.Format("The index value provided by path segment '{0}' is out of bounds of the array size.", position), message); }
public void Visit_NullInteriorTarget_ReturnsFalse() { // Arrange var visitor = new ObjectVisitor(new ParsedPath("/States/0"), new DefaultContractResolver()); // Act object target = new Class1() { States = null, }; var visitStatus = visitor.TryVisit(ref target, out var adapter, out var message); // Assert Assert.False(visitStatus); Assert.Null(adapter); Assert.Null(message); }