Can't add ReactiveUI to a NUnit Test Project
Asked Answered
F

2

10

I am currently trying to setup Unit to unittest our ReactiveUI ViewModels using NUnit and Moq. However I can't get it working. I can't add ReactiveUI to a NUnit test library (Unable to resolve dependency 'Rx-Xaml (≥ 2.2.5)'), and I can't add Moq to a PCL project.

Is it even possible to unittest ReactiveUI ViewModels with NUnit and Moq?

Btw: I'm using Xamarin Studio on Mac OSX 10.10.5 but the code runs fine on Windows 10 :(

On OSX I get a Unix Transport Error, but on Windows the test does work.

Faux answered 4/9, 2015 at 12:3 Comment(1)
What is the targetframework you're targeting ? cf reactiveui nuspec I think you need to target one that does not reference Rx-XamlKktp
S
0

Have the same issue here. The reason why it does not work for us is in PlatformRegistrations class from PortableLibraryStubs. We have no platform implementation of it in Unit Test project and that is why it fails.

Here is a pretty dirty hack on how to make things work (https://github.com/OlexaLe/ReactiveUI/commit/c8a8292fde7a0617338110c55bfbf8c7d6947e1d) and here is a link to pull request (https://github.com/reactiveui/ReactiveUI/pull/1008) for tracking - maybe some day this will be in master :-).

Hope that helps. Thanks!

Superfetation answered 26/12, 2015 at 20:41 Comment(0)
B
0

Okay i got it, but it does not work without editing the csproj file manually. Here is a quick explanation for anyone else struggling with running their tests for a xamarin.android/ios project using reactiveui on a mac in combination with xamarin studio.

  1. Install xamarin.mac using the xamarin.installer

  2. Open your solution and add a new Library project from the "Mac" "Library" - "Unified API" tree.

  3. Delete all unneeded files like the Main.cs or AppDeletage.cs

  4. Open the Options of the added solution and switch the Target Framework from "Xamarin.Mac Mobile Framework" to "Xamarin.Mac .Net 4.5 Framework" under "Build" - "General".

  5. Add your packages. Dont forget Nunit and reactiveui-testing.

  6. Open the csproj file of the new project and change the path part from Net45 to Xamarin.Mac10 for the Splat and ReactiveUI references. See the example code.

    Run your tests and be happy

Broken references:

<Reference Include="ReactiveUI">
  <HintPath>..\packages\reactiveui-core.6.5.0\lib\Net45\ReactiveUI.dll</HintPath>
</Reference>
<Reference Include="Splat">
  <HintPath>..\packages\Splat.1.6.2\lib\Net45\Splat.dll</HintPath>
</Reference>`

Fixed references:

<Reference Include="ReactiveUI">
  <HintPath>..\packages\reactiveui-core.6.5.0\lib\Xamarin.Mac10\ReactiveUI.dll</HintPath>
</Reference>
<Reference Include="Splat">
  <HintPath>..\packages\Splat.1.6.2\lib\Xamarin.Mac10\Splat.dll</HintPath>
</Reference>

For reference, this is our working csproj file https://gist.github.com/omares/e4bccf5a90524f2482f9

Buttons answered 5/4, 2016 at 10:27 Comment(1)
follow the steps, I got the error : System.IO.FileNotFoundException : Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. Any ideas?Egon

© 2022 - 2024 — McMap. All rights reserved.