Unit testing security
Following on from my previous post about using(Tricks) here is an example which makes writing test cases easier rather than just for making your code nicely formatted. Take a look at the following test which ensures Article.Publish sets the PublishedDate correctly: [TestMethod] public void PublishedDateIsSet() { //Create the EcoSpace, set its PMapper to a memory mapper var ecoSpace = TestHelper.EcoSpace.Create(); //Creat an article var article = new Article(ecoSpace); //Create our Rhino Mocks repository var mocks = new MockRepository(); //Mock the date/time to give us a predictable value var mockDateTimeService = mocks.StrictMock<IDateTimeService>(); ecoSpace.RegisterEcoService(typeof(IDateTimeService), mockDateTimeService); //Get a date/time to return from the mock DateTimeService var now = DateTime.Now; using (mocks.Record()) { //When asked, return the value we recorded earlier Expect.Call(mockDateTimeService.Now).Return(now); } //Check mo