Musings<Biefeld>
- curiosities of development, life, the universe and everything -
February 1st, 2010

How are things…
Things are things
People are people
I am neither
Things nor people
I am me
you are you
Next time ask
How do you do

August 27th, 2009


Whilst researching using MSpec with ReSharper I found it difficult to find all the resources I needed in one place. This is an attempt to condense everything into that one place and facilitate those seeking to accomplish the same task.

Step 1 – Git It:

First thing’s first, grab the latest Machine Spec source from github.

$ git clone git://github.com/machine.machine.specifications.git mspec

Step 2 – Build It:

Next, open it up in Visual Studio, set it to build in release mode and build it. Now the binaries will be ready for you.

Step 3 – Setup ReSharper:

Now we need to setup ReSharper to be able to utilize the MSpec framework and run the tests in ReSharper’s test runner. To do this we need to add a plugins directory to the “JetBrains\ReSharper\v4.5\Bin” directory or the where ever the bin directory for your ReSharper is located. In the Plugins create a Machine.Specifications directory, so you should now have a path similar to; “JetBrains\ReSharper\v4.5\Bin\Plugins\Machine.Specifications”. Place the following dlls in the newly created folder: Machine.Specifications.ReSharperRunner.4.5.dll and Machine.Specifications.dll.

Step 4 – Write some Specifications:

Coolio, now to test some behaviors, the dlls needed in our test project; Machine.Specifications.dll, Machine.Specifications.NUnit.dll or Machine.Specifications.XUnit.dll, and the appropriate test framework dll.


Let’s take a look at a couple of examples to get used to the syntax. The most common keywords you want to pay attention to are Subject, Establish, Because and It. Declare the Subject of your Spec, Establish a context of the spec, Because x occurs, It should do something. For more complex scenarios you can use the keyword, Behaves_like and the Behaviors attribute which allows you to define complex behaviors. If you need to perform some cleanup use the Cleanup keyword.

Now for a couple of simple contrived examples…

This first specification looks at adding two numbers:

[Subject("adding two operands")]
public class when_adding_two_operands
{
	static decimal value;

	Establish context = () =>
		value = 0m;

	Because of = () =>
		value = new Operator().Add(42.0m, 42.0m);

	It should_add_both_operands = () =>
		value.ShouldEqual(84.0m);
}

The second specification looks at adding multiple numbers:

[Subject("adding multiple operands")]
public class when_adding_multiple_operands
{
	static decimal value;

	Establish context = () =>
		value = 0m;

	Because of = () =>
		value = new Operator().Add(42m, 42m, 42m);

	It should_add_all_operands = () =>
		value.ShouldEqual(126m);
}

The code being tested:

public class Operator
{
	public decimal Add(decimal firstOperand, decimal secondOperand)
	{
		return firstOperand + secondOperand;
	}

	public decimal Add(params decimal[] operands)
	{
		decimal value = 0m;

		foreach (var operand in operands)
		{
			value += operand;
		}

		return value;
	}
}

Step 5 – Create Templates to Improve Your Efficiency:

Using ReSharper templates is a good way to improve your spec writing efficiency, the following are templates I have been using.

This first one is for your normal behaviors:

[Subject("$subject$")]
public class when_$when$
{
	Establish context =()=>	{};

	Because of =()=> {};		

	It should_$should$ =()=> $END$;
}

This one’s for assertions by themselves:

It should_$should$ =()=> $END$;

Step 6 – Run the Report

The report generated is pretty much the exact same as the SpecUnit report. The easiest thing to do is place the following MSpec binaries and file in the directory where your test binaries are placed; CommandLine.dll, Machine.Specifications.ConsoleRunner.exe, Machine.Specifications.dll and CommandLine.xml. The command to run the report goes a little something like:

machine.specifications.consolerunner --html <the location you want the html report stored> <your test dll name>

This is the report generated from the example specs:

MSpecReportExample


Well, that’s about all for now, let me know if you have any questions.


July 13th, 2009

