rafanoronha.speaking()

software development stuff

Archive for June, 2009

(Portuguese) Controller, mas nem tanto

without comments

Sorry, this entry is only available in Portuguese.

Written by rafanoronha

June 29th, 2009 at 2:01 am

Posted in Sem categoria

Tagged with ,

(Portuguese) Scrum não menciona engenharia. E daí?

with 2 comments

Sorry, this entry is only available in Portuguese.

Written by rafanoronha

June 21st, 2009 at 2:05 pm

Posted in Sem categoria

Tagged with ,

(Portuguese) Novos objetivos

with 4 comments

Sorry, this entry is only available in Portuguese.

Written by rafanoronha

June 15th, 2009 at 8:32 am

Posted in Sem categoria

Model validation specifications

without comments

Recently I designed an API concerned with model validation specifications.

The idea was to provide specifications for the design of my model objects.
The resulting code will show you how it works:


        [TestInitialize]
        public void setup()
        {
            ModelSpecifications.StartSpecificationsFor<User>();
        }

        [TestMethod]
        public void should_have_an_unique_name_with_min_lenght_of_2_and_max_length_of_20()
        {
            "Name"
                .NotNullOrEmpty()
                .Length(2, 20)
                .Unique();
        }

        [TestMethod]
        public void should_have_an_unique_email_correctly_formatted()
        {
            "Email"
                .NotNullOrEmpty()
                .EmailFormatting()
                .Unique();
        }

The API is ensuring, under reflection, that the specified model type has the called validations correctly declared (the validation is performed upon attributes usage).

Note that performing validations on top of the attributes is not this API concern.

The underlying code is pretty simple.
ValidationEnsurer is the object who ensures the specified validations.
It asks the type under specification for validation attributes matching the specified validations.

The fluent interface is obtained with string extension methods.
These methods encapsulates callings to ValidationEnsurer and to my testing infrastructure:


public static string NotNullOrEmpty(this string propertyName)
{
            var isValidating = new ValidationEnsurer(ModelSpecifications.TypeUnderSpec)
                .IsValidating(new NotNullNotEmptyAttribute(), propertyName);

            Assert.IsTrue(isValidating);

            return propertyName;
}

Now I can ensure in my testing/specification fixtures the correct behavior for the validation of my model objects.

Maybe this could be helpful, so here is a demo project that you can use, customizing your own underlying code: source code.

Written by rafanoronha

June 8th, 2009 at 8:56 pm

Posted in Sem categoria

Tagged with ,

(Portuguese) Building Domain Specific Languages in Boo – Review

without comments

Sorry, this entry is only available in Portuguese.

Written by rafanoronha

June 4th, 2009 at 4:06 pm

Posted in Sem categoria

Tagged with