Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:14:42+00:00 2026-06-17T08:14:42+00:00

I am using Rx and RxUI in a MVVM project and have a view

  • 0

I am using Rx and RxUI in a MVVM project and have a view model that queries its data from a WCF service asynchronously. In the unit tests I create a mock object that returns a Task with the expected value.

Here’s a general idea of what my view model looks like

public class ViewModel : ReactiveObject
{
    private IContext _context;

    public ViewModel(IContext context)
    {
        _context = context;

        Observable.FromAsync(() => _context.WcfServiceCall())
              .Subscribe(result => {
                   Children.AddRange(results.Select(r => new ChildViewModel(r).ToList()));
               });
     }

     public ObservableCollection<ChildViewModel> { get; private set;}
}

My unit test looks like this

[TestFixture]
public class ViewModelTest : AssertionHelper
{
    [Test]
    public void ShouldSetChildren()
    {
        var c = new Mock<IContext>();
        c.Setup(q => q.WcfServiceCall())
            .Returns(Task.Run(() => new []{ 1,2,3,4,5,6 })):

        var vm = new ViewModel(c.Object);
        var p = vm.Children.First(); // this call sometimes fails

        ... 
     }
}

The issue I’m having is that I have over 400 tests that do this sort of thing and they all work most of the time but I randomly get failed tests, one or two at a time, that report the sequence has no values. This is unpredictable and random. I can run the tests again after a failure and all succeed. I have added the TestScheduler as described here but the problems persist.

Is there a better way to test methods that make asynchronous method calls?

Edit from Paul Bett’s input:
I see FromAsync does not take an IScheduler parameter but I do have SubscribeOn and ObserveOn available.

Alternatively, I could call the WCF async method directly and convert the returned Task to an observable. I’m not sure I understand when it is more appropriate to use Observable.FromAsync versus not using it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:14:43+00:00Added an answer on June 17, 2026 at 8:14 am

    Does Observable.FromAsync take an IScheduler parameter? Is it your Test Scheduler?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the Word Interop API I have a document from which I remove text
Using SSRS 2008 R2 I have a background process that dynamically generates RDL for
Using CRM 4, I have an entity form that contains a tab with an
Using myObject.performClick() I can simulate click event from the code. Does something like this
using an interface (abstract class) on c++ i have the need to force any
Using RIDE, I want to connect to MySQL Database. I have downloaded the DatabaseLibrary
Using SolrNet for querying & faceting. I have a combination of int, tdate and
Using NLTK and WordNet , how do I convert simple tense verb into its
Using jQuery, how do I get the value from a textbox and then load
using MSQL 2005 I have a continuous set of flow measurements (averaged for each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.