Skip to content

Commit

Permalink
Repro for a bug with null assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg committed Sep 29, 2023
1 parent b3dcbc7 commit e5a5d1a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Samples/Common/DotVVM.Samples.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<None Remove="Views\FeatureSamples\Validation\RangeClientSideValidation.dothtml" />
<None Remove="Views\FeatureSamples\Validation\ValidationTargetIsCollection.dothtml" />
<None Remove="Views\FeatureSamples\Validation\ValidatorValueComplexExpressions.dothtml" />
<None Remove="Views\FeatureSamples\ViewModelDeserialization\PropertyNullAssignment.dothtml" />
<None Remove="Views\FeatureSamples\ViewModules\Incrementer.dotcontrol" />
<None Remove="Views\FeatureSamples\ViewModules\IncrementerInRepeater.dothtml" />
<None Remove="Views\FeatureSamples\ViewModules\InnerModuleControl.dotcontrol" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.ViewModel;
using DotVVM.Framework.Hosting;

namespace DotVVM.Samples.Common.ViewModels.FeatureSamples.ViewModelDeserialization
{
public class PropertyNullAssignmentViewModel : DotvvmViewModelBase
{

public DateTime? NullableDateTime { get; set; }

public DateTime Value { get; set; } = new DateTime(2023, 1, 2, 3, 4, 5, 678);

public void SetNullableDateTimeToNull()
{
NullableDateTime = null;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@viewModel DotVVM.Samples.Common.ViewModels.FeatureSamples.ViewModelDeserialization.PropertyNullAssignmentViewModel, DotVVM.Samples.Common

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>

<p class="result">{{value: NullableDateTime}}</p>

<dot:Button Text="Set value" Click="{command: NullableDateTime = Value}" />
<dot:Button Text="Set null" Click="{command: NullableDateTime = null}" />
<dot:Button Text="Set null with command" Click="{command: SetNullableDateTimeToNull()}" />

</body>
</html>


Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/Samples/Tests/Tests/Feature/ViewModelDeserializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ public void Feature_ViewModelDeserialization_NegativeLongNumber()
});
}

[Fact]
public void Feature_ViewModelDeserialization_PropertyNullAssignment()
{
RunInAllBrowsers(browser => {
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_ViewModelDeserialization_PropertyNullAssignment);

var value = browser.Single(".result");
var buttons = browser.FindElements("input[type=button]");

AssertUI.InnerTextEquals(value, "");

buttons[0].Click();
AssertUI.InnerTextEquals(value, "1/2/2023 3:04:05 AM");

buttons[1].Click();
AssertUI.InnerTextEquals(value, "");

buttons[0].Click();
AssertUI.InnerTextEquals(value, "1/2/2023 3:04:05 AM");

buttons[2].Click();
AssertUI.InnerTextEquals(value, "");
});
}

public ViewModelDeserializationTests(ITestOutputHelper output) : base(output)
{
}
Expand Down

0 comments on commit e5a5d1a

Please sign in to comment.