-
-
Notifications
You must be signed in to change notification settings - Fork 408
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 #3669 from russblair/v7.x
Fixes Blazor ViewModel Save doesn't call begin edit after save.
- Loading branch information
Showing
5 changed files
with
113 additions
and
15 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
79 changes: 79 additions & 0 deletions
79
Source/Csla.Blazor.Test/ViewModelEditChildListSaveEditLevelTests.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,79 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Csla.Blazor.Test.Fakes; | ||
using Microsoft.AspNetCore.Components.Forms; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using Csla.TestHelpers; | ||
using System.Threading.Tasks; | ||
using Csla.Core; | ||
|
||
namespace Csla.Blazor.Test | ||
{ | ||
[TestClass] | ||
public class ViewModelEditChildListSaveEditLevelTests | ||
{ | ||
private static TestDIContext _testDIContext; | ||
|
||
[ClassInitialize] | ||
public static void ClassInitialize(TestContext context) | ||
{ | ||
_testDIContext = TestDIContextFactory.CreateDefaultContext(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task SaveModelChildListChange_ValidateEditLevel() | ||
{ | ||
// Arrange | ||
FakePerson person = GetValidFakePerson(); | ||
//EditContext editContext = new EditContext(person); | ||
//editContext.AddCslaValidation(); | ||
var iuo = person as IUndoableObject; | ||
var appCntxt = TestDIContextExtensions.CreateTestApplicationContext(_testDIContext); | ||
var vm = new ViewModel<FakePerson>(appCntxt); | ||
vm.ManageObjectLifetime = true; | ||
vm.Model = person; | ||
|
||
Assert.IsTrue(iuo.EditLevel > 0); | ||
await vm.SaveAsync(); | ||
Assert.IsTrue(iuo.EditLevel == 1); | ||
|
||
// Act | ||
var eaddr = person.EmailAddresses.AddNew(); | ||
eaddr.EmailAddress = "[email protected]"; | ||
Assert.IsTrue(iuo.EditLevel > 0); | ||
await vm.SaveAsync(); | ||
|
||
// Assert | ||
Assert.IsTrue(iuo.EditLevel == 1); | ||
|
||
} | ||
|
||
#region Helper Methods | ||
|
||
FakePerson GetValidFakePerson() | ||
{ | ||
IDataPortal<FakePerson> dataPortal; | ||
FakePerson person; | ||
|
||
// Create an instance of a DataPortal that can be used for instantiating objects | ||
dataPortal = _testDIContext.CreateDataPortal<FakePerson>(); | ||
person = dataPortal.Create(); | ||
|
||
person.FirstName = "John"; | ||
person.LastName = "Smith"; | ||
person.HomeTelephone = "01234 567890"; | ||
|
||
return person; | ||
} | ||
|
||
private string ConcatenateMessages(IEnumerable<string> messages) | ||
{ | ||
return string.Join("; ", messages); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
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