Wednesday, February 22, 2012

NuGet Project Uncovered: SpecificationExtensions.[MSTest | NUnit | Xunit]

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

NOTE: this project is one I created and as it turns out this has now become it’s introductory post.

The SpecificationExtensions.[MSTest | NUnit | Xunit] are a set of NuGet packages that add C# fluent specification extensions to your test project. I first blogged about this in early 2009 and have had a set of these that I take with me for every project I work on.

There are a number of other options out there for specification extensions, but since I first created my original set, I haven’t used anything else (although I should as I might be able to learn a little from each).

image_thumb10_thumb

Tuesday, February 21, 2012

NuGet Project Uncovered: EventAggregator.Net

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

NOTE: this project is one I created and as it turns out this has now become it’s introductory post.

EventAggregator.Net is a single C# file that can provide a basis for a simple in memory Pub/Sub event aggregator.

I extracted this out of my StatLight project as I found that I often wanted a similar one and kept finding myself copy/pasting this into projects. I figured a single location for this project would be better and I use StatLight as the first dog bowl when I need to dog food the project.

If you’re familiar with the…

Install-Package Caliburn.Micro.EventAggregator

…then you know probably know what this project is like.

Its history starts a few years ago when I read Jeremey Miller’s Braindump on Event Aggregator Pattern and decided I wanted rip out StatLight’s usage of the Prism event aggregator and replace it with a similar one to the one found in StoryTeller. It’s gone through quite a few revisions inside of StatLight since then and eventually made its way into its own project.

Some thanks have to go out to the great feedback and pull requests from Jake Ginnivan who found this project on his own (before I publicized it).

If you’re interested in using it, I’d recommend checking out the source’s test project and the SampleUsage project. The SampleUsage project demonstrates how you can configure the tool to publish events in an async mode.

One concept introduced in this EventAggregator is taking the IEventAggregator interface and breaking it up into two interfaces (IEventPublisher and IEventSubscriptionManager). This proved extremely useful when trying to diagnose components that did both aggregator subscription management vs ones that only published events. It even helped to easily diagnose components that did not correctly unregister objects.

Monday, February 20, 2012

NuGet Project Uncovered: DumpToText

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

NOTE: this project is one I created and as it turns out this has now become its introductory post.

DumpToText is a single C# extension I wrote a little while back. The inspiration from this came from the need to view the values of an object graph quickly and easily during a TDD session.

Have you ever been doing TDD and something isn’t working quite as expected? Would it be nice to just dump out the values of an object quickly without having to spin up the debugger?

The inspiration for this project came from an amazing feature of LINQPad. If you have ever used LINQPad then you’re aware of the amazing ability for it to take any object and create a view of it’s data. Take the simple anonymous type below.

image_thumb2_thumb

Now wouldn’t it be great to have that “.Dump()” extension method at hand anywhere in your code and during a TDD session?

That’s why I create DumpToText.

Now if I have a test as follows and want to see it’s data. I can use the ‘.DumpToText()” extension method to have it print out an ASCII based representation of the object graph.

image_thumb4_thumb

image_thumb6_thumb

By default this just uses the System.Diagnostics.Trace(…) to write the output to, but you can override the “write” implementation by giving your own delegate as shown below.

image_thumb8_thumb

The below shows an example of a nested object that also has an array of items.

image_thumb14_thumb

image_thumb13_thumb1

Anyone out there using ApprovalTests? (You can get it on NuGet)

I’ve not taken the chance to use ApprovalTests yet in a project, but I have a strong feeling that my DumpToText helper could be very useful when leveraged in conjunction with ApprovalTests. If anyone out there is using ApprovalTests, I’d love to hear how it’s going, and if you think that DumpToText would be useful there.

Sunday, February 19, 2012

NuGet Project Uncovered: Nancy

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Nancy is another project founded by an elegant coder. Andreas has blogged about it a number of times here on ElegantCode.

Nancy is a lightweight HTTP framework for building web services and sites. The framework runs on both the .net framework and Mono.

I have not used this project myself, but as I started to look it over I think I might have to spin up a site quickly just to try it out.

Saturday, February 18, 2012

NuGet Project Uncovered: Extended.Wpf.Toolkit

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Extended.Wpf.Toolkit is a project that should not need an introduction, and if you follow this blog you’ve probably heard Brian talk about it. If not, check out some of the posts on the Extended WPF Toolkit!

This project is one of the most download on codeplex, discussed on Channel9, Coding4Fun, and is being leveraged by Telerik in their Open Access ORM product.

Below is a sample of some of the controls you can find in the toolkit:
(but make sure you check out the project site for the full list of controls)
  • BusyIndicator
  • Calculator
  • ChildWindow
  • ColorCanvas
  • ColorPicker
  • DateTimePicker
  • Magnifier
  • MultiLineTextEditor
  • PrimitiveTypeCollectionEditor
  • RichTextBox
  • SplitButton
  • WatermarkTextBox
  • Wizard

Friday, February 17, 2012

NuGet Project Uncovered: TranslatorService.Speech

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

TranslatorService.Speech is a small little wrapper around the Bing text to speech API. You will need to get a Bing api key to leverage this.

Below is a sample usage of the library.

SpeechSynthesizer speech = new SpeechSynthesizer(APP_ID);   


// To obtain a Bing Application ID, go to http://msdn.microsoft.com/en-us/library/ff512420.aspx  

string text = "Have a nice day!";
string language = "en";

using (Stream stream = speech.GetSpeakStream(text, language))
{
using (SoundPlayer player = new SoundPlayer(stream))
player.PlaySync();
}



I threw that into a quick test and was quite impress with how fast it worked.



Unfortunately I tried to translate a larger “paragraph” or so of text and saw.




System.Net.WebException : The remote server returned an error: (400) Bad Request.



at System.Net.HttpWebRequest.GetResponse()

at TranslatorService.Speech.SpeechSynthesizer.GetSpeakStream(String text, String language)


at NuGetTestProject.Sample.SampleTest() in Class1.cs: line 14




I didn’t take the time to diagnose why, whether it’s a Bing problem or this library.



Some other observations:




  • + It supports some Async methods as well


  • - The Async methods don’t support the standard APM so I couldn’t easily wrap a task around. (I know there are some ways to make it work, but it’s not out of the box easy…)

Thursday, February 16, 2012

NuGet Project Uncovered: JsValidator

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

JsValidator, on first glance, is a down right awesome gem of a NuGet. I’ve heard of Google’s Closure Compiler before, but have never used it. This NuGet makes it a snap to use inside Visual Studio.

When you first install the package:

Install-Package JsValidator;

This NuGet tool automatically updates your project so it will execute the tool on compilation. Awesome if you are not an MSBuild expert as it just configures itself for you straight from the package install.

Once installed, run a build on your solution. On first build you get an error. You’re probably thinking '”How can this tool be erroring, we just added it to the project”. This error is a good thing. It’s telling you that you now have a manual step to configure it correctly.

Go check out the codeplex site as it will explain more on how to use it.

I just might consider this on my next new javascript project in Visual Studio.net.

Wednesday, February 15, 2012

NuGet Project Uncovered: FastMember

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

FastMember would be something you pull in if you’re trying to do reflection to read properties of your objects, but starting to notice some performance issues. This project will emit some IL at runtime that can read your properties much faster than good old reflection (like below)

var value = typeof(MyObject).GetProperty(“MyProp”).GetValue(myObjInstance, new object[0]);

Replace the above with.

var accessor = TypeAccessor.Create(typeof(MyObject)); 
var value = accessor[obj, “MyProp”];



This project lets you either read or assign values to properties. (See my test below)



image_thumb1_thumb

Tuesday, February 14, 2012

NuGet Project Uncovered: FakeO

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

FakeO is a fake object generation library. It doesn’t seem to play nicely with objects that require parameters in the constructor. However if you have lots of classes that have a default constructor and plain old get/set properties this project might be very useful.

