public async Task TestCallHttpLayerAsync() { MobileCore.Init(new TestInjector(Assembly.GetExecutingAssembly())); var httpLayer = MobileCore.Instance.HttpLayer; Assert.IsNotNull(httpLayer, "Mobile Core must return the HTTP layer"); var request = httpLayer.NewRequest(); Assert.IsNotNull(request, "NewRequest() must create a request"); UriBuilder uriBuilder = new UriBuilder(localUrl); uriBuilder.Path = GET_TEST_PATH; var response = await request.Get(uriBuilder.Uri.ToString()).Execute(); Assert.NotNull(response); Assert.Null(response.Error); Assert.IsTrue(response.Successful); Assert.AreEqual(200, response.StatusCode); Assert.AreEqual(GET_TEST_BODY, response.Body); var jsonObject = JsonObject.Parse(response.Body); Assert.AreEqual(HELLO_WORLD, (string)jsonObject["text"]); MobileCore.Instance.Destroy(); }
/// <summary> /// Initializes Mobile core for Android. /// </summary> /// <param name="app">Xamarin.Forms.Application object</param> /// <param name="options">additional initialization options</param> public static void Init(Application app, Options options) { IPlatformInjector platformInjector = DependencyService.Get <IPlatformInjector>(); platformInjector.ExecutingAssembly = app.GetType().Assembly; MobileCore.Init(platformInjector, options); }
public void TestCoreInitAndDestroy() { Assert.Catch <InitializationException>(() => MobileCore.Instance.GetType(), "check uninitialized exception before init"); MobileCore.Init(new TestInjector(Assembly.GetExecutingAssembly())); Assert.NotNull(MobileCore.Instance, "check core initialized successfuly"); MobileCore.Instance.Destroy(); Assert.Catch <InitializationException>(() => MobileCore.Instance.GetType(), "check uninitialized exception after destroy"); }
public void TestRegisterService() { var testInstance = new TestService(); MobileCore.Init(new TestInjector(Assembly.GetExecutingAssembly())); MobileCore.Instance.RegisterService <ITestService>(testInstance); var registeredInstance = MobileCore.Instance.GetService <ITestService>(); Assert.NotNull(registeredInstance); Assert.AreSame(testInstance, registeredInstance); }
public void TestServiceConfigCasingType() { MobileCore.Init(new TestInjector(Assembly.GetExecutingAssembly())); var serviceConfigByType = MobileCore.Instance.GetServiceConfigurationsByType("dummy"); MobileCore.Instance.RegisterService <IDummyModule>(new DummyTypeCasingModule(serviceConfigByType[1])); var module = MobileCore.Instance.GetService <IDummyModule>(); Assert.IsNotNull(module); Assert.AreEqual("Hello world, from anotherdummy!", module.Data1); Assert.AreEqual(420, module.Data2); Assert.IsFalse(module.Data3); MobileCore.Instance.Destroy(); }
public void TestFirstServiceConfigByType() { MobileCore.Init(new TestInjector(Assembly.GetExecutingAssembly())); var serviceConfig = MobileCore.Instance.GetFirstServiceConfigurationByType("dummy"); MobileCore.Instance.RegisterService <IDummyModule>(new DummyModule(serviceConfig)); var module = MobileCore.Instance.GetService <IDummyModule>(); Assert.IsNotNull(module); Assert.AreEqual("dummy", module.Type); Assert.AreEqual("Hello world!", module.Data1); Assert.AreEqual(42, module.Data2); Assert.IsTrue(module.Data3); MobileCore.Instance.Destroy(); }
public void SetUp() { MobileCore.Init(new TestInjector(Assembly.GetExecutingAssembly())); }