Skip to content

Commit

Permalink
null propagation: few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Apr 5, 2020
1 parent 20aac34 commit 4c5b30b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Expand Up @@ -574,6 +574,7 @@ class TestViewModel

public long[] LongArray => new long[] { 1, 2, long.MaxValue };
public TestViewModel2[] VmArray => new TestViewModel2[] { new TestViewModel2() };
public int[] IntArray { get; set; }

public string SetStringProp(string a, int b)
{
Expand Down
24 changes: 24 additions & 0 deletions src/DotVVM.Framework.Tests.Common/Binding/NullPropagationTests.cs
Expand Up @@ -245,6 +245,30 @@ public void MethodArgument_Null_RefType()
Assert.IsNull(EvalExpression<TestViewModel>(v => Identity(v), null));
Assert.IsNull(EvalExpression<TestViewModel>(v => Identity(v.LongArray), null));
}

[TestMethod]
public void Operator()
{
Assert.IsNull(EvalExpression<TestViewModel>(v => v.LongArray[0] + 1, null));
Assert.IsNull(EvalExpression<TestViewModel>(v => v.LongArray[0] + v.TestViewModel2.MyProperty, new TestViewModel()));
Assert.IsNull(EvalExpression<TestViewModel>(v => v.TestViewModel2B.ChildObject.SomeString.Length + v.TestViewModel2.MyProperty, new TestViewModel()));
Assert.Equals(2, EvalExpression<TestViewModel>(v => v.LongArray[0] + 1, new TestViewModel()));
}

[TestMethod]
public void StringConcat()
{
Assert.Equals("abc", EvalExpression<TestViewModel>(v => v.StringProp + "abc", null));
}

[TestMethod]
public void Indexer()
{
Assert.IsNull(EvalExpression<TestViewModel>(v => v.IntArray[0] + 1, null));
Assert.IsNull(EvalExpression<TestViewModel>(v => v.IntArray[0] + 1, new TestViewModel { IntArray = null }));
Assert.IsNull(EvalExpression<TestViewModel>(v => v.TestViewModel2.Collection[0].StringValue.Length + 5, new TestViewModel { IntArray = null }));
Assert.IsNull(EvalExpression<TestViewModel>(v => v.TestViewModel2.Collection[0].StringValue.Length + 5, new TestViewModel { IntArray = null }));
}
}

public static class EnumerableExtensions
Expand Down

0 comments on commit 4c5b30b

Please sign in to comment.