Skip to content

Commit

Permalink
Merge pull request #153 from mikaelliljedahl/master
Browse files Browse the repository at this point in the history
#149 Add JArray check to VMSerializer.
  • Loading branch information
dsuryd authored Nov 26, 2018
2 parents 388b6e2 + 127427a commit 189b97b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DotNetifyLib.Core/BaseVM/VMSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public string Serialize(object viewModel, List<string> ignoredPropertyNames)
{
try
{
if (viewModel is string || !viewModel.GetType().GetTypeInfo().IsClass)
if (viewModel is string || viewModel is JArray || !viewModel.GetType().GetTypeInfo().IsClass)
return Convert.ToString(viewModel);

var serializer = new JsonSerializer() { ContractResolver = new VMContractResolver(ignoredPropertyNames) };
Expand Down
37 changes: 34 additions & 3 deletions UnitTests/SimpleListVMTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public int Add(EmployeeRecord record)

public void Update(EmployeeRecord record) => _employeeRecords[record.Id] = record;
public void Delete(int id) => _employeeRecords.Remove(id);
}

public void DeleteMany(List<int> ids) => ids.ForEach(id => _employeeRecords.Remove(id));
}

private class SimpleListVM : BaseVM
{
Expand Down Expand Up @@ -105,7 +107,18 @@ public class EmployeeInfo
ShowNotification = true;
};

private bool _showNotification;

public Action<int[]> RemoveMany => ids =>
{
_employeeService.DeleteMany(ids.ToList());
foreach(var id in ids)
{
this.RemoveList(nameof(Employees), id);
}
ShowNotification = true;
};

private bool _showNotification;
public bool ShowNotification
{
get
Expand Down Expand Up @@ -202,7 +215,25 @@ public void SimpleListVM_Delete()
Assert.IsFalse(employees.Exists(i => i.Id == 2));
}

[TestMethod]
[TestMethod]
public void SimpleListVM_DeleteMany()
{
var vmController = new MockVMController<SimpleListVM>(_simpleListVM);
var vmEmployees = vmController.RequestVM();

var employees = _employeeService.GetAll();
Assert.AreEqual(3, employees.Count);
Assert.IsTrue(employees.Exists(i => i.Id == 2));

vmController.UpdateVM(new Dictionary<string, object>() { { "RemoveMany", "[1,2]" } });

employees = _employeeService.GetAll();
Assert.AreEqual(1, employees.Count);
Assert.IsFalse(employees.Exists(i => i.Id == 2));
Assert.IsFalse(employees.Exists(i => i.Id == 1));
}

[TestMethod]
public void SimpleListVM_ShowNotification()
{
var vmController = new MockVMController<SimpleListVM>(_simpleListVM);
Expand Down

0 comments on commit 189b97b

Please sign in to comment.