I am unit testing Session exceptions but can’t figure out how to simulate session exceptions or how to substitute Session, SessionException classes with their mock objects.
According to the documentation, I can use the method SimulateError(this Session session, ErrorCode errorCode, string message, bool isFatal = false) to simulate session exceptions.
The only way to get the Session instance is to ask it from the Realm instance. The problem is that we use In memory realm inside unit tests and that realm has no session (realm.SynchedSession is null).
So the question is how to unit test session exceptions?
As you correctly stated the Session can’t be tested using a non-synced realm. What you could do is to create a testing app in Atlas and to use that as a testing environment. From there, the unit test could use that App and some hard-coded values to generate a user to create a SyncConfiguration.
Unfortunately, this is not really possible if not by using some internal API.
What I can recommend you is to take a look at how we execute our SessionTests and specifically how we generate a fake config to create a synced realm.
If after taking a look at our tests there is something unclear then don’t hesitate to ask.