2009-02-25

The amazing “Mr Thumb”

Yes, this is a very silly link but yes, this man really does look like he consists entirely of thumb.

http://www.facebook.com/group.php?gid=47403524050&ref=share

PayPal doesn’t do discounts

I can't believe it, I really can't!

I'm writing a shopping cart for a website. One of the features required is to give the user an X amount discount off their next order when they buy a specific product. So let's say the user has a £20 discount on their next order, how does PayPal let me apply that? Simple answer, it doesn't!

You can't send a cart line with a negative price "Discount for 20 GBP", nor can you send a cart line with a positive price but a negative quantity (that was desperation). The way to do this apparently is to send a cart total. YES! By sending the entire order aggregated into a single order line. NOOOOOOO!!!!!!

So PayPal wants my user to order £100 of goods, click Check-out, and then be presented with "Total for your order £100 (£20 discount)", that's it? In my opinion, that's not very good. In fact, considering PayPal is probably the largest Internet payment organisation in the world I consider this to be atrocious!

Oh well, back to it...

2009-02-24

More Balsamiq madness!

Someone pointed this link out to me today:

http://www.screensketcher.com/examples.html

It's another application along the lines of Balsamiq. This app does seem very "sharp", it has very snappy response times etc, which is nice and everything BUT I still don't like these kinds of apps!

I do prefer the name though, it suggests "I sketch screens" rather than "I am a bottle of vinegar".

2009-02-17

This is just a test

I've just spotted a "Publish to Blog" option in Word 2007. So I thought I'd give it a spin and see what happens. If it works then Blogging is going to be a much more pleasurable experience.

  1. My spelling is atrocious.
  2. I find complex formatting on BlogSpot is terrible.
  3. I will no longer have to edit HTML just to get my code to look right.

Talking of code, I had better try that out too...

    public class PreSaveConstraint

    {

        public readonly IObject Instance;

        public readonly string Name;

        public readonly Func<bool> CheckIsValid;


 

        public PreSaveConstraint(IObject instance, string name, Func<bool> checkIsValid)

        {

            if (instance == null)

                throw new ArgumentNullException("Instance");

            if (string.IsNullOrEmpty(name))

                throw new ArgumentNullException("Name");

            if (checkIsValid == null)

                throw new ArgumentNullException("CheckIsValid");


 

            Instance = instance;

            Name = name;

            CheckIsValid = checkIsValid;

        }

    }


 

Well, here goes. If you can see this then it worked!

2009-02-13

Proof of the existence of God

Finally there is proof that God exists. The proof has come in the guise of a product named Balsamiq. Balsamiq allows you to create mock GUI when specifying an application. Rather than having graphics that look like real forms etc it uses a pencil drawing lookalike approach.

Here is my reasoning.
  1. It does nothing you can't do for free in the IDE you undoubtedly already have.
  2. The result looks far worse than a mock up you can create in your IDE.
  3. Once you have the mock up you can't do anything useful with it except export it as an image or print it. You can't, for example, actually use that for a real form later in the project's life cycle.
  4. The result looks crap. Not poor, crap! It looks like a 7 year old has drawn it with a wax crayon....a blunt one.
  5. Balsamiq brought in revenue of over 100,000 US Dollars in its first 5 months.
Now the way I see it is this. Lots of people are sending money to a guy to buy software that does something they can already do much better for nothing. The only possible conclusion I can reach is that the developer must have sold his soul to the devil. Taking into account that we now have conclusive proof that Satan exists it is logical to conclude therefore that it is an absolute certainty that God also exists.

I rest my case.

2009-02-12

ASP.NET Development server and PayPal instant payment notification

I am currently developing part of a website where I pass cart information to PayPal to accept payment. PayPal will call back a "secret URL" on my website to allow me to confirm the cart details haven't been tampered with.

I hate installing software I don't need. This is especially the case with software like IIS which just feels so intrusive, which is why I use the ASP.NET Development Server when creating websites. The problem with this server is that it only accepts connections from the local machine. My computer is behind a hardware firewall and my web server wont accept remote connections, so how can I test my PayPal IPN call back?

Simple. Obviously I have to open a port on my firewall and direct it to my machine. So I opened port 80. Then I used this tool to list on port 80 and redirect all traffic to port 10101 (the port my ASP.NET development server was listening on). The result is that a remote computer can now make a HTTP request to my computer, and I can receive it + debug it in Visual Studio without having to install IIS.

The great thing about this port forwarder is that it is only 44KB in size and doesn't require any installation!

2009-02-10

Ultimate integration testing

I am just creating some classes that allow the user of an app to specify date/time validity. As I am modeling them it reminded me of some recurring event classes I once wrote to schedule payments between bank accounts.

One day my customer phoned me up. "Has your invoice been paid this month?" he asked.
"Yes" I said.
"Ah good, your code works then!"

2009-02-09

Onion architecture

Jeff seems to have put it very well in his blog. Much better than I did myself back in December 2006 when I blogged about my "Onion" idea.

