2

I have the following expression

 private IObservable<Point> GetLeftMouseDown()
    {
        return from pattern in Observable.FromEventPattern<MouseButtonEventArgs>(_element, "MouseDown")
            where pattern.EventArgs.ChangedButton == MouseButton.Left
            select pattern.EventArgs.GetPosition(_element);
    }

Is possible to mock source of events for tests? What I should do with GetPositionMethod which calls system functions and it isn't virtual?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38

1 Answers1

1

You don't need to test your GetLeftMouseButtonDown function in a unit test. What are you actually testing? You're testing Linq, Rx, and the EventArgs object, none of which you wrote. I'd probably write a quick interactive integration style test that ensures I am in fact getting the left button clicks, and call it good.

What you want to do in testing is to pass in an IObservable<Point> into the method under test. You can then pass in an IObservable that you can put values into. I'd probably just use a Subject object, no need to write your own mock implementation.

Then shoot whatever stream of values into it you want to test against, and observe the results in your tests.

Chris Tavares
  • 29,165
  • 4
  • 46
  • 63