Conditional mock data(Moq) with Bunit

375 Views Asked by At

I have a conditional mock data with moq like this where it returns different data based on if the parameter is null or not.

 locationMock
    .Setup(x => x.GetAllLocations(It.IsAny<SearchRequest>()))
    .Returns((SearchRequest req) =>
        {
            return req.SearchText == null
                ? thread
                : filteredThread;
        });

I register the service like this Services.AddSingleton(locationMock.Object);

I then have an input box where I input "TEST LOCATION" and click search icon which should filter the data AKA return the "filteredThread". When I debug through it, I can see it hit the different conditions. However, the data that is returned is always "thread" which does not contain the filtered data but the original data.

I'm wondering what I'm doing wrong or if there is something I can do to achieve the conditional return of data showing up in bunit.

var cut = RenderComponent<LocationList>();
var instance = cut.Instance;
instance.use = UseMode.None;
instance.Locations = locationData;

cut.Render();

cut.Find(".prompt.input-box").Input("TEST LOCATION");            
cut.Find(".search-icon").Click();

cut.Render();
var bob = cut.FindAll("table > tbody > tr");
cut.WaitForState(() => cut.FindAll("table > tbody > tr").Count == 1, TimeSpan.FromSeconds(15));
0

There are 0 best solutions below