• Customize SharePoint content page with control

    Sharepoint content page can be loaded with custom control, web part and user control. In uncustomized page mode, there is no special requirement for these control. In customized mode, there are some security restriction, they need to be declare as safe control in web.config file. To declare a user control to be safe control, we need to use following syntax in web.config

  • Create a stub with

    A stub can also be created using Mocking frameworks. Semantically speaking, a stub is a simulated object, just like a mock object, that will support our test so that we can test other things. In short, a stub will always make “happy noises” when being called, and can never be used to see if the test passed or not. Calling VerifyAll() will not verify anything against stub objects. Only against mocks. Most Mocking frameworks contain the semantic notion of a stub and RhinoMocks is no exception.

  • Strict Mork vs Non-strict mork

    A strict Mock Object will only allow calling methods on it that were explicitly set via Expectations. Any call that is made which either differs by the parameter values defined, or by the method name, will usually be handled by throwing an exception while the method is being called. That means the test fails on the first unexpected method call to a strict mock object.

  • An Example of Mock

     [Test] 
    Public void Analyze_TooShortFileName_ErrorLoggedToService() 
    { 
    MockRepository mocks = new MockRepository(); 
    IWebService simulatedService =  
    mocks.CreateMock(); 
     
    //pre-arrange setting
     using(mocks.Record()) 
     { 
        simulatedService.LogError("file name was too short "); 
     } 
     
    //play
        LogAnalyzer log = new LogAnalyzer(simulatedService); 
          string tooShortFileName="abc.ext"; 
          log.Analyze(tooShortFileName); 
    
    
  • The difference between mocks and stubs

    Stubs can’t fail tests. Mocks can do (or they’d be called Stubs). Stubs simply replace an object so that we can test the object under test without problems. The easiest way to tell we are dealing with a Stub is to notice that the Stub can never ever fail the test. The asserts the test uses are always against the class under test. When using Mocks, on the other hand, The test will use the Mock object to verify if the test failed or not. Again, when using a Mock, the Mock object is the object that we use to see if the test failed or not.