How do you mock the session object collection using Moq

I started with Scott Hanselman’s MVCMockHelper, added a small class and made the modifications shown below to allow the controller to use Session normally and the unit test to verify the values that were set by the controller. /// <summary> /// A Class to allow simulation of SessionObject /// </summary> public class MockHttpSession : HttpSessionStateBase … Read more

Random data in Unit Tests?

There’s a compromise. Your coworker is actually onto something, but I think he’s doing it wrong. I’m not sure that totally random testing is very useful, but it’s certainly not invalid. A program (or unit) specification is a hypothesis that there exists some program that meets it. The program itself is then evidence of that … Read more

Persist Data by Programming Against Interface

Your repository should accept BankAccount – not IBankAccount because Linq-to-sql doesn’t know what is IBankAccount and compiler doesn’t allow you to store it without casting it first to BankAccount (that can obviously fail at runtime if IBankAccount instance is not a BankAccount). Once you have BankAccount you simply call: Context.BankAccounts.Add(account); Context.SubmitChanges();

test a file upload using rspec – rails

You can use fixture_file_upload method to test file uploading: Put your test file in “{Rails.root}/spec/fixtures/files” directory before :each do @file = fixture_file_upload(‘files/test_lic.xml’, ‘text/xml’) end it “can upload a license” do post :uploadLicense, :upload => @file response.should be_success end In case you were expecting the file in the form of params[‘upload’][‘datafile’] it “can upload a license” … Read more