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

FileNameEditor.EditValue for an invalid provider can throw InvalidCastException #763

hughbe opened this Issue Apr 13, 2019 · 0 comments


None yet
1 participant
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 FileNameEditor();
    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

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.