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

Open
hughbe opened this Issue Apr 13, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@hughbe
Copy link
Contributor

hughbe commented Apr 13, 2019

E.g.

using Moq;

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

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

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

[Theory]
[MemberData(nameof(EditValue_InvalidProvider_TestData))]
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

Open

Add ImageEditor tests #810

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

@dreddy-work

This comment has been minimized.

Copy link
Member

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.