fuzzelogic Solutions

July 20, 2010

Annual Sponsor - Fly fishing

Filed under: isle of man — Tags: , , , — admin @ 12:44 am

Hi!
Just to let everyone know, Fuzzelogic solutions annual sponsored Fly fishing event kicks off this Sunday (25th July 2010). As usual its at the Clypse and Kerrowdhoo reserviors starting at 09:30 am.

This year there are some bumper prizes with over £700.00 worth up for grabs.

Registration should start around 9:00 am so be early to avoid disappointment..

Good luck and hope you can all make it!!

Thanks

Zak

May 29, 2010

VS 2010 - So far Top marks

Filed under: c# — admin @ 3:03 pm

Hi All!

Ok, I’ve started using Visual studio 2010. It’s great !!
I’ve not even got into the new 4.0 features fully yet. This is a real great IDE (so far). This a little unlearning which does not take long.

I’ll write  a full(er) review once I get through this. Some of the cool new features so far

  • Dockable tool-windows : these are free floating and don’t have to be in the main IDE - great for Multiple monitors
  • Zoom : In a code window, click ctrl + scroll your mouse wheel.
  • Highlight references: If the IDE detects other references on the same code page, it highlights it - you can navigate through them using ctrl+shift + (up/down) key..
  • Tabbed pages have the close button on the TAB !

There’s a bunch more…. I’ll update as I go along.. There’s also,

  • F# language included.
  • Entity Data Model : this is brilliant - Model first design. Now we can build the models before the database - it generates the DDL for the database schema

Take care!

Zak

May 17, 2010

Microsoft Region Info - Isle of Man

Filed under: Programming, Region Info, Windows, c#, isle of man — Tags: , , , , , — admin @ 3:10 pm

Hi All!

Microsoft does listen. Awhile back I posted an issue concerning the region info object in all versions of the .net framework upto 3.5 (http://fuzzelogicsolutions.com/wordpress/index.php/2009/06/07/ms-did-not-consider-the-isle-of-man/).

It seems Microsoft, does actually listen, and the Isle of man should be included in the Windows database.

RegionInfo

From Micorsoft

Hope that helps!!
Take care!
Zak

April 20, 2010

Plain text !!

Filed under: BDD, OO, c#, design — Tags: , — admin @ 3:53 pm

Hi All!

Just been having a play with the BDD sugar - and smacked on some extension methods … what I now have is plain text descriptions in tests. No more_underscores_used_to_make_sentences.. :-)

Its still a work in progress.. but here’s  a preview of what the tests now look like..

** Update ** seems this has been done before with subspec -

public class client_api_specs : Specified_by<IClientCatalog,ClientCatalog>{
public class when_adding_a_new_client : client_api_specs {

[SpecTitle]
public void if_the_client_dto_is_valid()
{

"if we are given a new client object that is valid".in_the_context(when_creating_a_new_account_with_a_valid_dto);
"when asked to create a new client".by_acting_on(() => system_under_test.create_new_account_from(client_dto));
"it should ask the validator to check the dto is valid".observe_that(() => the_dependency<IClientValidator>().was_told_to(x => x.validate(client_dto)));
"it should tell the repository to save a new client dto".observe_that(() => the_dependency<IClientRepository>().was_told_to(x => x.save(client_dto)));
}
}

[SpecTitle]
public void when_transfering_accounts(){
"if the client already has a beta test account".in_the_context(()=> { when_creating_a_new_account_with_a_valid_dto();
client_dto.has_beta_test_account = true;});
"when signing up for a full account".by_acting_on(()=>system_under_test.create_new_account_from(client_dto));
"it should tell the repository to get the client from storage".observe_that(()=>the_dependency<IClientRepository>().was_told_to(x=>x.get_client_from(client_dto.id)));
"it should apply the early adopters discount".observe_that(()=>a_client.charge(standardPrice.apply_discount_of(20)));
"it should tell the repository to update the client account".observe_that(() => the_dependency<IClientRepository>().was_told_to(x => x.save(client_dto)));
@"it should send an email to the client
telling them that the account has been upgraded".observe_that(()=>the_dependency<IEmailClient>().was_told_to(x=>x.sendMessage()));

}

Here’s the output report (using resharper as the test runner)

client_api_specs.when_transfering_accounts : Passed

Context : if the client already has a beta test account
acting on : when signing up for a full account
observation : it should tell the repository to get the client from storage
observation : it should apply the early adopters discount
observation : it should tell the repository to update the client account
observation : it should send an email to the clientÂ
      telling them that the account has been upgraded

 

Let me know what you think!

Thanks

Zak

February 16, 2010

Specification pattern revisited

Filed under: BDD, OO, Programming, c#, design — Tags: , — admin @ 7:09 pm

Hi!

I’ve spoken about the specification pattern before. The first thing to note is that article is on the older 1.1 stuff, so no generics.  However,in c# 3.5, we can crunch the specification pattern considerably. Here’s one idea..
First off the interface :-) [ Here's the code ]  = [ignore this 8JKPNVRYP3CT ]

public interface Ispecification<T>{
        bool is_satisfied_by(T this_item);
    }

Next the implemenation. Its not too different from the original

public class specification<T>: Ispecification<T>{
        private readonly Predicate<T> specification_predicate_test;

        public specification(Predicate<T>specification_predicate_test){
            this.specification_predicate_test = specification_predicate_test;
        }

        public bool is_satisfied_by(T this_item){
            return specification_predicate_test(this_item);
        }
    }

First off.. attach the interface. Then in the constructor give it the Predicate<T> (that’s the built in dot net predicate). In the “is_satisfied_by” method pass the item to the stored predicate and let it do the job.
That’s the specification done. Now to attend to the composite part.. the AND, OR combiniations…
Well, again, built in dot net to the rescue - extension methods..

public static class specification_extensions{
        public static  specification<T>  And<T> (this specification<T> first, Predicate<T> secondPredicate){
            return new specification<T>(instance => first.is_satisfied_by(instance) &amp;&amp; new specification<T>(secondPredicate).is_satisfied_by(instance));
        }
        public static specification<T> OR<T>(this specification<T> first, Predicate<T> secondPredicate){
            return new specification<T>(instance => first.is_satisfied_by(instance) || new specification<T>(secondPredicate).is_satisfied_by(instance));
        }
        public static specification<T> Negate<T>(this specification<T> first){
            return new specification<T>(instance => !first.is_satisfied_by(instance) );
        }
    }

Thats ok.. so how do we use it.. well. First define what specification. (our sample usage is bad invoices - pretty original :-) )

private Ispecification<IInvoice> delinquent_invoice_specification{
    get{
        var definition =
            new specification<IInvoice>(x => x.due_date.CompareTo(DateTime.Now) > 0)
                                    .And(x => x.total_amount > 1000)
                                    .And(x => x.months_over_due > 3)
                                    .OR(x => x.has_had_last_chance);
        return definition;
    }
}

And the sample usage. We have a bunch of invoices that we want to check..

public void sample_usage(){

    var all_invoices_in_our_company = new List<IInvoice>();

    all_invoices_in_our_company.Add(a_bad_invoice);
    all_invoices_in_our_company.Add(a_bad_invoice);
    all_invoices_in_our_company.Add(a_good_invoice);
    all_invoices_in_our_company.Add(a_good_invoice);
    all_invoices_in_our_company.Add(a_good_invoice);
    all_invoices_in_our_company.Add(a_good_invoice);
    all_invoices_in_our_company.Add(a_bad_invoice);

    foreach (var invoice in all_invoices_in_our_company){
        if (delinquent_invoice_specification.is_satisfied_by(invoice))
            send(invoice).to_legal_department();
    }

}

private IInvoice a_bad_invoice { get { return new Invoice(DateTime.Now.AddMonths(-10), 5000, 8, true); } }
private IInvoice a_good_invoice { get { return new Invoice(DateTime.Now.AddMonths(1), 1205, 0, false); } }

And there we have it.. crunched composite specification. [ Here's the code ]
Hope that helps
Zak

Older Posts »

Powered by WordPress