Esempio n. 1
0
        public void Setup()
        {
            var context = GetShellDb();

            // Add data to shelltemps and shelltemppositions
            for (var index = 0; index < shellTemps.Count; index++)
            {
                var shellTemp = shellTemps[index];
                context.ShellTemperatures.Add(shellTemp);

                ShellTemp dbTemp = context.ShellTemperatures.Find(shellTemp.Id);

                ShellTemperaturePosition shellTemperaturePosition = new ShellTemperaturePosition
                {
                    ShellTemp = dbTemp,
                    Position  = devPos[index]
                };
                context.ShellTemperaturePositions.Add(shellTemperaturePosition);
            }

            context.SaveChanges();

            positionsRepository = new PositionsRepository(context);
            context.Positions.Add(devPos[3]); // Extra
        }
Esempio n. 2
0
        public void Create()
        {
            Random random = new Random();

            int        temp       = random.Next(18, 25);
            int        lat        = random.Next(0, 54);
            int        lon        = random.Next(0, 10);
            DeviceInfo deviceInfo = deviceInfos[random.Next(0, deviceInfos.Length)];

            ShellTemp shellTemp = new ShellTemp(Guid.NewGuid(), temp, DateTime.Now,
                                                lat, lon, deviceInfo);

            Positions position = positions[random.Next(0, positions.Count)];

            Context.ShellTemperatures.Add(shellTemp);

            ShellTemperaturePosition shellTemperaturePosition = new ShellTemperaturePosition
            {
                ShellTemp = shellTemp,
                Position  = position
            };

            bool created = shellTemperaturePositionRepository.Create(shellTemperaturePosition);

            Assert.IsTrue(created);
        }
Esempio n. 3
0
 public void Create_DeviceNull()
 {
     Assert.Throws <ArgumentNullException>(delegate
     {
         ShellTemperaturePosition shellTemperaturePosition = new ShellTemperaturePosition();
         shellTemperaturePositionRepository.Create(shellTemperaturePosition);
     });
 }
Esempio n. 4
0
 public void GetItem()
 {
     foreach (var shellTemperaturePosition in shellTemperaturePositions)
     {
         ShellTemperaturePosition temp = shellTemperaturePositionRepository.GetItem(shellTemperaturePosition.Id);
         Assert.IsNotNull(temp);
         Assert.IsNotNull(temp.Position);
         Assert.IsNotNull(temp.ShellTemp);
     }
 }
Esempio n. 5
0
        public void Setup()
        {
            Context = GetShellDb();
            shellTemperaturePositionRepository = new ShellTemperaturePositionRepository(Context);

            shellTemps.Clear();
            positions.Clear();
            shellTemperaturePositions.Clear();

            Random random = new Random();

            string[] pos = new[]
            {
                "Ironman", "Thor", "StarLord", "Rocket", "Gamora", "Thanos",
                "Quill", "Groot", "BlackWidow", "Hawkeye"
            };

            Context.DevicesInfo.AddRange(deviceInfos);

            for (int i = 0; i < 10; i++)
            {
                int        temp       = random.Next(18, 25);
                int        lat        = random.Next(0, 54);
                int        lon        = random.Next(0, 10);
                DeviceInfo deviceInfo = deviceInfos[random.Next(0, deviceInfos.Length)];

                ShellTemp shellTemp = new ShellTemp(Guid.NewGuid(), temp, DateTime.Now,
                                                    lat, lon, deviceInfo);

                shellTemps.Add(shellTemp);

                Positions position = new Positions(pos[i]);
                positions.Add(position);

                ShellTemperaturePosition shellTemperaturePosition = new ShellTemperaturePosition
                {
                    ShellTemp = shellTemp,
                    Position  = position
                };
                shellTemperaturePositions.Add(shellTemperaturePosition);

                Context.Positions.Add(position);
                Context.ShellTemperatures.Add(shellTemp);
                Context.ShellTemperaturePositions.Add(shellTemperaturePosition);
            }

            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());
        }