diff --git a/src/Samples/Common/DotVVM.Samples.Common.csproj b/src/Samples/Common/DotVVM.Samples.Common.csproj index 4602ac2f7a..bd6baaecd1 100644 --- a/src/Samples/Common/DotVVM.Samples.Common.csproj +++ b/src/Samples/Common/DotVVM.Samples.Common.csproj @@ -127,6 +127,7 @@ + diff --git a/src/Samples/Common/ViewModels/FeatureSamples/ViewModelDeserialization/PropertyNullAssignmentViewModel.cs b/src/Samples/Common/ViewModels/FeatureSamples/ViewModelDeserialization/PropertyNullAssignmentViewModel.cs new file mode 100644 index 0000000000..154d660a92 --- /dev/null +++ b/src/Samples/Common/ViewModels/FeatureSamples/ViewModelDeserialization/PropertyNullAssignmentViewModel.cs @@ -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; + } + } +} + diff --git a/src/Samples/Common/Views/FeatureSamples/ViewModelDeserialization/PropertyNullAssignment.dothtml b/src/Samples/Common/Views/FeatureSamples/ViewModelDeserialization/PropertyNullAssignment.dothtml new file mode 100644 index 0000000000..7674deee2a --- /dev/null +++ b/src/Samples/Common/Views/FeatureSamples/ViewModelDeserialization/PropertyNullAssignment.dothtml @@ -0,0 +1,21 @@ +@viewModel DotVVM.Samples.Common.ViewModels.FeatureSamples.ViewModelDeserialization.PropertyNullAssignmentViewModel, DotVVM.Samples.Common + + + + + + + + + + +

{{value: NullableDateTime}}

+ + + + + + + + + diff --git a/src/Samples/Tests/Abstractions/SamplesRouteUrls.designer.cs b/src/Samples/Tests/Abstractions/SamplesRouteUrls.designer.cs index 899b5ad55c..89dde243e6 100644 --- a/src/Samples/Tests/Abstractions/SamplesRouteUrls.designer.cs +++ b/src/Samples/Tests/Abstractions/SamplesRouteUrls.designer.cs @@ -381,6 +381,7 @@ public partial class SamplesRouteUrls public const string FeatureSamples_ViewModelCache_ViewModelCacheMiss = "FeatureSamples/ViewModelCache/ViewModelCacheMiss"; public const string FeatureSamples_ViewModelDeserialization_DoesNotDropObject = "FeatureSamples/ViewModelDeserialization/DoesNotDropObject"; public const string FeatureSamples_ViewModelDeserialization_NegativeLongNumber = "FeatureSamples/ViewModelDeserialization/NegativeLongNumber"; + public const string FeatureSamples_ViewModelDeserialization_PropertyNullAssignment = "FeatureSamples/ViewModelDeserialization/PropertyNullAssignment"; public const string FeatureSamples_ViewModelNesting_NestedViewModel = "FeatureSamples/ViewModelNesting/NestedViewModel"; public const string FeatureSamples_ViewModelProtection_ComplexViewModelProtection = "FeatureSamples/ViewModelProtection/ComplexViewModelProtection"; public const string FeatureSamples_ViewModelProtection_NestedSignatures = "FeatureSamples/ViewModelProtection/NestedSignatures"; diff --git a/src/Samples/Tests/Tests/Feature/ViewModelDeserializationTests.cs b/src/Samples/Tests/Tests/Feature/ViewModelDeserializationTests.cs index 83a93fe586..207220877a 100644 --- a/src/Samples/Tests/Tests/Feature/ViewModelDeserializationTests.cs +++ b/src/Samples/Tests/Tests/Feature/ViewModelDeserializationTests.cs @@ -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) { }