Skip to content

Commit

Permalink
Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg committed Sep 29, 2023
1 parent abb2229 commit 57442c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ public string Text
}
public static readonly DotvvmProperty TextProperty
= DotvvmProperty.Register<string, ControlWithExtractGenericArgument>(c => c.Text, null);

[ExtractGenericArgumentDataContextChange(typeof(List<>), 0)]
public string Text2
{
get { return (string)GetValue(Text2Property); }
set { SetValue(Text2Property, value); }
}
public static readonly DotvvmProperty Text2Property
= DotvvmProperty.Register<string, ControlWithExtractGenericArgument>(c => c.Text2, null);

}

public class ListOfString : List<string>
{
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public void ResolvedTree_CustomBindingResolverInDataContext()
}

[TestMethod]
public void ResolvedTree_DataContextChange_ExtractGenericArgument()
public void ResolvedTree_DataContextChange_ExtractGenericArgument_Interface()
{
var prop = ControlWithExtractGenericArgument.TextProperty;

Expand All @@ -682,6 +682,36 @@ public void ResolvedTree_DataContextChange_ExtractGenericArgument()
Assert.AreEqual(typeof(List<string>), binding.Binding.DataContextTypeStack.Parent!.DataContextType);
}

[TestMethod]
public void ResolvedTree_DataContextChange_ExtractGenericArgument_Self()
{
var prop = ControlWithExtractGenericArgument.Text2Property;

var root = ParseSource(@"@viewModel System.Collections.Generic.List<System.String>
<cc:ControlWithExtractGenericArgument Text2={value: _this} />");

var binding = root.Content.Single().Properties[prop] as ResolvedPropertyBinding;
Assert.IsNotNull(binding);

Assert.AreEqual(typeof(string), binding.Binding.DataContextTypeStack.DataContextType);
Assert.AreEqual(typeof(List<string>), binding.Binding.DataContextTypeStack.Parent!.DataContextType);
}

[TestMethod]
public void ResolvedTree_DataContextChange_ExtractGenericArgument_BaseType()
{
var prop = ControlWithExtractGenericArgument.Text2Property;

var root = ParseSource(@"@viewModel DotVVM.Framework.Tests.Runtime.ControlTree.DefaultControlTreeResolver.ListOfString
<cc:ControlWithExtractGenericArgument Text2={value: _this} />");

var binding = root.Content.Single().Properties[prop] as ResolvedPropertyBinding;
Assert.IsNotNull(binding);

Assert.AreEqual(typeof(string), binding.Binding.DataContextTypeStack.DataContextType);
Assert.AreEqual(typeof(ListOfString), binding.Binding.DataContextTypeStack.Parent!.DataContextType);
}

[TestMethod]
public void DefaultViewCompiler_ControlUsageValidator()
{
Expand Down

0 comments on commit 57442c4

Please sign in to comment.