Skip to content

Commit

Permalink
Merge branch 'main' into release/3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
quigamdev committed Aug 27, 2021
2 parents c478a08 + d98f33c commit dd394c2
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 22 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
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,48 @@ protected override Expression VisitIndex(IndexExpression node)

protected override Expression VisitMethodCall(MethodCallExpression node)
{
if (node.Method.Attributes.HasFlag(MethodAttributes.SpecialName))
{
var expr = TryVisitMethodCallWithSpecialName(node);
if (expr != null)
return expr;
}

return CheckForNull(Visit(node.Object), target =>
Expression.Call(target, node.Method, UnwrapNullableTypes(node.Arguments)),
suppress: node.Object?.Type?.IsNullable() ?? true
);
}

private Expression TryVisitMethodCallWithSpecialName(MethodCallExpression node)
{
// Check if we are translating an access to indexer property
if (node.Method.Name.StartsWith("get_", StringComparison.Ordinal) || node.Method.Name.StartsWith("set_", StringComparison.Ordinal))
{
var targetType = node.Object?.Type;
if (targetType == null)
return null;

var indexer = targetType.GetProperties().SingleOrDefault(p => p.GetIndexParameters().Length > 0);
if (indexer == null)
return null;

if (!node.Method.Name.Equals($"get_{indexer.Name}", StringComparison.Ordinal) && !node.Method.Name.Equals($"set_{indexer.Name}", StringComparison.Ordinal))
return null;

return CheckForNull(Visit(node.Object), target =>
{
return CheckForNull(Visit(node.Arguments.First()), index =>
{
var convertedIndex = TypeConversion.ImplicitConversion(index, node.Method.GetParameters().First().ParameterType);
return Expression.Call(target, node.Method, new[] { convertedIndex }.Concat(node.Arguments.Skip(1)));
});
}, suppress: node.Object?.Type?.IsNullable() ?? true);
}

return null;
}

protected override Expression VisitNew(NewExpression node)
{
return Expression.New(node.Constructor, UnwrapNullableTypes(node.Arguments));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getItem<Key, Value>(dictionary: Dictionary<Key, Value>, identifi
throw Error("Provided key \"" + identifier + "\" is not present in the dictionary!");
}

return dictionary[index].Value;
return ko.unwrap(dictionary[index]).Value;
}

export function remove<Key, Value>(observable: any, identifier: Key): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down
14 changes: 7 additions & 7 deletions src/DotVVM.Samples.Tests/DotVVM.Samples.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Riganti.Selenium.Coordinator.Client" Version="3.0.0-preview07-final" />
<PackageReference Include="Riganti.Selenium.Core" Version="3.0.0-preview07-final" />
<PackageReference Include="Riganti.Selenium.Core.Abstractions" Version="3.0.0-preview07-final" />
<PackageReference Include="Riganti.Selenium.DotVVM" Version="3.0.0-preview07-final" />
<PackageReference Include="Riganti.Selenium.AssertApi" Version="3.0.0-preview07-final" />
<PackageReference Include="Riganti.Selenium.xUnitIntegration" Version="3.0.0-preview07-final" />
<PackageReference Include="Riganti.Selenium.Validators" Version="3.0.0-preview07-final" />
<PackageReference Include="Riganti.Selenium.Coordinator.Client" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.Core" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.Core.Abstractions" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.DotVVM" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.AssertApi" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.xUnitIntegration" Version="3.0.0-preview09-final" />
<PackageReference Include="Riganti.Selenium.Validators" Version="3.0.0-preview09-final" />
</ItemGroup>

<ItemGroup>
Expand Down
31 changes: 18 additions & 13 deletions src/DotVVM.Samples.Tests/Feature/DictionaryTranslationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ public void Feature_DictionaryTranslation_Clear()
{
RunInAllBrowsers(browser => {
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_JavascriptTranslation_DictionaryIndexerTranslation);
// Clear dictionary
var inputs = browser.FindElements("input");
inputs.ElementAt(4).Click();
var spans = browser.FindElements("span");
WaitForExecutor.WaitFor(() => {
var spans = browser.FindElements("span");
AssertUI.Text(spans.FirstOrDefault(), s => !s.Contains("KEY: "), waitForOptions: WaitForOptions.Disabled);
AssertUI.Text(spans.ElementAt(1), s => !s.Contains("VAL: "), waitForOptions: WaitForOptions.Disabled);
});
AssertUI.Text(spans.FirstOrDefault(), s => !s.Contains("KEY: "));
AssertUI.Text(spans.ElementAt(1), s => !s.Contains("VAL: "));
});
}

Expand All @@ -41,7 +42,7 @@ public void Feature_DictionaryTranslation_ContainsKey()
inputs.FirstOrDefault().SendKeys("key1");
inputs.ElementAt(2).Click();
AssertUI.TextEquals(inputs.ElementAt(2), "true");
inputs.FirstOrDefault().Clear().SendKeys("key123");
inputs.ElementAt(2).Click();
AssertUI.TextEquals(inputs.ElementAt(2), "false");
Expand Down Expand Up @@ -74,7 +75,7 @@ public void Feature_DictionaryTranslation_GetItem()
AssertUI.TextEquals(spans.FirstOrDefault(), "KEY: \"key1\"");
AssertUI.TextEquals(spans.ElementAt(1), "VAL: \"value1\"");
AssertUI.TextEquals(spans.ElementAt(2), "KEY: \"key2\"");
AssertUI.TextEquals(spans.ElementAt(3),"VAL: \"value2\"");
AssertUI.TextEquals(spans.ElementAt(3), "VAL: \"value2\"");
});
}

Expand Down Expand Up @@ -128,17 +129,21 @@ public void Feature_DictionaryTranslation_AddKeyValue_ThenSetItem()
inputs.ElementAt(1).SendKeys("value123");
inputs.ElementAt(3).Click();
var spans = browser.FindElements("span");
AssertUI.TextEquals(spans.ElementAt(4), "KEY: \"key123\"");
AssertUI.TextEquals(spans.ElementAt(5), "VAL: \"value123\"");
WaitForExecutor.WaitFor(() => {
var spans = browser.FindElements("span");
AssertUI.TextEquals(spans.ElementAt(4), "KEY: \"key123\"", waitForOptions: WaitForOptions.Disabled);
AssertUI.TextEquals(spans.ElementAt(5), "VAL: \"value123\"", waitForOptions: WaitForOptions.Disabled);
});
// Change value
inputs.FirstOrDefault().Clear().SendKeys("key123");
inputs.ElementAt(1).Clear().SendKeys("changed-value123");
inputs.ElementAt(3).Click();
AssertUI.TextEquals(spans.ElementAt(4), "KEY: \"key123\"");
AssertUI.TextEquals(spans.ElementAt(5), "VAL: \"changed-value123\"");
WaitForExecutor.WaitFor(() => {
var spans = browser.FindElements("span");
AssertUI.TextEquals(spans.ElementAt(4), "KEY: \"key123\"", waitForOptions: WaitForOptions.Disabled);
AssertUI.TextEquals(spans.ElementAt(5), "VAL: \"changed-value123\"", waitForOptions: WaitForOptions.Disabled);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void Feature_FormControlsEnabled_FormControlsEnabled()
string[] prefixes = { "b", "c", "cb", "lb", "rb", "tb" };

RunInAllBrowsers(browser => {
browser.Driver.Manage().Window.Size = new System.Drawing.Size(1920, 1000);
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_FormControlsEnabled_FormControlsEnabled);
// LinkButton tests. Selenium does not recognize them as disabled as that is handled by DotVVM.
Expand Down

0 comments on commit dd394c2

Please sign in to comment.