Lately

wow, busy lately. Went and saw Nickelback at the Xcel Center on the 14th, that was pretty sweet. Had a house warming on the 16th, that was even sweeter. Now I just need to put my grill together 🙂 I put up some pictures I took right before the party here so check it out. Hopefully things will semi-calm down and I will have more time to post/geek around with projects.

Unit Testing Verisign Payflow Pro with VS2005

When you set up payflow pro on a system, you usually are going to use it through the web, you usually dump the certs folder into the inetsrv folder and it works fine. Thing is, when you are using VS2005 Unit Testing, you arent on the web, you can even try setting an HttpContext, but that still doesnt work, you end up with:

Get error “RESULT=-31&RESPMSG=The certificate chain did not validate, no local certificate found, Cert Path = certs, Working Directory = C:ProjectsMyProjectTestResultsuser.name_COMPUTERNAME DateTimeOut”

before you make your request in your tests, do this:
System.Environment.SetEnvironmentVariable(“PFPRO_CERT_PATH”, “c:certs”, EnvironmentVariableTarget.Process);

Copy your certs directory to your C: drive, or you can set the path wherever – mostly likely you would want to add it to your test project, and then set the path when you setup your environment variable as releative to your project.

When you run your unit tests again, you should see a valid response and the request to Verisign should go through correctly.

Caching got you down? Try an Object Lock

If you are using caching in ASP.net, and when your cache invalidates, you see some really bad performance or race conditions, you probably need to implement object locks.

Object myObjectLock = new object();
//Use the lock statement to ensure that only one request

lock (myObjectLock)
{
//check again if the cache is not populated by another request
if (HttpRuntime.Cache["myCacheKey"] == null)
{
DataTable cacheValue = GetDataFromDatabase();

//remove the cache key
HttpRuntime.Cache.Remove("myCacheKey");

//insert into the cache
HttpRuntime.Cache.Insert("myCacheKey", cacheValue, null, DateTime.Now.AddHours(8), TimeSpan.Zero);
}
}

Now, when your cache is rebuilt, you will avoid race conditions and bad performance on your site/database.