house9

random code and what not

Update: FireFox and multiple cookies for the same site

well after a few days with CookieSwap it seems a bit buggy, basically if you open two browser instances and then switch the CookieSwap profile it is updating both browser instances making it somewhat useless?

so I did some more googling and now using this technique

Initial Setup
- close all instances of firefox
- Start -> Run -> firefox.exe -ProfileManager
- create 5 or so profiles, I named them p1 - p5

Then when you want to use different profiles launch each one from the command line
- Start -> Run -> firefox.exe -P p1 -no-remote

each profile is totally distinct (history, cookies, etc…), only issue there does not seem to be an easy way to tell which profile you currently have open, I think I can live with that

Comments

Anonymous
You can use different skins in different profiles to distinguish them easily.
kinjal
maybe someone can write a firefox addon which displays the profile name in the title. maybe i can do this.

NAnt build with TFS changeset as revision number

This code sample is a nant script that
  • deletes the CommonAssembly.cs file (linked to all projects)
  • uses the nant asminfo task to recreate the CommonAssembly.cs file, but after we query TFS for the changeset (revision) number which is used in the version number
  • build the solution in release mode using the ide.exe (there are other - better ways, but this one works)
  • xcopy files to C:\temp\{app} and clean up all the source files

basically I just put together a few bits that I found on other blogs (should have saved the urls - doh!), most were related to using svn for source control and then I added in the code block for the c# stuff to query TFS.

A quick note about the linked CommonAssembly.cs file, visual studio has an option when you are adding an existing file to a project to select ‘linked’, click the arrow on the ‘Add’ button when you select your existing file

what this script does not do - get latest from TFS, I usually do that part manually or from ccnet



the c# bit that goes in the nant script block above
NOTE: see updated version of this code block



nant is awesome!

Comments

juho
Seems that this solution doesn't work with TFS2010, but thanks for the idea, I'll use it as a base for my project :)
Mahendra Mavani
I was looking for this solution, since long. Thanks for providing this sample. It works great on my project

FireFox and multiple cookies for the same site

I like FireFox but still use IE most of the time; one of the main reasons is during web application development I need to login to the same web application as different users at the same time, switching back and forth between each user account. IE makes it easy just open a new instance for each individual user account.

In the past I tried to find a solution for FireFox, but always came up short. Well today I did a google search and came up with two different ones!

both are FireFox extensions

after a quik spin with both I am liking CookieSwap better

With CookiePie you right click on the individual tab to toggle seperate cookie sessions on or off; just didn’t have good luck using it the way I would do stuff with IE

With CookieSwap you right click in the lower right hand status bar area of FireFox and can toggle between named profiles (default is Profile1, Profile2, Profile3) - this worked right out of the box as I would expect!

SyntaxHighlighter and Google Blogger

Just started using the SyntaxHighlighter on my code samples blog - here is some quick notes on what I had to do

One issue I ran into was that the google blogger automatically adds br tags where newlines appear in any content - makes the code pretty much unreadable, but the fix is well documented and easy to implement - http://code.google.com/p/syntaxhighlighter/wiki/BloggerMode

Rhino.Mocks - the basics

Started using Rhino.Mocks recently (Awesome!!!) - just wanted to list a few of the basics; the official Rhino Mocks Documentation is very good and available here. These examples are a bit rough, they have not been compiled; there may be typos.

using
using Rhino.Mocks;

The mock repository
// use the mock repository to create the mocked objects
MockRepository mocks = new Rhino.Mocks.MockRepository();
// example
System.Object someObject = mocks.CreateMock();
// set up the behaviour you want from calls to your mocked object
Rhino.Mocks.Expect.Call(someObject.Equals(someParameter)).Return(false);
// then don't forget
mocks.ReplayAll();
// now do stuff that calls your mocked object Equals method
...

Mock a call to the db
// create our mocked repository object - IProductRepository, the real one calls the db
IProductRepository repository = mocks.CreateMock();
// tell rhino.mocks when we call the method GetProduct with the argument 33 to return null
Rhino.Mocks.Expect.Call(repository.GetProduct(33)).Return(null);
// get the mocking ready
mocks.ReplayAll();
// pass our mock to our product service layer
ProductService service = new ProductService(repository);
// service.GetProduct makes a call to the mocked repository.GetProduct which will return null
IProduct product = service.GetProduct(33);
// should be null
Assert.IsNull(product);