You can even specify not just random text or numbers to generate, but some specific context driven data.

For example:

  • Random company name
  • Lorem Ipsum to various lengths.
  • Phone numbers
  • Random strings based on a regex.
  • etc…
// example FakeO call
var comp = FakeO.Create.Fake<Company>(
c => c.Name = FakeO.Company.Name(),
c => c.Phone = FakeO.Phone.Number(),
c => c.EmployeeCount = FakeO.Number.Next(100,200)); // random number from 100 to 200

Monday, February 13, 2012

NuGet Project Uncovered: NaturalSpec

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

NaturalSpec is a BDD framework written in F#. This one is interesting due to F#’s concise nature and can give you very readable tests/specs.

The below sample was pulled from the github readme.

[<Scenario>]
let ``When removing an element from a list it should not contain the element``() =
Given [1;2;3;4;5] // "Arrange" test context
|> When removing 3 // "Act"
|> It shouldn't contain 3 // "Assert"
|> It should contain 4 // another assertion
|> It should have (length 4) // Assertion for length
|> It shouldn't have duplicates // Tests if the context contains duplicates
|> Verify // Verify scenario



It says you don’t have to learn F# to use it. Which I’d argue you may not have to learn F# as deep as you might to be able to code a production product in it, but you will definitely benefit from learning some as you go. You will also spend a bit of time learning the DSL that this project has created.



Regardless, this project has enough interest factor for me to play around with someday.

Sunday, February 12, 2012

NuGet Project Uncovered: SpecsFor

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

SpecsFor is a BDD framework. This project is nice in that it has packaged many of my favorite testing tools all into one package. Instead of pulling down NUnit, Moq, Should, Automocking, and ExpectedObjects creating your own base fixture class. This project wraps all that up for you with a solid base spec class.

The creator of this project spent some time and created a nice project site with examples and documentation.

Saturday, February 11, 2012

NuGet Project Uncovered: Disruptor-net

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Disruptor-net is a port of the LMAX Disruptor which is a concurrent programming framework. The answer in this StackOverflow question gave a pretty good explanation of the project/pattern used.

Project Source: https://github.com/odeheurles/Disruptor-net

Friday, February 10, 2012

NuGet Project Uncovered: Nukito

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Nukito is a project that’s taking AutoMocking to another level and baking it into the tooling/framework. If you use xUnit and Moq and want to avoid much of your redundant mock setup/verify code. You might want to take a look at this project.

I didn’t dig very deep into this project, but it smells somewhat like AutoFixture which I believe has more support for other frameworks and is a bit more popular. (Again I didn’t dig deep enough to understand the core differences).

Thursday, February 9, 2012

NuGet Project Uncovered: StudioShell

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

StudioShell is a project that sort of blew my mind. The crazy PowerShell integration they’ve packaged into this visual studio extension is plain amazing.

I’d highly recommend watching the demo videos near the bottom of the project’s home codeplex site.

http://studioshell.codeplex.com/

Wednesday, February 8, 2012

NuGet Project Uncovered: AboditNLP

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

AboditNLP is a Natural Language Processor library. This kind of stuff in interesting, but not something I have chosen to spend my time on.

It has a demo http://nlp.abodit.com/home/demo which gives you sample things to type to the library. I noticed it was a bit case sensitive, but still, project is one to look into if you were to say build a home automation system.

Tuesday, February 7, 2012

NuGet Project Uncovered: Northwind.Db

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Northwind.Db is a version of the infamous Northwind database packaged in an awesomely easy install/setup NuGet package. I’ll outline the experience of installing the Northwind.Db into a sample project.

After executing the below command in my Package Manager Console

Install-Package Northwind.Db

I was presented with a wizard where I could choose what type of database model I wanted to use.

image_thumb61_thumb

How did I want to generate my model?

image_thumb7_thumb

Where should it connect to (Notice the Northwind database was already setup for me).

image_thumb8_thumb1

And now I had the Northwind database all setup and ready to go.

image_thumb9_thumb

