public void GetSingleItem()
 {
     foreach (var shellTemperatureComment in shellTemperatureComments)
     {
         ShellTemperatureComment dbComment = shellTemperatureCommentRepository.GetItem(shellTemperatureComment.Id);
         Assert.IsNotNull(dbComment);
         Assert.AreEqual(shellTemperatureComment, dbComment);
         Assert.IsNotNull(dbComment.Comment);
         Assert.IsNotNull(dbComment.ShellTemp);
         Assert.AreEqual(shellTemperatureComment.Comment, dbComment.Comment);
         Assert.AreEqual(shellTemperatureComment.ShellTemp, dbComment.ShellTemp);
     }
 }
        public void Update_InvalidId()
        {
            Assert.Throws <NullReferenceException>(delegate
            {
                Guid id       = It.IsAny <Guid>();
                Random random = new Random();

                ShellTemperatureComment shellTemperatureComment =
                    shellTemperatureComments[random.Next(0, shellTemperatureComments.Count)];

                // Invalidate guid id
                shellTemperatureComment.Id = id;
                shellTemperatureCommentRepository.Update(shellTemperatureComment); // throws error!!!
            });
        }
        public void Create()
        {
            // Arrange
            Random random = new Random();

            ShellTemp      shellTemp      = shellTemps[random.Next(0, shellTemps.Count)];
            ReadingComment readingComment = readingComments[random.Next(0, readingComments.Count)];

            ShellTemperatureComment newComment = new ShellTemperatureComment(readingComment, shellTemp);

            // ACt
            bool created = shellTemperatureCommentRepository.Create(newComment);

            // Assert
            Assert.IsTrue(created);
        }
        public void Setup()
        {
            Context = GetShellDb();
            shellTemperatureCommentRepository = new ShellTemperatureCommentRepository(Context);

            Random random = new Random();

            shellTemps.Clear();
            readingComments.Clear();
            shellTemperatureComments.Clear();

            string[] comments = new[]
            {
                "IronMan", "Thor", "CaptainMarvel", "Thanos", "BlackWidow", "Wolverine", "JonSnow", "Deadpool",
                "Rocket", "Quill"
            };

            for (int i = 0; i < 10; i++)
            {
                int temp = random.Next(18, 25);
                int lat  = random.Next(0, 55);
                int lon  = random.Next(0, 10);

                ShellTemp shellTemp = new ShellTemp(Guid.NewGuid(), temp, DateTime.Now,
                                                    lat, lon, deviceInfo[random.Next(0, deviceInfo.Length)]);
                shellTemps.Add(shellTemp);

                ReadingComment readingComment = new ReadingComment(comments[i]);
                readingComments.Add(readingComment);

                ShellTemperatureComment shellTemperatureComment =
                    new ShellTemperatureComment(readingComment, shellTemp);
                shellTemperatureComments.Add(shellTemperatureComment);

                Context.ReadingComments.Add(readingComment);
                Context.ShellTemperatures.Add(shellTemp);
                Context.ShellTemperatureComments.Add(shellTemperatureComment);
            }

            Context.SaveChanges();
        }
        /// <summary>
        /// Get all the live and sd card shell temperatures along with
        /// the comments and positions
        /// </summary>
        /// <returns></returns>
        public ShellTemperatureRecord[] GetShellTemperatureRecords(DateTime start, DateTime end, DeviceInfo deviceInfo = null)
        {
            ShellTemp[]       tempData;
            SdCardShellTemp[] sdCardShellTemps;

            // Has device information, user selected device
            if (deviceInfo != null)
            {
                // Get live data and live data comments and positions
                tempData = _shellTemperatureRepository.GetShellTemperatureData(start, end,
                                                                               deviceInfo.DeviceName, deviceInfo.DeviceAddress).ToArray();

                // Get SD Card data and SD card data comments
                sdCardShellTemps = _sdCardShellTemperatureRepository.GetShellTemperatureData(start, end,
                                                                                             deviceInfo.DeviceName, deviceInfo.DeviceAddress).ToArray();
            }
            else // No device information, just use dates
            {
                // Get live data and live data comments and positions
                tempData = _shellTemperatureRepository.GetShellTemperatureData(start, end).ToArray();

                // Get SD Card data and SD card data comments
                sdCardShellTemps = _sdCardShellTemperatureRepository.GetShellTemperatureData(start, end).ToArray();
            }

            // Get the live comments
            ShellTemperatureComment[] liveDataComments = _commentRepository.GetAll()
                                                         .Where(x => x.ShellTemp.RecordedDateTime >= start &&
                                                                x.ShellTemp.RecordedDateTime <= end)
                                                         .ToArray();

            // Get the live positions
            ShellTemperaturePosition[] positions = _shellTemperaturePositionRepository.GetAll().ToArray();

            // Sd card comments
            SdCardShellTemperatureComment[] sdCardComments = _sdCardCommentRepository.GetAll().ToArray();


            // Create new temp list of records
            List <ShellTemperatureRecord> records = new List <ShellTemperatureRecord>();

            // For ever item in ShellTemps, find and match the comment that may have been made
            foreach (ShellTemp shellTemp in tempData)
            {
                ShellTemperatureRecord shellTemperatureRecord =
                    new ShellTemperatureRecord(shellTemp.Id, shellTemp.Temperature, shellTemp.RecordedDateTime,
                                               shellTemp.Latitude, shellTemp.Longitude, shellTemp.Device, false); // Not from SD

                // Find the comment for the shell temperature
                ShellTemperatureComment comment =
                    liveDataComments.FirstOrDefault(x => x.ShellTemp.Id == shellTemperatureRecord.Id);

                ShellTemperaturePosition position =
                    positions.FirstOrDefault(x => x.ShellTemp.Id == shellTemperatureRecord.Id);

                if (comment?.Comment != null)
                {
                    shellTemperatureRecord.Comment = comment.Comment.Comment;
                }
                if (position?.Position != null)
                {
                    shellTemperatureRecord.Position = position.Position.Position;
                }

                records.Add(shellTemperatureRecord);
            }

            // Find the sd card data shell temps
            foreach (SdCardShellTemp shellTemp in sdCardShellTemps)
            {
                if (!shellTemp.RecordedDateTime.HasValue) // Doesn't have DateTime, skip
                {
                    continue;
                }

                ShellTemperatureRecord shellTemperatureRecord =
                    new ShellTemperatureRecord(shellTemp.Id, shellTemp.Temperature, (DateTime)shellTemp.RecordedDateTime,
                                               shellTemp.Latitude, shellTemp.Longitude, shellTemp.Device, true); // This is from SD

                // Find the comment for the sd card shell temperature
                SdCardShellTemperatureComment temp =
                    sdCardComments.FirstOrDefault(x => x.SdCardShellTemp.Id == shellTemperatureRecord.Id);

                if (temp?.Comment != null)
                {
                    shellTemperatureRecord.Comment = temp.Comment.Comment;
                }

                records.Add(shellTemperatureRecord);
            }

            return(records.ToArray());
        }