Ignore any arguments
// any call to GetProduct will return null no matter the value of the arg
Rhino.Mocks.Expect.Call(repository.GetProduct(null)).Return(null).IgnoreArguments();

mock a method that returns void
IProduct product = new Product("003092", "Sierra Nevada", 6.49);
// this void call will handle our product 003092
Rhino.Mocks.Expect.Call(delegate { repository.Save(product); });
// this void call will handle any argument
Rhino.Mocks.Expect.Call(delegate { repository.Save(null); }).IgnoreArguments();

Handle multiple calls to the same method
IProduct product = new Product("003092", "Sierra Nevada", 6.49);
// note the .Repeat.Any()
Rhino.Mocks.Expect.Call(repository.GetProduct("003092")).Return(product).Repeat.Any();
// send the mock to our product service object
ProductService service = new ProductService(repository);
// find by sku calls GetProduct on the mocked Product repository
IProduct beer = service.FindBySku("003092");
// find decent beer calls GetProduct on the mocked Product repository also
IProduct decentBeer = service.FindDecentBeer();

Partial Mock
// create a partial mock with constructor args (our product repository again)
IProductService service = mocks.PartialMock(repository);
// our test case data
IUser loggedOnUser = new User("John", "Doe", CustomerType.Gold);
// mock product service calls to GetLoggedOnUser
Rhino.Mocks.Expect.Call(service.GetLoggedOnUser()).Return(loggedOnUser);
// get the mocking ready
mocks.ReplayAll();
// now GetDiscount is not a mocked method but it does call the mocked GetLoggedOnUser method
decimal discount = service.GetDiscount();
// assert the result
Assert.AreSame(44.4M, discount, "Gold customer discount not correct?");
// NOTE: this will not work (compile) unless the mocked method GetLoggedOnUser is public

Comments

House 9
Had an issue with comment moderation
————————————-

New Day posted this about a month ago

For the Equals method I get the same error as ben.biddington. I am using .NET 2.0
The error occurs on the line with Expect.Call so it does not proceed any further down the test.

Error
"Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method)."
Anonymous
IProduct product = new Product("003092", "Sierra Nevada", 6.49);

Lär ju gå bra att instansiera ett interface, nötter…
Anonymous
In 3.5 CreateMock is deprecated and should be changed to StrictMock. Might want to try that,
House 9
I have not tried it on 3.5 of .net but I believe it should work. Is it possible you are making multiple calls to the same mocked method? you might need a .Repeat.Any();
ben.biddington
Hi,

Does you first example (The mock repository) work with v.3.5?

I get the error:

Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).

Rails like migrations in the .NET world

I have done a few very small projects with rails; one of the really nice features with rails is database migrations

There are a few ports of rails migrations to the .NET world (that’s where I spend alot of my time). I have not used any of these for ‘real’ but I have ‘sampled’ them. They all look promising but it seems like there is not very much activity on these projects.

Migratordotnet
http://code.google.com/p/migratordotnet/

RikMigrations
http://www.rikware.com/RikMigrations.html

SubSonic Migrations
I don’t know if they ever did incorporate this into the official release of sub sonic? maybe it will come in a future release
http://blog.wekeroad.com/2007/10/03/subsonic-migrate-me/

I recently stumbled across vincent-vega and have begun using it on a small project and am planning to incorporate it into some of our larger applications. It is an Nant task that handles database versioning. It is not a migration in the same way as the other solutions as it uses actual sql scripts for all schema changes instead of c# code, which makes sense to me!

Vincent-Vega
[update 2008/10/14]
vincent-vega is now part of the tarantino project.
http://code.google.com/p/tarantino/
Thanks for the heads up Dan!
[/update]

 

Comments

Dan Nuttall
vincent-vega is now part of the tarantino project. I know you mentions it in a later post, but it took me forever to find it!

http://code.google.com/p/tarantino/

mssql reporting services - logs

a while back I had to set up reporting services; most of the errors do not get logged to the event log, instead they are logged to a file:

{drive}\Program Files\Microsoft SQL Server\{instance}\Reporting Services\LogFiles