Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Archive for July 2010

Khmer Collation support in SQL Server 2008

leave a comment »

SQL Server ’08 using default collation as “SQL_Latin1_General_CP1_CI_AS” which most/all of us knew that

  • We can store Khmer Unicode (with NVARCHAR, NText etc)
  • Searching Khmer Unicode ? suck !

There are work around if you really want to search content in Khmer Unicode after you stored it; using SQL Server ’08 default collation. How?

Method #1: Try to break each word using hidden space

Method #2: Encoding incoming Khmer Unicode content and stored it as ASCI

It works but it hurt; there is an althernative SQL Server ’08 introduce a few additional collation algorithm among those “Khmer_100” is one of them.

Khmer Collation in SQL Server 2008

That awesome all you have to do is changing your column collation from <default collation> to “Windows Collation -> Khmer_100” that’s it no code isn’t that cool ?

No it’s not cool, It only works if SQL Server install on Windows Vista or Higher.

Edit: actually we can also use this

Written by Chorn Sokun

July 28, 2010 at 10:48 am

Mocking ASP.NET MVC 2 Context & Session using RhinoMock

leave a comment »

Watching video record from #mvcconf about “Making ASP.NET Apps Testable” by Eric B. Sowell. He showing how to test ASP.NET MVC Session make me wonder how difficult it is for RhinoMock so I load sample app and here how I test it. Since

public void TestSession()
   // Arrange
   // HttpContextBase, HttpSessionStateBase are abstract classes
   // I can ask RhinoMock to generate stubs for those classes
   var httpContext = MockRepository.GenerateStub<HttpContextBase>();
   var session = MockRepository.GenerateStub<HttpSessionStateBase>();

   session["Name"] = "Sokun";
   httpContext.Stub(c => c.Session)

   // act
   controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller);
   var result = controller.TestSession() as ViewResult;

   // assert

and the action:

public ActionResult TestSession()
   ViewData["Name"] = Session["Name"];
   return View();

So, what you think? it just fine to love ASP.NET MVC 2

Written by Chorn Sokun

July 26, 2010 at 10:45 am

Me & the Onion Architecture

leave a comment »

Jump into ASP.NET MVC 2 in Action Chapter 23 which talk about an integration of ASP.NET MVC and NHibernate the author introduce us to the Onion Architecture.

Using this architecture we simply structure our solution like:

  • Core, storing POCO & various Interfaces
  • Infrastructure, talking with underline or external system
  • IntegrationTests, generally speaking this would test Infrastructure functionality
  • UI

Let focus on the Infrastructure because it is the main actor in this architecture; the following role given to this layer

  • Mapping between Core class & Database by talking through NHibernate (I agree)
  • Responsible for injecting NHibernate session into web session with NHibernateModule: IHttpModule (I agree)
  • Contain abstract RepositoryBase<T>: IRepository<T> (I agree)
  • Contain all Interfaces  implmentation hmm ? isn’t it too much for an Infrastructure? what about
    • Core
    • Infrastructure
    • Services
    • IntegrationTests
    • UI

I will do more investigation (Pros, Cons) but love to hear your take on this, if you haven’t read the chapter yet do it now.

Written by Chorn Sokun

July 25, 2010 at 2:35 pm

Posted in Uncategorized

Tagged with ,