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>
            [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?
  2. Kaloyan
    Admin
    Kaloyan avatar
    872 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>(),
                    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top