I’m not quite sure why it installed twice. (once in the root of my test project, and the other in the App_Data folder)

I also couldn’t use the Uninstall-Package command to remove the project

The process cannot access the file '…App_Data\Northwind.MDF' 
because it is being used by another process.



Regardless of some of the issues, if I had to quickly get a sample sql database up and running this would be nice and easy.

Monday, February 6, 2012

NuGet Project Uncovered: Deleporter

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Deleporter is a project I used over a year ago. It allows you to setup a delegate and execute it in a different process.

For Example: You spin up a unit/integration test project. Over in IIS you have a web site running. Now how do you do things like mock out crazy dependencies, adjust the time in your favorite SystemTime implementation or just tweak the configuration on the fly?

You can leverage Deleporter to execute code over on the web server controlled by your test project.

I’d recommend your go read the introductory blog post

Deleporter: Cross-Process Code Injection for ASP.NET

Sunday, February 5, 2012

NuGet Project Uncovered: DynamicXaml

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

DynamicXaml takes a fluent approach to building up xaml in code. Following the pattern laid down by the HtmlTags project, this project provides a very clean way to write out your xaml code in C#.

I’ve copied a sample from the github readme below.

var _builder = new XamBuilder();
var button =
_builder.Start<Button>()
.Margin("5,0")
.WidthAndHeight(200d,30d)
.Create();



One of the things I like about these projects is if you can’t use markup and are pushed to write your xaml in C#, you can apply some great tricks to reduce duplication with your code. (Not sure how this library works out, but I would suspect that if you created a default Button object, it would allow you to override specific properties one at a time or extend with new properties. This way you can create your base controls and only tweak as necessary.

Friday, February 3, 2012

NuGet Project Uncovered: IntX

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Have you ever wanted to generate a number that could potentially have millions of digits and do arbitrary mathematical operations against it? Ya, me neither. But if I did, I would take a look at this project.

IntX is

an arbitrary precision integers class written in pure C# with fast - about O(N * log N) - multiplication/division algorithms implementation. Runs on .NET 2.0+.

The intx.codeplex site has quite a bit of info about the project (TL;DR). If you’d like to learn more I’d suggest checking it out.

Thursday, February 2, 2012

NuGet Project Uncovered: Burro

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Burro is a project that I only quickly looked at. I don’t know all that it does, or how to get it up and running. In the project’s readme it says

I'll put some examples up as things progress, for now you'll just have to work it out yourself.

What I do know is that it is supposed to parse build output from a build server in a consistent way. How do I know that? (The github project says).

What is it?

Burro is a tool for parsing output from build servers in a consistent way.

I only put this in here as a project to look at. I think that parsing build output sounds very challenging and props to this project for giving it a go…

Wednesday, February 1, 2012

NuGet Project Uncovered: Chronic

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

Chronic is a port of Ruby’s Chronic providing some natural language parsing for dates.

This is a pretty cool little utility as it lets you take some input like "tomorrow” or “two weeks ago” and turn that into a DateTime object.

Take a look at some tests I pulled from https://github.com/robertwilczynski/nChronic/blob/master/src/Chronic.Tests/CustomParsingTest.cs.

[Fact]
public void seven_days_from_now_at_midnight()
{
Parse(" seven days from now at midnight")
.AssertEquals(Time.New(2006, 8, 24));
}

[Fact]
public void _2_weeks_ago()
{
Parse("2 weeks ago")
.AssertEquals(Time.New(2006, 8, 02, 14));
}

[Fact]
public void two_weeks_ago()
{
Parse("two weeks ago")
.AssertEquals(Time.New(2006, 8, 02, 14));

I tried playing with it a bit. There seem to be some cases sensitivity issues with the codebase now as “tomorrow” works but “Tomorrow” doesn’t. But I think that’s a great reason to be on GitHub. Fork, fix, and send a pull request. All better…

 

Copyright 2008 All Rights Reserved - Revolution Theme - by Brian Gardner. Converted into Blogger Template by Bloganol dot com