chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
NMock has a method called ExpectNoCall(), and I could not find a same in TypeMock. Does it exist? I'm testing some code generating attributes for Boo, and I want to make sure that a certain method does not get called.

Thank You.
asked by Dog_Soldier (3.1k points)

4 Answers

0 votes
NMock has a method called ExpectNoCall(),
...
and I want to make sure that a certain method does not get called.


Hi,
In TypeMock just set the method to be Strict. When a method is strict ONLY the expected calls are allowed, any call that is not expected will fail the tests.

Example:
      // mock TestedClass
      Mock theMock = MockManager.Mock(typeof(TestedClass)); 
      // set up our expectations - Only ONE call to Boo 
      theMock .ExpectCall("Boo");
      
      // Set method to strict - if Boo is called more then once the test will fail  
      // All other methods are not strict
      theMock.MethodSettings("Boo").IsStrict = true;
answered by scott (32k points)
0 votes
Thanks. Boo is not a method :D. It is a programming language: http://boo.codehaus.org/.
answered by Dog_Soldier (3.1k points)
0 votes
Boo is not a method :D. It is a programming language.

Wooops :oops:

So are you writting the tests in Boo as well?
answered by scott (32k points)
0 votes
Yes. TypeMock works as long as you force nant to use .NET 1.1. Because Boo is open source, and you have access to the pipeline, you can do really cool stuff with it to save you from coding. You can write macros and attributes that generate code. Right now, I'm developing the Boo.Lang.Useful.dll.

Boo.Lang.Useful.Attributes.AsyncMethodAttribute:

[AsyncMethod]
def Foo():

Generates:

def BeginFoo()
def EndFoo()


Boo.Lang.Useful.Attributes.SingletonAttribute:

[Singleton]
class Foo:
...
foo = Foo.Instance


Boo.Lang.Useful.Attributes.DisposableAttribute:
This one is big and the most useful.

[Disposable]
class Foo:


It generates all of this:

/*
class DisposableObject(IDisposable):
"""
Example of the IDisposable pattern.
"""
   _disposed   as bool
   _diposeLock as object
   
   def DoSomething():
      if _disposed:
         raise ObjectDisposedException(self.GetType().Name, "Resources.ObjectDisposedExceptionMessage"))
      
      # Do work.
   
   def destructor():
      Dispose(false)
   
   def Dispose():
      Dispose(true)
      GC.SuppressFinalize(self)
   
   
      I/O-stype dispose.
      
      def IDisposable.Dispose():
         Close():
   
      def Close():
         Dispose(true)
         GC.SuppressFinalize(self)
   
      
   protected virtual def Dispose(disposing as bool):
      lock _disposeLock: # thread safety
         if not _disposed:
            if disposing:
               # Free managed resources
               
               for each disposable field in self:
                  field.Dispose()
            else:
               # Free unmanaged resources (finalize-time code).
               
            _disposed = true

class DerivedDisposableObject(DisposableObject):
"""
Example of the IDisposable pattern continued.
"""
   def DoSomethingElse():
      if _disposed:
         raise ObjectDisposedException(self.GetType().Name, "Resources.ObjectDisposedExceptionMessage"))
      
      # Do work.
      
   protected override def Dispose(disposing as bool):
      lock _disposeLock: # thread safety
         if not _disposed:
            if disposing:
               # Free managed resources
               
               for each disposable field in self:
                  field.Dispose()
            else:
               # Free unmanaged resources (finalize-time code).
            
            super.Dispose(disposing)
            _disposed = true
*/


Boo.Lang.Useful.Macros.FireAndForgetMacro:
It will take care of calling EndSomething().

fireAndForget foo.BeginSomething(arg1, arg2, ...)


There are also some ideas for interface implementation attributes (http://groups-beta.google.com/group/boolang/browse_thread/thread/f6f8cfd700c124a6/482880f6df1636ce#482880f6df1636ce).

The language is very wrist friendly. With Boo.Lang.Useful.dll and the user's macros/attributes, it can be even friendlier.
answered by Dog_Soldier (3.1k points)
...