Reputation: 1
I have a simple action in the list view of my XAF application. The action's active (true/false) state is determined by the current view ID. I am trying to write a unit test for this action, but I am unable to create a mock view of my list view (e.g., "Employee_Custom_ListView"). How can I create a view for a given list view ID in a unit test?
Here is my code.
public partial class EmployeeListViewActionController : ViewController
{
private SimpleAction EmpAction;
public EmployeeListViewActionController()
{
InitializeComponent();
TargetObjectType = typeof(Employee);
{
EmpAction = new SimpleAction(this, "EmpAction", PredefinedCategory.Edit)
{
Caption = "EmpAction",
SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects,
TargetViewType = ViewType.Any
};
EmpAction.Execute += EmpAction\_Execute;
}
}
protected override void OnActivated()
{
base.OnActivated();
ManageActionVisibility();
}
public void ManageActionVisibility()
{
if(View.Id == "Employee\_Custom\_ListView")
{
EmpAction.Active.SetItemValue("Action", true);
}
else if(View.Id == "Employee\_ListView")
{
EmpAction.Active.SetItemValue("Action", false);
}
else
{
// Other logic.
}
}
private void EmpAction\_Execute(object sender, SimpleActionExecuteEventArgs e)
{
// Implementation..
}
protected override void OnDeactivated()
{
EmpAction.Active..Clear();
base.OnDeactivated();
}
I am Using Mock to create ListView , So How can I create a view for a given list view ID in a unit test by using Mock.
I have created a mockview like below
var mockView = new Mock<View>(/*isRoot:*/true);
mockView.Setup(v =>v.ObjectSpace).Returns(objectSpaceMock.Object);
var controller = new controller();
controller.SetView(mockView.Object);
but in this case mockview created has null value as id. tried to give id like this
controller.TargetViewId = "Employee_Custom_ListView";
but still the view id null
Any help would be appreciated.
Upvotes: 0
Views: 23