I used Fluxor for state management in in one of the razor components in my Blazor app and I'm not really sure how to set it up for testing with Moq. I can't just assing a value to students because it's an init only property. Is there a specific way to set up Fluxor for testing?
code
var teacherService = new Mock<ITeacherService>();
var localStorage = new Mock<ILocalStorageService>();
var studentService = new Mock<IStudentService>();
var toastService = new Mock<IToastService>();
var NavigationManager = new Mock<NavigationManager>();
var Dispatcher = new Mock<IDispatcher>();
var actionSubscriber = new Mock<IActionSubscriber>();
var StudentsState = new Mock<IState<StudentsState>>();
var TeacherState = new Mock<IState<TeacherState>>();
// Help here
StudentsState.Setup(t => t.Value.Students = )
I was stuck on this for quite a while, but went looking through Fluxor's glitter community and found something that might help! I understand that you'd like to test using Moq, but perhaps what I found might be easier/suit your purposes for testing Fluxor components!
Instead of using Moq, I followed this format and managed to get something working:
Test.cs
In the constructor, we create a service collection and add Fluxor (just like you would to your Startup.cs), then scan for assemblies.
In my code above, I scanned for the Reducers and the State. Please refer to my directory structure here (you'll get an idea of how I decided what to include).
Actions.cs
Reducers.cs (scanned in the constructor)
InhousePetOwnerState.cs (scanned in the constructor)
What this solution does is it allows you to inject all your Fluxor states, actions and reducers, enabling you to call them as you normally would - I've found it pretty easy to test this way!