My mistakes were
01: I was missing a domain services layer.
02: I tried to explain it using a specific example (wizard app with a "process stack" aka "task stack"), and later decided I didn't like the example :-)
03: When I drew my diagrams I showed them as a typical stacked diagram, because my graphics skills are crap :-)

Here's my badly put idea of onion layered applications:
http://mrpmorris.blogspot.com/2006/12/net-onion-part-1.html

Here's Jeffrey's
http://jeffreypalermo.com/blog/the-onion-architecture-part-1/

Well done Jeff, very nicely put!

Rhino Mocks, returning a different result every time

[TestMethod]
public void Meh()
{
var mockFileSystem = MockRepository.GenerateMock<IFileSystemService>();
mockFileSystem.Stub(fs => fs.CreateFileStream(null, FileMode.Append, FileAccess.Write, FileShare.None))
.IgnoreArguments()
.Return(new MemoryStream());

var result1 = mockFileSystem.CreateFileStream(null, FileMode.Append, FileAccess.Write, FileShare.None);
var result2 = mockFileSystem.CreateFileStream(null, FileMode.Append, FileAccess.Write, FileShare.None);
Assert.AreNotSame(result1, result2);
}


This test case shows a problem I was having. The return value of the stubbed CreateFileStream method isn't calculated each time it is called, it is calculated once at the point you defined the stub method and then returned for every subsequent call. The problem with this is that my real test needed to call CreateFileStream twice and get two different streams, the test was failing because the method being tested disposes of the stream it uses; this was resulting in an ObjectDisposedException in my test.

The correct way to implement this is to override the return value using WhenExecuted()

[TestMethod]
public void Meh()
{
var mockFileSystem = MockRepository.GenerateMock<IFileSystemService>();
mockFileSystem.Stub(fs => fs.CreateFileStream(null, FileMode.Append, FileAccess.Write, FileShare.None))
.IgnoreArguments()
.Return(null)

//*****The return value is replaced in the next line!
.WhenCalled(invocation => invocation.ReturnValue = new MemoryStream());

var result1 = mockFileSystem.CreateFileStream(null, FileMode.Append, FileAccess.Write, FileShare.None);
var result2 = mockFileSystem.CreateFileStream(null, FileMode.Append, FileAccess.Write, FileShare.None);
Assert.AreNotSame(result1, result2);
}

2009-02-08

Why are all my Visual Studio unit test results "Not executed"

When I run my unit tests in my project I am seeing a result "Not executed" for every one. I have restarted my computer so I doubt this is some kind of hung process issue.

Google has revealed nothing that is not related to load balancing, and I am not load balancing!

Solved

In order to determine the error you have to do this

  1. Open the Visual Studio command prompt
  2. Change to the directory where the binary output of your test project is.
  3. Type mstest /testcontainer:The.Name.Of.Your.Test.Assembly.dll

At the bottom of the output you will see the following text

Run has the following issue(s):

In my case it was the following:

Failed to queue test run 'Peter Morris@PETERMORRIS-PC 2009-02-09 10:00:37': Test Run deployment issue: The location of the file or directory 'C:\SomePath\SomeProject.Tests\bin\Debug\Rhino.Mocks.dll' is not trusted.

Now if VS had told me this in the IDE I could have fixed it in minutes! All you have to do is open Windows Explorer and find that DLL. Right-click on it and go to Properties. Then click the "Unblock" button.

If the IDE had told me the reason then it would have taken me 5 minutes to fix (as it did once I knew what it was)

2009-02-06

Silent errors

I'm working on an app which uses a 3rd party library for producing SWF and FLV files. For some reason the trial worked perfectly but when I switched my app to the full version there was no audio output.

We'd been looking at this problem for a while, emailing support etc, but just couldn't see what was wrong. It wasn't until I went back to my proof of concept app and ran it that we realised the full version did produce audio, it was just my main app that wouldn't work properly. Then I spotted the error...

var compressor = new TVE4();
compressor.LoadSettings(SettingsPath);
compressor.SetOutputFile(outputFileName);
compressor.EncodeSequenceAudio(Composition.EffectiveProductionAudioFileName);
compressor.Key1 = 12345;
compressor.Key2 = 54321;
(loop to encode frames)


Do you see the error? It was only as I switched between the proof of concept code and my app code in the IDE that I noticed the two following lines moving up and down...

compressor.Key1 = 12345;
compressor.Key2 = 54321;
Once I spotted it the problem was obvious! If I don't set my license key before encoding anything (including audio) it is not going to work. Moving the key up a couple of lines fixed the problem. It was a simple absent minded mistake to have made, but why did it take over a day to solve?

There were so many factors involved. We aren't using the "full edition" of the tool we are using a feature restricted version so we thought it might be that for a while. Then we thought it might be our settings files. Then their support department kept talking about missing codecs (which made no sense to be honest.) Then there was the fact that in the app it runs in a thread. All sorts of variables that seemed much more likely than a simple 2 line coding error.

The thing is, the EncodeSequenceAudio method returns a bool to indicate success or failure. I hadn't even spotted this. I am so accustomed to experiencing exceptions that I didn't even think to expect a boolean return type. In addition to this the examples that ship with the product don't check for a result either.

Silent errors are evil!