Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 149 #153

Merged
merged 1 commit into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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