locked
Cannot access ListView.SelectedItems in UITestMethod UnitTest RRS feed

  • Question

  • Hi,

    I created a UnitTest for a UWP Value Converter.

    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();
    }
    }

    This is the Unit Test:

    [UITestMethod] // NOT WORKING
    [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"));
    }

    When I hover over the <results> variable, Intellisense shows me a System._COMObject type. I cannot cast the result of the converter to IList<object>, although the ListView.SelectedItems property which is returned by the value converter is of type IList<object>. I get a System._COMObject as a result. I also get a "Information not available, no symbols loaded for Windows.UI.Xaml.dll" message. This crashes my test. What can I do ?

    Thank you.

    • Moved by Barry Wang Thursday, May 19, 2016 7:19 AM
    Wednesday, May 18, 2016 9:04 AM

All replies

  • Hello,

    As the issue is more related to Unit Testing, I'm moving your case to a better forum.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 19, 2016 7:20 AM
  • Hi octavian_epure,

    >>[UITestMethod] // NOT WORKING

    You would add:

    using

    Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AppContainer;

    Sorry for that I couldn't repro this issue, it seems that there are some issue with this line code in my side for "converter":

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

    Could you share me a simple sample using one drive? So I could really repro this issue using the same sample as yours.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 20, 2016 10:20 AM
  • Sorry it took so long to reply - the unit test was considered "overkill" and was removed. But if you still want to test the issue, the "converter" variable was initiazlized in a [TestInitialize] type method, where it was initialized like this:

        var converter = new MultipleSelectionChangedConverter();

    Thanks.

    Tuesday, June 7, 2016 10:36 AM
  • Hi octavian_epure,

    Thank you for your question, I'm doing research on this case, it might take some time before we get back to you. I will update my reply later.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 8, 2016 11:26 AM