Testing ActionFilterAttributes with MSpec

I am currently trying to understand MSpec, mainly to learn new ways (T / B) DD to be able to make an informed decision about which technology to use. Previously, I mainly (read-only) used the built-in MSTest environment with Moq, so BDD is completely new to me.

I am writing an ASP.NET MVC application and I want to implement PRG . The last time I did this, I used action filters to export and import ModelStatethrough TempData, so that I could return RedirectResult, and the validation errors would still be there when the user got the view. I tested this scenario by checking two things:

a) I used the ExportModelStateAttribute file that I wrote (among the tests for my controller)
b) That the attribute worked (among the tests of the action filter attributes)

However, in BDD, I realized that I was more worried about behavior, and even more so about implementation. This means that I should probably just check that the state of the model is in tempdata when the action has completed execution - it is not necessary that this happens through an attribute.

To complicate matters even further, attributes are not triggered when the action is called directly in the test, so I cannot just call the action and see if the task is completed.

How do I specify / test this in MSpec?

+5
source share
1

, , ( ).

( temp), ( , , ?).

: ASP.NET MVC , . PRG , PRG ( ). , , , .

+1

All Articles