Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageEditor.EditValue for an invalid provider can throw InvalidCastException #762

hughbe opened this Issue Apr 13, 2019 · 1 comment


None yet
2 participants
Copy link

hughbe commented Apr 13, 2019


using Moq;

public static IEnumerable<object[]> EditValue_InvalidProvider_TestData()
    yield return new object[] { null };

    var nullServiceProviderMock = new Mock<IServiceProvider>(MockBehavior.Strict);
        .Setup(p => p.GetService(typeof(IWindowsFormsEditorService)))
    yield return new object[] { nullServiceProviderMock.Object };

    var invalidServiceProviderMock = new Mock<IServiceProvider>(MockBehavior.Strict);
        .Setup(p => p.GetService(typeof(IWindowsFormsEditorService)))
        .Returns(new object());
    yield return new object[] { invalidServiceProviderMock.Object };

public void EditValue_InvalidProvider_ReturnsValue(IServiceProvider provider)
    var editor = new FontEditor();
    var value = new object();
    Assert.Same(value, editor.EditValue(null, provider, value));

If the service is not IWindowsFormsEditorService then an InvalidCastException is thrown.

Proposed fix is to use an as cast

@hughbe hughbe referenced a pull request that will close this issue Apr 16, 2019


Add ImageEditor tests #810

@dreddy-work dreddy-work added this to the Future milestone Apr 19, 2019


This comment has been minimized.

Copy link

dreddy-work commented Apr 19, 2019

@hughbe , can you please create seperate PR for each issue ? It would help us review them easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.