c# - How do you stub IQueryable<T>.Where(Func<T, bool>) with Rhino Mocks? -
In the .NET 3.5 project, I was writing a few tests for a service class.
Public Class Service Class: IServiceClass {Private Readonly IRPository _Repository; Public service class (erupository repository) {_repository = repository; } # Field ISARCLSS member public INIMMerelabel & lt; Action type & gt; GetAvailableActions () {IQueryable & lt; ActionType & gt; Type the action = _repository.Query & lt; ActionType & gt; (); Type the return action. Where (x = & gt; x.Name == "debug"). AsEnumerable (); } #endregion} And I find a difficult time stub or
actionTypeQuery.Where (how to ridicule X = & gt; ; X. Name == "debug") part
What have I found so far :.
[TestFixture] Public class ServiceClassTester {Private serviceclass _ service; Private irrepository; Private IQueryable & lt; ActionType & gt; _actionQuery; [Set up] Public zero setup () {_repository = MockRepository.GenerateMock & lt; IRepository & gt; (); _service = new service class (_pozaspery); } [Test] Public Zero heres_a_test () {_actionQuery = MockRepository.GenerateStub & lt; IQueryable & lt; ActionType & gt; & Gt; (); _repository.Expect (x = & gt; x.Query & lt; ActionType & gt; ()). Return (_actionQuery); _actionQuery.Expect (x = & gt; x.Where (y = & gt; y.Name == "debug")). Return (_actionQuery); _service.GetAvailableActions (); _repository.VerifyAllExpectations (); _actionQuery.VerifyAllExpectations (); }} [note: the name of the class has been changed to protect it]
but this is a System.NullReferenceException But failed with
_actionQuery.Expect (x = & gt; x.Where (y = & gt; y.Name == "debug")). Return (_actionQuery); So my question is:
How do I duplicate or pass the IQueryable.Where function stub with RhinoMocks and get this test
< P> My current setup will not allow me to duplicate or stub IQueryable, so a logic explanation why this epic thanks for reading the long-standing question.
I initially wanted to call calls like 'IQueryable.Where (Func)', but I It seems that it is testing at the wrong level. Instead of making fun of IQueryable in my tests, I then check the result:
// Set a dummy list, which will be filtered, queried, etc. Various panelists = new list & lt; ActionType & gt; () {New action type () {name = "debug"}, new action type () {name = "other"}}; _repository.Expect (x = & gt; x.Query & lt; ActionType & gt; ()). Return (action list); Var result = _service.GetAvailableActions (). ToList (); // Check the logic of GetAvailableActions gives the list of correct subtitles // action, etc.: assurance. That (the result is length, is.EqualTo (1)); Responsibility (Results [0], I.Aquilito (action list [0]); _pozami.verify all projection ();