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

MockTable.FromType does not work with "getter-only" property. #25

Open
Becold opened this issue May 26, 2021 · 0 comments
Open

MockTable.FromType does not work with "getter-only" property. #25

Becold opened this issue May 26, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@Becold
Copy link

Becold commented May 26, 2021

Hi,

I'm using the MockTable.FromType method but it crash with a "getter-only" property.

My use case:

_services.DbMocks.WhenTag("MY_TAG").ReturnsTable(MockTable.FromType(new[] {
    new MockedA()
    {
        MyLabel = "Mocked sample A",
        MyOtherLabel = "Mocked sample B"
    }
}, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance));

class A 
{
    public string MyLabel { get; set; } = string.Empty;
    public string ReadOnlyLabel => MyLabel;
}

class MockedA : A
{
    public string MyOtherLabel { get; set; } = string.Empty;
}

The stack trace :

  Message: 
    System.ArgumentException: Property set method not found.
  Stack Trace: 
    RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
    RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
    DataRowConvertor.ToType[T](DataRow row)
    DataRow.MapTo[T]()
    <>c.<GetMyObjectsByProfileIds>b__28_0(DataRow row) line 1190
    <>c__DisplayClass19_0`1.<ExecuteTableAsync>b__1(DataRow row)
    SelectArrayIterator`2.MoveNext()
    Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
    Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
    DataTableConvertor.ToDataTable(IEnumerable`1 rows)
    DataTableConvertor.ToDataTable(Object value)
    DatabaseCommand.ExecuteInternalCommandAsync[T](Func`1 action)
    DatabaseCommand.ExecuteTableAsync[T](Func`2 converter)
@dvoituron dvoituron added the bug Something isn't working label May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants