简体   繁体   中英

UWP ValueConverter returns System._COMObject

I'm creating unit tests for a UWP (Windows 10) project. I'm testing a Value Converter. The converter should return, if all is OK, the SelectedItems property of a ListView control. This is the converter:

internal class MultipleSelectionChangedConverter : IValueConverter
{
  public object Convert(object value, Type targetType, object parameter, string language)
  {
    var listView = parameter as ListView;

    if (listView != null)
       return listView.SelectedItems;

    return new ListView();
  }

  public object ConvertBack(object value, Type targetType, object parameter, string language)
  {
    throw new NotImplementedException();
  }
}

I'm trying to check the results in this Unit test:

[UITestMethod] 
[TestCategory("Multiple Selection Changed Converter")]
public void ShouldSetSelectedItems()
{
  IList<object> results = null;

  var listToSetSelectedItems = new ListView
  {
    ItemsSource = new List<string> { "item 1", "item 2", "item 3", "item 4"     },
    SelectionMode = ListViewSelectionMode.Multiple,
  };
  listToSetSelectedItems.SelectedItems.Add("item 1");
  listToSetSelectedItems.SelectedItems.Add("item 2");

  results = (IList<object>)converter.Convert(null, typeof(IList<object>), listToSetSelectedItems, string.Empty);

  Assert.IsTrue(results != null);
  Assert.IsTrue(results.Count == 2);
  //Assert.IsTrue(results.Contains("item 1"));
  //Assert.IsTrue(results.Contains("item 2"));
}

The variable should contain the SelectedItems property, which is of type IList. Instead, it comes back set with a System._COMObjects value. Also, I get an "Information not available, no symbols loaded for Windows.UI.Xaml.dll" message. What can I do to get the correct type for the SelectedItems property ?

Thanks

In this part of your code

var listView = parameter as ListView;

    if (listView != null)
       return listView.SelectedItems;

    return new ListView();

you are returning list of selected items when listview is not null. however when it is null you are returning a new listview itself. Don't you think return type should be same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM