2

I'm currently implementing System.Activties.Presentation.View.IExpressionEditorService to provide a custom expression editor.

The problem is, that I don't know how to properly test the method CreateExpressionEditor, which is declared by the interface, as the first two parameters are sealed types that I can't mock.

Stubbing is also not an option, as this would require me to properly set them up with other values, which in the end means that I also could just create an instance of the workflow designer and try to get the values from there. This smells like something I shouldn't do.

Any hints, tricks, pointers are very welcome.

Best regards,
Daniel


The interface is declarared as follows, I copied it from the official Microsoft reference source repository.

//------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------

namespace System.Activities.Presentation.View
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Controls;
    using System.Activities.Presentation.Model;
    using System.Activities.Presentation.Hosting;
    using System.Windows;

    public interface IExpressionEditorService
    {
        IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text, Type expressionType);
        IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text, Type expressionType, Size initialSize);
        IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text);
        IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text, Size initialSize);
        void CloseExpressionEditors(); // Closes all editors
        void UpdateContext(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces);
    }
}
2coder
  • 21
  • 4
  • 1
    A possible workaround might be something like [the solution described in this answer](https://stackoverflow.com/a/30200039/2846483), but it doesn't integrate well with Moq. – dymanoid Mar 09 '20 at 15:35
  • Very much appreciated @dymanoid. – 2coder Mar 09 '20 at 16:14

0 Answers0