Ejemplo n.º 1
0
		private async void Connection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
		{
			var lDeferral = args.GetDeferral();
			try
			{
				var message = args.Request.Message;
				if(message.ContainsKey("MessageType") && message.ContainsKey("Message"))
				{
					var type = message["MessageType"] as String;
					var mes = message["Message"] as String;
					if(type != null && mes != null)
					{
						using(var lh = new LoggingHelper())
						{
							var result = lh.LogEntry(type, mes);
							var vs = new ValueSet();
							vs["result"] = result;
							await args.Request.SendResponseAsync(vs);
						}
					}
				}
			}
			catch { }
			lDeferral.Complete();	
		}
Ejemplo n.º 2
0
		public void LogEntryTest()
		{
			using (var dbContext = new DbContextMock())
			{
				using(var logHelper = new LoggingHelper(dbContext))
				{
					Assert.ThrowsException<ArgumentNullException>(() => logHelper.LogEntry(null, ""));
					Assert.ThrowsException<ArgumentNullException>(() => logHelper.LogEntry("test", null));

					var results = logHelper.LogEntry("test", "{}");
					Assert.IsFalse(results, "LogType of test should return false");
					results = logHelper.LogEntry(nameof(ApplicationLogEntry), "{");
					Assert.IsFalse(results, "Invalid json for message should return false");
					results = logHelper.LogEntry(nameof(ApplicationLogEntry), @"{
	""DeviceId"": -2,
	""ApplicationId"": ""LoggingTest"",
	""Message"": ""This is the test message"",
	""Exception"": ""Exception Message""
}");
					Assert.IsTrue(results, "Entry was not logged correctly");
					var firstItem = dbContext.ApplicationLogEntries.FirstOrDefault();
					Assert.IsNotNull(firstItem, "Entry not added");
					Assert.AreNotEqual(Guid.Empty, firstItem.Id);
					Assert.AreEqual(-2, firstItem.DeviceId);
					Assert.AreEqual("LoggingTest", firstItem.ApplicationId);
					Assert.AreEqual("This is the test message", firstItem.Message);
					Assert.AreEqual("Exception Message", firstItem.Exception);
					Assert.AreNotEqual(default(DateTime), firstItem.EntryDateTime);
					Assert.IsFalse(firstItem.Synced, "Synced should be false");
				}
			}
		}