realm-dotnet: Can't set a property of a RealmModel in 0.81.0
Goal
The goal is to be able to unit test my PCLs without deploying to the device for faster test time.
In 0.78.1 we were able to new up a class overriding RealmObject, however we are unable to do so in 0.81.0.
This blocks us from upgrading the version since we are entirely unable to test our entire data access layer.
Expected Results
I should be able to:
- Mock the Realm object #537
- Either mock (#529) or create and manipulate RealmModels that are pointing to the “bait” nuget package without having exceptions.
Actual Results
In 0.78.1 I am able to new up a RealmModel, set properties to it and use it in my mocks, while mocking a wrapper layer around the Realm object as a workaround on #537.
In 0.81.0 when setting a property in the unit tests the object checks if it is managed, throwing an exception because of an unimplemented method in the “bait” nuget.
Steps & Code to Reproduce
Write a nunit project in Xamarin studio that uses the bait Realm nuget package to test the business logic of your app.
New an object that extends RealmObject and set a property to it.
Using 0.78.1 the code will work, using 0.81.0 it fails.
Code Sample
// Model
public class Person : RealmObject
{
public string Name { get; set; }
}
// Failing unit test
[Test]
public void Test_PersonCreation()
{
new Person { Name = "This fails on 0.81.0, but not on 0.78.1" }
}
Version of Realm and tooling
Realm version(s): 0.78.1 works, 0.81.0 fails
Xamarin Studio version: 6.1.2
Which operating system version and device: Nunit projects running on an iMac and Windows 10 against the bait nuget package.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 29 (10 by maintainers)
As I fear this discussion might get too big and distract us from the original issue, I extracted the gist of it in #1065. @joseprl89 we’ll try to get this sorted and if it’s urgent for you (e.g. there are features in 0.81.0 that you need, but can’t use due to this issue), we can provide you with a nightly build once we merge the fix.
Regarding inheritance, it is high on our backlog, but there are a lot of moving parts required to support it, so we’re still evaluating how to provide a lot of value (e.g. being able to write queries) without the complexity exploding 😅 Still, I am fairly confident that the first iteration will still have
RealmObject
in the root.Finally, in terms of testing, there are multiple approaches and we haven’t spent enough time evaluating them to confidently say which one is the best. We could go with an interface, or a mockable set of classes similar to this one that you’ll be able to use as a drop-in replacement for the real ones. The more feedback we get from you folks, the better informed decision we’ll be able to make when we get to cracking that problem, so keep it coming 😋
Has there been any more thought put into proper unit testing strategies around these limitations?