A while ago I was having issues using configuring fluent NHibernate with an external configuration file. I kept running into the issue of mappings not being registered. I was finally able to get it working appropriately and thought I would share my solution. The key is to configure the normal mappings first and then pass that configuration in when configuring fluent NHibernate.

string configFile = "hibernate.cfg.xml";

//setup the normal map configuration
Configuration normalConfig = new Configuration().Configure(configFile);

//setup the fluent map configuration
Fluently.Configure(normalConfig)
.Mappings(
m => m.FluentMappings
.ConventionDiscovery.Add(DefaultLazy.AlwaysFalse())
.AddFromAssemblyOf<UserMap>())
.BuildConfiguration();
May 23rd, 2009


I am ramping up on my next personal project, No Fluff News. The site is going to be designed to sort out real news from non-news. The objective so far: Aggregate news, weed out non-news, link to true news, create an insightful, non-PC, sarcastic description and picture per item. For updates on the site follow on twitter, @nofluffnews.


May 16th, 2009


Just watched the Obama Deception, made by Alex Jones, it is very illuminating on the facade put up by international banking cartels that have been around for centuries, i.e. the Rothschild Family. It is incredible that people continue to believe politicians even though they continually lie.

Some of the best quotes from the film are of former presidents Abraham Lincoln and Thomas Jefferson:

“The money powers prey upon the nation in times of peace and conspire against it in times of adversity. It is more despotic than a monarchy, more insolent than autocracy, (and) more selfish than bureaucracy. It denounces, as public enemies, all who question its methods or throw light upon its crimes. I have two great enemies, the Southern Army in front of me and the bankers in the rear. Of the two, the one at my rear is my greatest foe…corporations have been enthroned, and an era of corruption in high places will follow, and the money power of the country will endeavor to prolong its reign by working upon the prejudices of the people until the wealth is aggregated in the hands of a few, and the Republic is destroyed.”Abraham Lincoln

“If the American people ever allow private banks to control the issue of their currency, first by inflation then by deflation, the banks and the corporations that will grow up around them, will deprive the people of all property until their children wake up homeless on the continent their fathers conquered.”Thomas Jefferson


Bush and Obama are one in the same, two figure heads of a serpent constricting the freedom and life out of our country. Our freedoms are slowly being taken from us, they are beginning to assault free people filming and taking pictures in public places, both in the U.K. and the U.S.

The Bilderberg Group is currently meeting outside of Athens, Greece. A writer for the The Guardian, Charlie Skelton has been arrested multiple times for taking pictures near where the group is meeting. Skelton is a very engaging and enlightening writer. Here are a few highlights from his posts:

“It wasn’t meant to end this way. I’d gone for a gentle sunset walk, up by the Bilderberg hotel, to relax before the big opening day of the elite globalist shindig, watch Phoebus plunge headlong into the western sea, and (yes) maybe sneak a couple of short-lens pictures of the mounting security…Over came the man with the machine gun. Over came the man with the special mirror-on-a-stick for car bombs. It was the first time in my life, and hopefully the last, that I’ve been intimidated by a mirror on a stick. They circled round me. One of them, the one in the photo with one hand up and the other on his pistol, kept prodding me in the shoulder, and shouting: ‘Give the camera! Just give the camera!’” – Charlie Skelton

“Bilderberg is all about control. It’s about “what shall we do next?” We run lots of stuff already, how about we run some more? How about we make it easier to run stuff? More efficient. Efficiency is good. It would be so much easier with a single bank, a single currency, a single market, a single government. How about a single army? That would be pretty cool. We wouldn’t have any wars then. This prawn cocktail is GOOD. How about a single way of thinking? How about a controlled internet…My confession is that being tailed today by Greek special branch, and doubling back through a cafe and catching them out, and buying them chilled water on a hot day like in Beverley Hills Cop, when Eddie Murphy has room service sent to their car – all this was pretty exciting…Bilderberg is about positions of control. I get within half a mile of it, and suddenly I’m one of the controlled. I’m followed, watched, logged, detained, detained again. I’d been put in that position by the “power” that was up the road. Likewise, the Bilderberg delegates occupy a position of power over the bobbing ignorance of the people patting beach balls in the sea, and me with my crappy little camera and my curiosity and my ill-formed sense of citizenship. I may not be very good at bearing witness here, but I’m doing my best. I haven’t shinned over the fence and shoved a camera in David Rockefeller’s face but I don’t want to be shot in the forehead.”- Charlie Skelton

“I walk into the far entrance of the cafe. I’m in an episode of The Wire. The cafe is long and thin. I double back on myself and stand, hidden, by the earlier entrance. I’m standing behind a shrub, clutching a laptop to my chest, my heart beating like a Phil Collins solo (on drums, not piano)…They’re watching me now. REALLY. They’re sitting on the wall outside the cafe Oceania or whatever this is called, watching me type this sentence. I asked them in for a coffee but they declined. They laughed sheepishly when I called them Starsky and Hutch.”- Charlie Skelton


Not only that, the youth of our country are being trained in tactical assault reminiscent of the Hitler Youth. They are gearing up to take our country hostage and handle any uprising that may occur against the self-appointed gods that these ruling elite view themselves as.

The best way to fight these narcissistic rulers is to spread information exposing who they are and what they are doing. Everyone must become a disseminator of information about secret/semi-secret organizations like the Bilderberg Group, the Council on Foreign Relations, and the Trilateral Commission. Freedom of information is the absolute enemy of the elite bankers, politicians, and corporations. Only through an information revolution exposing truth will we the people be able to usurp these fascistic, narcissistic, masochistic would-be rulers. The corruption is endemic in all levels of government and the citizen media is key to embarrassing and exposing the degradation of these so-called rulers. Resist the doublespeak and newspeak, don’t be sheeple, seek the truth and you shall be free.

The Obama Deception Film


May 12th, 2009


*UPDATE: Per sean chambers, this is an example of the adapter pattern


I recently ran into an issue where I needed to implement a simple email service to send users a randomly generated PIN when they are first entered into the system. To accomplish this I decided to just use the System.Net.Mail implementation.  To create and send an email you have to use the SmtpClient class which does not implement an interface. All I really wanted to test was that the Send() method was called, I did not want to write an integration test that actually sends an email.


One way to work around this problem is to create an interface containing the elements you need to mock from the compiled class.  After this, create your own class that inherits the compiled class and implements your interface. Now when testing, you can seemingly mock up the non-interfaced compiled class, which is exactly what I wanted to achieve. I am not sure whether this is the appropriate way to handle the issue, if anyone has any thoughts on a better way to do this, I would be grateful for the advice.

My specification ended up looking like this:


public class EmailServiceSpecs : ContextSpecification
{
	protected IEmailService _emailService;
	protected ISmtpClient _smtpClient;
	protected string _emailTo = "phillip.fry@planetexpress.com";
	protected string _emailFrom = "hermes.conrad@planetexpress.com";
	protected string _emailSubject = "New Process to Improve Morale";
	protected string _emailBody = "From now on all employees will be required to have Brain slugs, remember, a mindless worker is a happy worker.";

	protected override void SharedContext()
	{
		DependencyInjection.RegisterType<IEmailService, EmailService>();

		_emailService = DependencyInjection
			.GetDependency<IEmailService>(_emailTo, _emailFrom, _emailSubject, _emailBody);

		_smtpClient = MockRepository.GenerateMock<ISmtpClient>();

		DependencyInjection.RegisterInstance(_smtpClient);
	}
}

[TestFixture]
[Concern("Email Service")]
public class when_sending_an_email : EmailServiceSpecs
{
	protected override void Context()
	{
		_smtpClient.Stub(smptClient => smptClient.Send(new MailMessage()))
			.IgnoreArguments()
			.Repeat.Any();

		_emailService.Send();
	}

	[Test]
	[Observation]
	public void should_send_email()
	{
		_smtpClient.AssertWasCalled<
			(smtpClient => smtpClient.Send(new MailMessage()),
			assertionOptions => assertionOptions.IgnoreArguments());
	}
}

Below are my email classes:

public interface ISmtpClient
{
	void Send(MailMessage message);
}

[MapDependency(typeof(ISmtpClient))]
public class SubsideSmtpClient : SmtpClient, ISmtpClient { }

public interface IEmailService
{
	void Send();
}

[MapDependency(typeof(IEmailService))]
public class EmailService : IEmailService
{
	public EmailService(string to, string from, string subject, string body)
	{
		Email = new MailMessage(from, to, subject, body);
	}

	protected MailMessage Email
	{
		get; set;
	}

	private ISmtpClient _smptClient;

	protected ISmtpClient Smtp
	{
		get
		{
			_smptClient = DependencyUtilities
				.RetrieveDependency(_smptClient);
			return _smptClient;
		}
	}

	public void Send()
	{
		Smtp.Send(Email);
	}
}
May 12th, 2009


Hey just wanted to let everyone know that I updated my Firefox theme, MonoChrome, for version 3.5b4pre.
You can grab it from the link below:


https://addons.mozilla.org/en-US/firefox/addon/8791


Screen shot:


If you would like to contribute or grab the source, it is hosted on google code:

http://code.google.com/p/monochrometheme

May 11th, 2009


A wonderful poem by Michael Savage:

“I am Moses,
I am Abraham.
I am Isaac,
I am Charlagmane.
I am John Wayne,
I am Coltrane.
They try to suppress me,
try to redress me.
Call me incorrect,
deserving no respect.
I am Patton,
I am Hatton,
even Mt. Batten.
I am Eisenhower,
not a wallflower.
I am Washington,
I am Pershing.
I am McArthur,
I am Kipling.
I am Audie Murphy
and I am Sky King.
They’ll steal your crown,
trample you down.
Take your good name,
and put it to shame.
I am Gene Autry,
I am Roy Rogers.
I am Tom Mix.
They try to push me,
over the river Styx.
But it won’t mix,
with my true blood,
which runs thick for America.
I am the bane,
of those vain.
I am the Weather Vein!
I am Michael Savage!


Poem relating to Savage’s ban in the U.K.

-Michael Savage

Audio Source: mp3

Copyright 2009 Michael Savage, Talk Radio Network All Rights Reserved.

April 14th, 2009


I just finalized my text color theme for visual studio. Just thought I would share it with everyone. It is geared towards those of you who have resharper installed, but it should still work fine without it.


The theme is based off of the textmate twilight theme. I was going for a low contrast theme that is easy on the eyes.  I have tried the Vibrant Ink theme and it is too abrasive for me. My goal was to make warnings and errors blatantly obvious and distinguish classes from interfaces. I also love how the comments are dark and do not draw attention, I am not a big fan of comments.  I think the code along with BDD tests should be self-explanatory of what is going on.


All resharper warnings show up as red text. Build errors have red squiggly lines under them.  Breakpoints have red background.


Here is a c# example:



Here is an example of an aspx page:



Style sheet example:



JavaScript example:



Let me know if you have any suggestions.


Grab the Visual Studio settings file here!


March 3rd, 2009


As .net developers do you ever feel like Microsoft is hindering your development by the development tools they impose on us. I have been thinking about this lately and decide to discuss it, or this might actually be a rant, forgive the rant. I aim to take a brief look at web development the Microsoft way, how it has evolved, and the hindrances imposed on the community.

The Microsoft Web Development World

Now I have never developed Microsoft web applications pre-webforms, i.e. pre-Asp.net, so I am not going to comment on that. What I am going to focus on is Microsoft’s asp.net development frameworks. As a side note, I have not done much development on the windows side of things, but it seems that it has been stagnating. I would love to see Microsoft write some bindings for GTK+ and/or Qt, and support those cross platform toolkits. Pie in the sky dreams, I know.

ASP.NET – Web Forms

Somehow in their brilliance, big brother decided that abstracting HTML and Javascript into a infinitely more complex framework would be a good idea. This is ludicrous, don’t introduce unnecessary bloat into a framework. The page life cycle is ridiculous, all the built in webform controls use some retarded infinite inheritance scheme. Also what’s Microsoft’s infatuation with span tags, they wrapped all their webform controls in them.


Lol, I know this is common knowledge and has been discussed at length before but I still have to deal with it on a daily basis and it feels like I’m trying to cut off my leg with a steak knife. My interest lies in finding the true reasoning behind this. I have to working theories. One is that Microsoft is so loving and kind towards their developers that they wanted to coddle them, and that coddling most likely stemmed from their lack of respect for us and our intelligence. The other theory is that Microsoft convoluted the framework without realizing it due to their arrogance, believing they own the world and the way they are doing things must be right.

ASP.NET AJAX

Next the web 2.0 boom arrived and everyone was clamoring for more interactive web UIs. The .net developers yelled loud enough and long enough that they wanted to have the same thing that they were witnessing in other web frameworks. The keyword here is ajax. So what does Microsoft do, they don’t take this moment and think about totally redesigning their asp.net framework, they say lets create some more complex web controls and use them in conjunction with an uber-complex ajax framework.


Awesome, we now how fresh steamy poo piled on top of old rotting, festering poo. Thanks big brother. Instead of realizing their mistakes they made with web forms they exacerbate the problem. Now we get a seemingly dumbed down ajax scheme, oh just wrap everything in an update panel and Microsoft will do the rest. Besides the fact that this removes all control you have over the interactions between the server and client, you also can not use any other javascript inside of these panels. So once again it boils down to arrogance, contempt, and a lack of foresight.

ASP.NET MVC

Now, Microsoft sees a significant proportion of developers moving to ruby utilizing the ruby on rails framework. Also the community is yelling and screaming again, must be appeasement time. Did Microsoft actually take an introspective look and realize how ass backwards webforms is? Doubtful, they just figured out that they better do something to try and hold onto market share and give the community some fools gold. So they copy ruby on rails, ooooh, way to go big brother, you’re so innovative!


It is way too late in the game, asp.net mvc is something Microsoft should have done long ago. Back when they were formulating asp.net webforms. There is no excuse for Microsoft not to have created a framework like this when they introduced the asp.net ajax stuff. It’s ridiculous, and still they are losing market share, I wonder why.


They ignore their base long enough and they won’t have a base. What are we supposed to drink the kool-aid and be satisfied, the MVC pattern is how old? Oh, wow they are supporting a way to unit test the UI interactions, wow how progressive you are Microsoft. Where is the support for plugins, where is the support for RESTful web services? The point is there is nothing to be impressed about, it’s ridiculous that people are excited, this should have happened long ago.

Conclusion

Now don’t get your panties in a wad I’m not all cynical, I like c# as a language, even thought it is a static language and I like the CLR. Hopefully MVC is a sign that Microsoft is going to be moving at a less stagnant pace. I don’t think they will be.


Things like Mono, NHibernate, the alt.net community supplement the failings of the giant, but we should be fed up. Microsoft doesn’t listen, because of their corporate culture, which i doubt will change. Adding things to the web framework that should have been there long ago is nothing to celebrate, there i said it, “Big whoop, want to fight about it”.


On a larger scale, why is Microsoft not listening to the community more, why are they not seeking to improve the community along the lines of the ruby community? Where is Microsoft’s version of package management like ruby gems? Where’s their continuous integration/build tool? Where’s their testing framework? Where’s there promotion of best software practices, i.e. SOLID, TDD, BDD, Agile methodologies, Lean methodologies? The answer is no where, all of that exists inside the community without Microsoft’s support.


The community is bettering ourselves in spite of Microsoft’s stagnation. Now think what could be accomplished if they actually fully embraced the community and threw their money and clout behind what the community stands for, it would be great. I am very doubtful that will happen, though, I think it will take mass exodus from .net development for Microsoft to ever get the message. If nothing happens the .net community will continue to stagger along at the pace of Microsoft, it will not reach its potential, and the community will wither and die.


There is an entire software industry that needs to mature, the .net community is but a sub-section of it.  It would be great if we could lead the industry in best practices and passion for our craft.

Older Posts

Musings<Biefeld> is proudly powered by WordPress
Entries (RSS) and Comments (RSS).