This is a migrated thread and some comments may be shown as answers.

Help with Mock.Arrange public method

1 Answer 14 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Javier
Top achievements
Rank 2
Javier asked on 22 May 2013, 03:55 PM
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>
        [Dependency]
        public IConfigurationExtensionService ConfigurationExtensionService { get; set; }
  
        public void Initialize()
        {
            ConfigurationExtensionService.RegisterExtension(typeof(AutomaticWarehouseCommanderAddInConfiguration),
                                                             new AutomaticWarehouseCommanderConveyorConfigConverter());
        }
    }

And I tried to test it like this:

  
[TestMethod]
      public void InitializeRegisterExtensionCorrectly()
      {
          IConfigurationExtensionService configurationExtensionService = Mock.Create<ConverterConfigurationBuilder>();
 
          AutomaticWarehouseKpiAddInn automaticWarehouseKpiAddInn = new AutomaticWarehouseKpiAddInn
              {
                  ConfigurationExtensionService = configurationExtensionService
              };
          Mock.Arrange(() => configurationExtensionService.RegisterExtension(null, null)).MustBeCalled();
          automaticWarehouseKpiAddInn.Initialize();
 
          Mock.Assert(configurationExtensionService);
      }


What I am doing wrong?

1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 23 May 2013, 08:02 AM
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>(),
                Arg.IsAny<AutomaticWarehouseCommanderConveyorConfigConverter>()))
                .MustBeCalled();

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

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

Regards,
Kaloyan
Telerik
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.
Tags
General Discussions
Asked by
Javier
Top achievements
Rank 2
Answers by
Kaloyan
Telerik team
Share this question
or