locked
Validation, Service Layers and testing RRS feed

  • Question

  • User-265234229 posted

    Hello,


    I have a quick question in regards to testing my validation. I have been looking through a few MVC examples and have noticed the 'Validating with a Service Layer' tutorial which is pretty nice. It discusses how to abstract your code out etc..

    My question is, that they have validation occuring in the service layer, if errors occur, the error + message then gets added to a model state dictionary.

    Now i want to test my model to make sure my business rules are being applied to it, but with this approach, for starters, the Validation method is not in the interface. Now, if the validation method was in the interface, during testing you would have to re-implement the validation on the testing side.

    Am i missing somthing? Where should your validation code go? I feel like it should go in the model, but then i have to track the errors on the model side.


    Any common practices to this?

    Thursday, December 23, 2010 11:29 AM

Answers

  • User197322208 posted

    Now, if the validation method was in the interface, during testing you would have to re-implement the validation on the testing side.

    Right. Let's say you raise an error if the birthdate is in the future( 2019). In the test, you will put the birthdate in DateTime.Now.Year +1 and expect the error.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 23, 2010 12:55 PM