Пример #1
0
		public void Run(IBackgroundTaskInstance taskInstance)
		{
			taskInstance.Canceled += canceled;
			deferral = taskInstance.GetDeferral();

			var details = taskInstance.TriggerDetails as AppServiceTriggerDetails;
			var connection = details.AppServiceConnection;

			controller = new ServiceController(AppSettings.Current);
			connection.RequestReceived += requestReceived;
		}
Пример #2
0
		public async Task GetConfigurationAsyncTest()
		{
			Uri serverUri = new Uri("http://localtest.me");
			String username = "******";
			var appSettings = new StubIAppSettings();
			appSettings.ServerUri_Get(() => serverUri);
			appSettings.Username_Get(() => username);

			var controller = new ServiceController(appSettings);
			var results = await controller.GetConfigurationAsync();
			Assert.AreEqual(serverUri, results.Item1);
			Assert.AreEqual(username, results.Item2);
		}
Пример #3
0
		public async Task SetConfigurationAsyncTest()
		{
			Uri serverUri = null;
			String username = null;
			String password = null;
			var appSettings = new StubIAppSettings();
			appSettings.ServerUri_Set((s) => serverUri = s);
			appSettings.ServerUri_Get(() => serverUri);
			appSettings.Username_Get(() => username);
			appSettings.Username_Set((u) => username = u);
			appSettings.Password_Get(() => password);
			appSettings.Password_Set((p) => password = p);

			var controller = new ServiceController(appSettings);
			var result = await controller.SetConfigurationAsync(null, null, null);
			Assert.IsFalse(result.Item1);
			Assert.AreEqual("ServerUri cannot be null", result.Item2);

			result = await controller.SetConfigurationAsync(new Uri("http://test"), null, null);
			Assert.IsFalse(result.Item1);
			Assert.AreEqual("Username cannot be null", result.Item2);

			result = await controller.SetConfigurationAsync(new Uri("http://test"), "test", null);
			Assert.IsFalse(result.Item1);
			Assert.AreEqual("Password cannot be null", result.Item2);

			result = await controller.SetConfigurationAsync(new Uri("http://test"), "test", "passwordTest");
			Assert.IsFalse(result.Item1);
			Assert.AreEqual("Error verifying with server", result.Item2);
			Assert.AreEqual(new Uri("http://test"), serverUri);
			Assert.AreEqual("test", username);
			Assert.AreEqual("passwordTest", password);

			var expectedUri = new Uri("http://localhost:5000/");
			var expectedUsername = "******";
			var expectedPassword = "******";

			result = await controller.SetConfigurationAsync(expectedUri, expectedUsername, expectedPassword);
			Assert.IsTrue(result.Item1);
			Assert.AreEqual("Success", result.Item2);
			Assert.AreEqual(expectedUri, serverUri);
			Assert.AreEqual(expectedUsername, username);
			Assert.AreEqual(expectedPassword, password);
		}
Пример #4
0
		private void canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
		{
			deferral?.Complete();
			controller = null;
		}