Skip to content

strongloop-community/loopback-sdk-xamarin

Repository files navigation

Loopback SDK for Xamarin

The repository contains the LoopBack Xamarin SDK, including the lb-xm script that creates a Xamarin client to call a LoopBack server backend API.

See also:

Set up

Windows / MacOS

Run npm install in shell.

After setup, to compile an SDK, make sure you have all the dependencies and run this command:

node lb-xm d:\someserver\server\server.js dll

Where the first parameter is the main application file of the Loopback server, and dll is a DLL compilation flag.

To review the C# part of the generator (source code of lb-xm/bin/LBXamarinSDKGenerator.dll), look at the LBXamarinSDK.sln solution.

To review simple example apps using a compiled SDK, see the folder "examples". This folder contains a LoopBack server and a Xamarin solution of an Android app using the SDK, and a second LoopBack server and a Visual Studio solution of a console application using the SDK.

Basic procedure

To create a Xamarin client based on a LoopBack API:

  1. Go into bin
  2. Create CS code for the SDK; for example:
node lb-xm d:\someserver\server\server.js
  1. Compile an SDK DLL; for example:
node lb-xm d:\someserver\server\server.js dll
  • To ensure compatibility with Xamarin-Forms, add the flag 'forms', e.g. node lb-xm d:\someserver\server\server.js forms.

In addition the C# source files are in C# directory, accessed by LBXamarinSDK.sln. This contains the open-source of the C# part of the generator. This project's end result is LBXamarinSDKGenerator.dll that is placed automatically as a post-build event inside the bin directory.

The C# project also contains testers for the lb-xm end result, for which we have the "test-server" folder, upon which the Testers act. The "examples" folder contains an example server and Xamarin solution of an App using a compiled SDK, and also a second example LoopBack server and a Visual Studio solution of a console application using the SDK. Last folder is "UnitTests", containing Testers for the project: it should get an input of the CS code generated by lb-xm.

Testers for LBXamarinSDK

The unit tests are in the C#\lb-xmTesters folder. It contains a Xamarin/Visual Studio testing solution on the test-server.

IMPORTANT: The Testing unit is an example of building tests for a server. Classes in LBXamarinSDK.cs are calibrated to work with the test server, and created specifically for that server. You must recompile LBXamarinSDK.cs when you change the server.

Setting up testers

Install Server

  1. Go into test-server and run 'npm install' in terminal/shell

Visual Studio

NOTE: It is important to do the setup while the project is open.

  1. Open lb-xmTesters.csproj in C#\lb-xmTesters.
  2. Make sure you have NuGet installed:
  • Tools-> Extensions and Updates.
  • Select online on left tab.
  • Search for NuGet Package manager.
  1. Make sure you have NUnit testing adapter installed; for instructions, see http://nunit.org/index.php?p=vsTestAdapter&r=2.6.3

Xamarin

No special setup is needed.

Running Tests###

All platforms

  1. Go into test-server and enter slc run. (NOTE: If the server was already run, close and run it again) Important Do this each time you run a test, as test change data in the server.
  2. If you made changes to the test-server:
  • Compile a new LBXamatinSDK.cs and replace the existing one (node lb-xm SERVERPATH).
  • Make sure that the code corresponds to changes on expected test results

Visual Studio

  1. Open lb-xmTesters.csproj located in C#\lb-xmTesters.
  2. Choose Test -> Windows -> Test Explorer.
  3. The first time you run tests click Run All in the tab that opens.

For more information on NUnit, see http://nunit.org/index.php?p=vsTestAdapter&r=2.6.3.

Xamarin

  1. Open LBXamarinSDK.sln.
  2. Right-click "lb-xmTesters" in the Solution Explorer -> run unit.

Contribution Workflow to the SDK Generator

  • Write a failing test of the desired feature in lb-xmTest.
  • Make changes to the SDK Generator C# project and/or test server and/or JS Code.
  • Build the SDKGenerator C# project.
  • Run lb-xm to create a CS file and put it into the Testers project.
  • Run test and check feature functionality.