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

FontEditor.EditValue for an invalid provider can throw InvalidCastException #761

hughbe opened this Issue Apr 13, 2019 · 0 comments


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 13, 2019


Add FontEditor tests, fix bugs and debug asserts #760

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

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.