Skip to content

Instantly share code, notes, and snippets.

@ursenzler
Last active September 9, 2015 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ursenzler/5ef86b4ca1cd776ad3cf to your computer and use it in GitHub Desktop.
Save ursenzler/5ef86b4ca1cd776ad3cf to your computer and use it in GitHub Desktop.

Fake It Easy Specs

Asserting On Set Only Properties

Set Only Properties

  • establish
  • when assertion on set only properties
  • it should be able to assert with argument constraint

Unconfigured Fake

Virtual Method

  • when faking a class with a virtual method
  • it should return a default value when the method is called during the constructor
  • it should return a default value when the method is called after the constructor
  • it should record the method call during the constructor
  • it should record the method call after the constructor

Virtual Properties

  • when faking a class with virtual properties
  • it should return a default value when a reference type property is called during the constructor
  • it should return a default value when a value type property is called during the constructor
  • it should return the value assigned during constructor when a reference type property is gotten after the constructor
  • it should return the value assigned during constructor when a value type property is gotten after the constructor

Creation

Use Successful Constructor

  • when faking a class whose first constructor fails
  • it should instantiate the fake using the successful constructor with the longest parameter list
  • it should instantiate a fake that does not remember the failing constructor call
  • it should only have tried the parameterless constructor and one with the longest parameter list

Throwing Constructor

  • when faking a class whose constructor throws
  • it should throw a FakeCreationException
  • it should throw an exception whose message includes original exception type
  • it should throw an exception whose message includes original exception message
  • it should throw an exception whose message includes original exception stack trace

Property

Setting Indexed Property For Different Indexes

  • establish
  • when setting the value of an indexed property for different indexes
  • it should return the correct value for the first indexes
  • it should return the correct value for the second indexes

Setting Indexed Property

  • establish
  • when setting the value of an indexed property
  • it should return the value to the getter with same indexes
  • it should return the same instance each time the getter is called with those indexes
  • it should return the default value to getters with different indexes
  • it should return the same instance each time the getter is called with other indexes

Getting Unconfigured Fakeable Property

  • establish
  • when getting the value of an unconfigured fakeable property
  • it should not return null
  • it should return the same instance on a subsequent get

Getting Unconfigured Unfakeable Property

  • establish
  • when getting the value of an unconfigured unfakeable property
  • it should not return null if dummy can be made
  • it should return the same instance on a subsequent get

Calls Base Methods Fake

Abstract Method

  • establish
  • when abstract method is called on fake that calls base methods
  • it should return default value

Concrete Method

  • establish
  • when concrete method is called on fake that calls base methods
  • it should call base method

Faking Internals

Invisible Internals

  • when trying to fake invisible internals
  • it should throw an exception with a message containing a hint at using internals visible to attribute

Override Internal Method

  • establish
  • when trying to override internal method on type
  • it should throw an exception with a message complaining about accessibility

Generic Type With Internal Type Parameters

  • when trying to fake generic type with internal type parameters
  • it should throw an exception with a message containing a hint at using internals visible to attribute

Self Initialized Fakes

Self Initializing With File Recorder

  • establish
  • when self initializing a fake with a FileRecorder
  • it should return the expected result while recording
  • it should return the recorded result during playback

Self Initializing

  • establish
  • when self initializing a fake
  • it should forward calls to the wrapped service while recording
  • it should return the result while recording
  • it should not forward calls to the wrapped service during playback
  • it should return the recorded result for the first set of arguments
  • it should return the recorded result for the second set of arguments
  • it should return the second recorded result when arguments are repeated

Configuration

Multiple Callbacks

  • establish
  • when configuring multiple callback
  • it should call the first callback
  • it should call the second callback
  • it should return the configured value

Callback

  • establish
  • when configuring callback
  • it should invoke the callback

Call Base Method

  • establish
  • when configuring to call base method
  • it shuld have called the base method
  • it should return value from base method
  • it should invoke the callback

Fixture Initialization

Initialization

  • establish
  • when initializing fixture
  • it should set sut
  • it should use the same instance when more than one dependency is of the same type
  • it should inject fake from fixture
  • it should inject fake when not available in fixture

Event Raising

Action Event

  • when raising action event passing arguments
  • it should pass the first argument
  • it should pass the second argument

Sender And Event Arguments

  • when raising event passing sender and arguments
  • it should pass the sender
  • it should pass the event arguments

Value Type Event Handler With Null Value

  • when raising value type event passing null argument
  • it should fail with good message

Unsubscribed Event

  • when raising unsubscribed event
  • it should not throw

With Empty

  • when raising event using WithEmpty
  • it should pass the fake as sender
  • it should pass empty event arguments

Event Arguments

  • when raising event passing arguments
  • it should pass the fake as sender
  • it should pass the event arguments

Reference Type Event Handler With Derived Arguments

  • when raising reference type event passing derived arguments
  • it should pass the event arguments

Sender And Custom Event Arguments

  • when raising generic event passing sender and arguments
  • it should pass the sender
  • it should pass the event arguments

Multiple Subscribers

  • establish
  • when raising event with multiple subscribers
  • it should invoke the first handler once
  • it should invoke the second handler once

Reference Type Event Handler With Invalid Argument Type

  • when raising reference type event passing invalid argument type
  • it should fail with good message

Null Sender And Event Arguments

  • when raising event passing arguments and null sender
  • it should pass null as the sender
  • it should pass the event arguments

Reference Type Event Handler

  • when raising reference type event passing arguments
  • it should pass the event arguments

Custom Event Arguments

  • when raising generic event passing arguments
  • it should pass the fake as sender
  • it should pass the event arguments

Null Sender And Custom Event Arguments

  • when raising generic event passing arguments and null sender
  • it should pass null as the sender
  • it should pass the event arguments

Custom Event Handler

  • when raising custom event passing sender and arguments
  • it should pass the sender
  • it should pass the event arguments

Async Await

Defined Method With Return Value

  • establish
  • when calling defined method with return value
  • it should return

Undefined Void Method

  • establish
  • when calling undefined void method
  • it should return

Undefined Method With Return Value

  • establish
  • when calling undefined method with return value
  • it should return

Defined Void Method

  • establish
  • when calling defined void method
  • it should return

Strict Fake

Repeated Assertion

  • establish
  • when asserting must have happened when did not happen
  • it should throw an expectation exception
  • it should have an exception message containing the name of the method

Fake Scope

Call From Constructor

  • establish
  • when configuring a method called by a constructor from within a scope
  • it should call ConfigureFake of the fake scope
  • it should return the configured value within the scope during the constructor
  • it should return the configured value within the scope after the constructor
  • it should return default value outside the scope

Dummy Factory

Dummy Factory Usage

  • when a dummy factory is defined for a set of types
  • it should create a dummy from the factory

Dummy Factory Priority

  • when two dummy factories apply to the same type
  • it should use the one with higher priority

Lazy

Lazy Return Value

  • establish
  • when calling a method that returns a lazy
  • it should return a lazy
  • it should return a lazy whose value is a dummy

Fake Configurator

Defined Fake Configurator

  • when a fake configurator is defined for a set of types
  • it should configure the fake

Fake Configurator Priority

  • when two fake configurators apply to the same type
  • it should use the one with higher priority

During Construction

  • when configuring a method called by a constructor
  • it should use the configured behavior in the constructor

Ordered Call Matching

Non Generic Calls

  • establish
  • when failing to match ordered non generic calls
  • it should tell us that the call was not matched

Generic Calls

  • establish
  • when failing to match ordered generic calls
  • it should tell us that the call was not matched

Creation Options

Configure Fake Overrides Fake Configurator

  • when ConfigureFake is used to configure a method also configured by a FakeConfigurator
  • it should use the configured behavior from the ConfigureFake

Calls Base Methods Overrides Configure Fake

  • when ConfigureFake followed by CallsBaseMethods are used to configure a fake
  • it should call base method

Multiple Wrapping Configurations

  • when Wrapping is used to configure a fake twice
  • it should delegate to the last wrapped instance

With Arguments For Constructor With Example Constructor

  • when WithArgumentsForConstructor is used to create a fake with an example constructor
  • it should create a fake using the supplied arguments

Calls Base Methods Overrides Wrapping

  • when Wrapping followed by CallsBaseMethods are used to configure a fake
  • it should call base method

Multiple With Additional Attributes Configurations

  • when WithAdditionalAttributes is used to configure a fake twice
  • it should produce a fake that has all of the attributes

With Additional Attributes And Null Set Of Attributes

  • when WithAdditionalAttributes is used to configure a fake with a null set of attributes
  • it should throw an argument null exception

Strict Overrides Wrapping

  • when Wrapping followed by Strict are used to configure a fake
  • it should throw an exception from a method call

Multiple Configure Fake Configurations

  • when ConfigureFake is used twice to configure a method
  • it should apply each configuration in turn

Calls Base Methods Overrides Strict

  • when Strict followed by CallsBaseMethods are used to configure a fake
  • it should call base method

Wrapping

  • when Wrapping is used to configure a fake that has a FakeConfigurator
  • it should delegate to the wrapped object

Wrapping During Construction

  • when Wrapping is used to configure a fake
  • it should delegate to the wrapped instance during the constructor
  • it should delegate to the wrapped instance after the constructor

With Additional Attributes

  • when WithAdditionalAttributes is used to configure a fake
  • it should produce a fake that has the attribute

Calls Base Methods During Construction

  • when CallsBaseMethods is used to configure a fake
  • it should call base method during the constructor
  • it should call base method after the constructor

Wrapping Combined With Configure Fake

  • when Wrapping followed by ConfigureFake are used to configure a fake
  • it should use the configured behavior during the constructor
  • it should use the configured behavior after the constructor

Strict During Construction

  • when Strict is used to configure a fake
  • it should throw an exception from a method call during the constructor
  • it should throw an exception from a method call after the constructor

Strict Overrides Configure Fake

  • when ConfigureFake followed by Strict are used to configure a fake
  • it should throw an exception from a method call

With Arguments For Constructor

  • when WithArgumentsForConstructor is used to create a fake with a list of arguments
  • it should create a fake using the supplied arguments

Wrapping Overrides Calls Base Methods

  • when CallsBaseMethods followed by Wrapping are used to configure a fake
  • it should delegate to the wrapped instance

Configure Fake During Construction

  • when ConfigureFake is used to configure a method
  • it should return the configured value during the constructor
  • it should return the configured value after the constructor

Strict Overrides Calls Base Methods

  • when CallsBaseMethods followed by Strict are used to configure a fake
  • it should throw an exception from a method call

Wrapping Overrides Strict

  • when Strict followed by Wrapping are used to configure a fake
  • it should delegate to the wrapped instance

Wrapping Overrides Configure Fake

  • when ConfigureFake followed by Wrapping are used to configure a fake
  • it should delegate to the wrapped instance during the constructor
  • it should delegate to the wrapped instance after the constructor

Configure Fake Overrides Calls Base Methods

  • when CallsBaseMethods followed by ConfigureFake are used to configure a fake
  • it should use behavior defined by ConfigureFake

Multiple Implements Configurations

  • when Implements is used to configure a fake twice
  • it should produce a fake that implements both interfaces

Implements

  • when Implements is used to configure a fake
  • it should produce a fake that implements the interface

Strict Combined With Configure Fake

  • when Strict followed by ConfigureFake are used to configure a fake
  • it should return the configured value during the constructor
  • it should return the configured value after the constructor

Multiple With Arguments For Constructor Configurations

  • when WithArgumentsForConstructor is used to create a fake twice
  • it should create a fake using the last set of supplied arguments

Call Matching

Out Parameter

  • establish
  • when matching a call with an out parameter
  • it should match without regard to out parameter value
  • it should assign the constraint value to the out parameter

Parameter Arrays

  • establish
  • when matching calls with parameter arrays
  • it should be able to match the call
  • it should be able to match the call with argument constraints
  • it should be able to match the call mixing constraints and values
  • it should be able to match using array syntax

No Generic Calls

  • establish
  • when no generic calls
  • it should tell us that the call was not matched

Failing Match Of Generic Calls

  • establish
  • when failing to match generic calls
  • it should tell us that the call was not matched

No Non Generi Calls

  • establish
  • when_no_non_generic_calls
  • it should tell us that the call was not matched

Ref Parameter

  • establish
  • when matching a call with a ref parameter
  • it should match when ref parameter value matches
  • it should not match when ref parameter value does not match
  • it should assign the constraint value to the ref parameter

Parameter Having An Out Attribute

  • establish
  • when matching a call with a parameter having an out attribute
  • it should match when ref parameter value matches
  • it should not match when ref parameter value does not match

Failing Match Of Non Generic Calls

  • establish
  • when failing to match non generic calls
  • it should tell us that the call was not matched

Failing Match Of Out Parameter

  • establish
  • when failing to match a call with an out parameter
  • it should tell us that the call was not matched

Faking Delegates

Without Configuration

  • establish
  • when faking a delegate type and invoking without configuration
  • it should be possible to assert the call
  • it should be possible to assert the call without specifying invoke method

Throws

  • establish
  • establish
  • when faking a delegate type and invoking with throwing configuration
  • it should throw the configured exception

With Configuration

  • establish
  • establish
  • when faking a delegate type and invoking with configuration
  • it should return configured value

Missing Invoke

  • establish
  • establish
  • when faking a delegate type and invoking with configuration without specifying invoke methode
  • it should return configured value

Assigns Out And Ref Parameters

hen_configuring_a_fake_to_assign_out_and_ref_parameters_lazily_using_call

  • establish
  • when configuring a fake to assign out and ref parameters lazily using call
  • it should assign the conditional value to the out field

Assign Out And Ref Parameters Lazily Using Func

  • establish
  • when configuring a fake to assign out and ref parameters lazily using func
  • it should assign the conditional value to the out field

Assign Out And Ref Parameters Lazily Using Call

  • establish
  • when configuring a fake to assign out and ref parameters
  • it should assign the conditional value to the out field

Disposable

Faking Disposable

  • establish
  • when faking a disposable class
  • it should not throw when finalized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment