public void when_jsonserialized_then_jsonisasexpected()
        {
            //ARRANGE
            var ht = new HeightLog {
                command_text          = "Test Command",
                device_id             = "Test Device",
                from_height           = 0.0,
                to_height             = 15.5,
                move_duration_seconds = 4.2,
                move_initiate_time    = new DateTime(2015, 6, 6, 4, 3, 2)
            };

            //ACT
            string output = JsonConvert.SerializeObject(ht);

            Console.WriteLine(output);

            //ASSERT
            var ht2 = JsonConvert.DeserializeObject <HeightLog>(output);

            Assert.AreEqual(ht.command_text, ht2.command_text);
            Assert.AreEqual(ht.device_id, ht2.device_id);
            Assert.AreEqual(ht.from_height, ht2.from_height);
            Assert.AreEqual(ht.to_height, ht2.to_height);
            Assert.AreEqual(ht.move_duration_seconds, ht2.move_duration_seconds);
            Assert.AreEqual(ht.move_initiate_time, ht2.move_initiate_time);
        }
Example #2
0
 /// <summary>
 /// Saves a height entry to the database
 /// </summary>
 /// <param name="entry"></param>
 public void SaveHeightLogEntry(HeightLog entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException();
     }
     if (string.IsNullOrEmpty(entry.id))
     {
         entry.id = Guid.NewGuid().ToString();
     }
     using (var dbContext = new RobotDeskData()) {
         dbContext.HeightLogs.Add(entry);
         dbContext.SaveChanges();
     }
 }
Example #3
0
        /// <summary>
        /// Triggered via Service Bus Queue, this function takes the message and records the contained info in the height log database
        /// </summary>
        /// <param name="message"></param>
        /// <param name="logger"></param>
        public static void ProcessQueueMessage(
            [ServiceBusTrigger("robotdeskheightchangequeue")] BrokeredMessage message, TextWriter logger)
        {
            logger.WriteLine("got message!");
            string json = null;

            using (Stream stream = message.GetBody <Stream>())
                using (TextReader reader = new StreamReader(stream)) {
                    json = reader.ReadToEnd();
                }
            logger.WriteLine("Received message: " + json);

            HeightLog height = null;

            height = JsonToHeightLog(json);

            var svc = new HeightLogSvc();

            svc.SaveHeightLogEntry(height);
        }