Help with Mock.Arrange public method

2 posts, 0 answers
  1. Javier
    Javier avatar
    10 posts
    Member since:
    Apr 2013

    Posted 22 May 2013 Link to this post

    Hi I would like to test this piece of code:

    /// <summary>
        /// Represents the Automatic Warehouse add in
        /// </summary>
        ///  /// <seealso cref=""/>
        public class AutomaticWarehouseKpiAddInn: IKeyPerformanceIndicatorAddIn
            /// <summary>
            /// Gets or sets the configuration extension service.
            /// </summary>
            public IConfigurationExtensionService ConfigurationExtensionService { get; set; }
            public void Initialize()
                                                                 new AutomaticWarehouseCommanderConveyorConfigConverter());

    And I tried to test it like this:

          public void InitializeRegisterExtensionCorrectly()
              IConfigurationExtensionService configurationExtensionService = Mock.Create<ConverterConfigurationBuilder>();
              AutomaticWarehouseKpiAddInn automaticWarehouseKpiAddInn = new AutomaticWarehouseKpiAddInn
                      ConfigurationExtensionService = configurationExtensionService
              Mock.Arrange(() => configurationExtensionService.RegisterExtension(null, null)).MustBeCalled();

    What I am doing wrong?
  2. Kaloyan
    Kaloyan avatar
    880 posts

    Posted 23 May 2013 Link to this post

    Hi Javier,

    I assume you will need to pass correctly matching arguments in the arrange. For example, if your RegisterExtension method is implemented like so:
    void RegisterExtension(Type automaticWarehouseCommanderAddInConfiguration,
                AutomaticWarehouseCommanderConveyorConfigConverter aWCCCC);
    You will need to change the null arguments in the arrange with matchers:
    Mock.Arrange(() => configurationExtensionService.RegisterExtension(Arg.IsAny<Type>(),

    Another approach is to completely ignore the arguments in the arrange:
    Mock.Arrange(() => configurationExtensionService.RegisterExtension(null, null))

    I hope this helps. Contact us again if you need further assistance.

    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Back to Top