TDD: Testing with Stub Methods

Please see my other Test Driven Development articles. Adding flexibility to return values using Stub methods. Continuing on my “Testing with Dummy objects” article, you might have noticed a limitation with regards to the return value – only one was allowed. In situations where multiple return values are needed, Stub methods provide an alternative. In…

TDD: Refactoring with Polymorphism

Please see my other Test Driven Development articles. Using polymorphism to refactor SRP violations. Single Responsibility Principle (SRP) violations are one of the most common issues found in code. Either the class or its behavior is attempting to fulfill more than one primary purpose. In this example, I will illustrate how polymorphism provides a powerful…

TDD: Mocking with Dummy Objects

Please see my other Test Driven Development articles. Using custom objects in place of a mocking framework. When it’s desired to avoid the overhead of a mocking framework and its functionality isn’t required, developers may elect to provide their own dummy objects instead. In this article I will illustrate a simple example of writing my…

TDD: Assets

Please see my other Test Driven Development articles. Leveraging overloaded Assert() methods to enhance test methods. Continuing from my TDD: Mocking with Dummy objects article, I wanted to illustrate some examples of other Assert() methods available for use to enhance testing results. As illustrated in my last example, you may just utilize the traditional Assert.AreEqual()…

MVC: Validation – Remote

Please see my other MVC articles. Using the Remote attribute to leverage JQuery’s validator. MVC provides a flexible and powerful method for using logic external to the Model for enforcing business rules – the Remote attribute. In this article, I will illustrate how to use an action method from a Controller to validate a Model’s…

MVC: Validation – Model

Please see my other MVC articles. Enforcing Model-level validation. MVC enables validation to be performed at the model-level by implementing the IValidatableObject interface. Once you’ve defined Validate(), your routines then may perform custom validation using the Model’s properties. To illustrate this feature, I’ll implement a routine to ensure the territory entered is one of the…

MVC: Validation

Please see my other MVC articles. Utilizing validation in the model to enforce business rules. In this article, I will illustrate some of the basic validation types available to ensure business rules for data are enforced. Since MVC provides this capability within the Model, separation of concerns are maintained by keeping this logic out of…

MVC: Using ViewBag for Data Storage

Please see my other MVC articles. Passing data to a View. Sometimes a business requirement necessitates data to passed from a Controller to the View for displaying to the user. One method MVC provides is the object ViewBag which allows you to easily attach inference-typed variables for initialing with many types of data. To illustrate…

MVC: User Context Info

Please see my other MVC articles. Using context objects to discern user information. This article illustrate how easy ASP.NET MVC allows access to a wealth of user information. Notice from my code, I simply access just a few object to retrieve almost everything about the user. Here are the results of my code, showing my…

MVC: Regular Expressions

Please see my other MVC articles. Enforcing valid formats on user input. Most user-input forms’ business rules indicate specific formats for the data they receive. MVC enables developers to enforce those rules very easily by using regular expression within their custom models. To illustrate this feature, I will begin with a simple Create form. As…