-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1525 from riganti/serializer-nerf-records
serializer: only inject properties to constructors of records
- Loading branch information
Showing
17 changed files
with
541 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Samples/Common/ViewModels/ComplexSamples/ViewModelDependencyInjection/ChildViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.ViewModel; | ||
|
||
namespace DotVVM.Samples.Common.ViewModels.ComplexSamples.ViewModelDependencyInjection; | ||
|
||
public class ChildViewModel : DotvvmViewModelBase | ||
{ | ||
public ChildViewModel() | ||
{ | ||
} | ||
|
||
public override Task Init() | ||
{ | ||
if (Context is null) | ||
{ | ||
throw new Exception($"{nameof(Context)} is null in {nameof(Init)} method of {nameof(ParentViewModel)}."); | ||
} | ||
|
||
return base.Init(); | ||
} | ||
|
||
public override Task Load() | ||
{ | ||
if (Context is null) | ||
{ | ||
throw new Exception($"{nameof(Context)} is null in {nameof(Load)} method of {nameof(ParentViewModel)}."); | ||
} | ||
|
||
return base.Load(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Samples/Common/ViewModels/ComplexSamples/ViewModelDependencyInjection/ParentViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.ViewModel; | ||
|
||
namespace DotVVM.Samples.Common.ViewModels.ComplexSamples.ViewModelDependencyInjection; | ||
|
||
public class ParentViewModel : DotvvmViewModelBase | ||
{ | ||
public ChildViewModel ChildViewModel { get; set; } | ||
public bool Result { get; set; } | ||
|
||
|
||
public ParentViewModel(ChildViewModel childViewModel) | ||
{ | ||
this.ChildViewModel = childViewModel; | ||
} | ||
|
||
public override Task Init() | ||
{ | ||
if (Context is null) | ||
{ | ||
throw new Exception($"{nameof(Context)} is null in {nameof(Init)} method of {nameof(ParentViewModel)}."); | ||
} | ||
|
||
return base.Init(); | ||
} | ||
|
||
public override Task Load() | ||
{ | ||
if (Context is null) | ||
{ | ||
throw new Exception($"{nameof(Context)} is null in {nameof(Load)} method of {nameof(ParentViewModel)}."); | ||
} | ||
|
||
return base.Load(); | ||
} | ||
|
||
public void DoSomething() | ||
{ | ||
Result = true; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Samples/Common/ViewModels/ComplexSamples/ViewModelPopulate/ViewModelPopulateViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.ViewModel; | ||
|
||
namespace DotVVM.Samples.Common.ViewModels.ComplexSamples.ViewModelPopulate | ||
{ | ||
public class ViewModelPopulateViewModel : DotvvmViewModelBase | ||
{ | ||
|
||
public NonDeserializableObject NonDeserializableObject { get; set; } = new(1, ""); | ||
|
||
|
||
public void DoSomething() | ||
{ | ||
NonDeserializableObject.Test = NonDeserializableObject.Test + "success"; | ||
} | ||
} | ||
|
||
public class NonDeserializableObject | ||
{ | ||
|
||
public string Test { get; set; } | ||
|
||
public NonDeserializableObject(int nonPropertyField, string test) | ||
{ | ||
|
||
} | ||
} | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
src/Samples/Common/Views/ComplexSamples/ViewModelDependencyInjection/Sample.dothtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@viewModel DotVVM.Samples.Common.ViewModels.ComplexSamples.ViewModelDependencyInjection.ParentViewModel, DotVVM.Samples.Common | ||
|
||
<!DOCTYPE html> | ||
|
||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>ViewModel Dependency Injection</title> | ||
</head> | ||
<body> | ||
<p> | ||
<dot:LinkButton Text="Call command" | ||
Click="{command: DoSomething()}" | ||
data-ui="command" /> | ||
</p> | ||
<p class="result">{{value: Result}}</p> | ||
</body> | ||
</html> |
19 changes: 19 additions & 0 deletions
19
src/Samples/Common/Views/ComplexSamples/ViewModelPopulate/ViewModelPopulate.dothtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@viewModel DotVVM.Samples.Common.ViewModels.ComplexSamples.ViewModelPopulate.ViewModelPopulateViewModel, DotVVM.Samples.Common | ||
|
||
<!DOCTYPE html> | ||
|
||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
|
||
<dot:TextBox Text="{value: NonDeserializableObject.Test}" /> | ||
|
||
<dot:Button Text="Test" Click="{command: DoSomething()}" /> | ||
|
||
</body> | ||
</html> | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/Samples/Tests/Tests/Complex/ViewModelDependencyInjectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotVVM.Samples.Tests.Base; | ||
using DotVVM.Testing.Abstractions; | ||
using Riganti.Selenium.Core; | ||
using Riganti.Selenium.DotVVM; | ||
using Xunit; | ||
|
||
namespace DotVVM.Samples.Tests.Complex | ||
{ | ||
public class ViewModelDependencyInjectionTests : AppSeleniumTest | ||
{ | ||
public ViewModelDependencyInjectionTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void Complex_ViewModelDependencyInjection_Sample() | ||
{ | ||
RunInAllBrowsers(browser => { | ||
browser.NavigateToUrl(SamplesRouteUrls.ComplexSamples_ViewModelDependencyInjection_Sample); | ||
|
||
browser.Single("a").Click(); | ||
AssertUI.TextEquals(browser.Single(".result"), "true"); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.