Skip to content

Commit

Permalink
Added more tests for null propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
acizmarik committed Aug 26, 2021
1 parent 8bdd655 commit 4ebe7d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/DotVVM.Framework.Tests/Binding/BindingCompilationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ class TestViewModel
{
public string StringProp { get; set; }
public int IntProp { get; set; }
public int? NullableIntProp { get; set; }
public double DoubleProp { get; set; }
public TestViewModel2 TestViewModel2 { get; set; }
public TestViewModel2 TestViewModel2B { get; set; }
Expand All @@ -979,6 +980,8 @@ class TestViewModel
public long[] LongArray => new long[] { 1, 2, long.MaxValue };
public List<long> LongList => new List<long>() { 1, 2, long.MaxValue };
public string[] StringArray => new string[] { "Hello ", "DotVVM" };
public Dictionary<string, TestViewModel2> StringVmDictionary = new() { { "a", new TestViewModel2() }, { "b", new TestViewModel2() } };
public Dictionary<int?, TestViewModel2> NullableIntVmDictionary = new() { { 0, new TestViewModel2() }, { 1, new TestViewModel2() } };
public TestViewModel2[] VmArray => new TestViewModel2[] { new TestViewModel2() };
public int[] IntArray { get; set; }

Expand Down
9 changes: 9 additions & 0 deletions src/DotVVM.Framework.Tests/Binding/NullPropagationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ public void Indexer()
Assert.IsNull(EvalExpression<TestViewModel>(v => v.TestViewModel2.Collection[0].StringValue.Length + 5, new TestViewModel { IntArray = null }));
}

[TestMethod]
public void IndexerArgument()
{
Assert.IsNull(EvalExpression<TestViewModel>(v => v.IntArray[v.NullableIntProp.Value], new TestViewModel()));
Assert.IsNull(EvalExpression<TestViewModel>(v => v.TestViewModel2.Collection[v.NullableIntProp.Value], new TestViewModel()));
Assert.IsNull(EvalExpression<TestViewModel>(v => v.StringVmDictionary[v.StringProp], new TestViewModel()));
Assert.IsNull(EvalExpression<TestViewModel>(v => v.NullableIntVmDictionary[v.NullableIntProp], new TestViewModel()));
}

[TestMethod]
public void Coalesce()
{
Expand Down

0 comments on commit 4ebe7d0

Please sign in to comment.