The Rain and The Shade

August 3, 2011

Something beautiful while using AutoFixture

Filed under: Unit Testing — ovaisakhter @ 5:39 pm

In one of the projects I have the following class

public class SiteSurveyConfiguration : Entity
    {       
        public string CustomerName { get; set; }

        public string Website { get; set; }

        public string ShortDescriptionOnPopup { get; set; }

        public string HeadlineOnPopup { get; set; }

        public string LabelOfButtonOnPopup { get; set; }

        public int PercentOfUserWhoWillSeePopup { get; set; }

        public string CustomerLogoImageUrl { get; set; }

        public int ClicksByUserBeforePopShown { get; set; }

        public string ColorOfHeadline { get; set; }

        public string ColorOfShortText { get; set; }

        public string ColorOfButton { get; set; }

        public string FontOfPopup { get; set; }

        public int WidthOfPopup { get; set; }

        public int HeightOfPopup { get; set; }

        public bool ShowPopupInIFrame { get; set; }       
    }

While unit testing I needed to create a list containing 10 instances of this class along with different random data in each field.

var ListOfConfigurations = new List<SiteSurveyConfiguration>();
          var fixture = new Fixture();
          fixture.AddManyTo(ListOfConfigurations,10);

So this code created 10 instances of my class, added data to each field and added these instances to my list. I almost had tears of joy in my eyes Smile.

you can get more information about AutoFixture from http://autofixture.codeplex.com/

 

 

Advertisements

1 Comment »

  1. Its awesome.

    Comment by devbridge — August 4, 2011 @ 9:25 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: