public bool Update(ShellTemperatureComment model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model), "The shell temperature comment supplied is null");
            }

            // get data from database
            DeviceInfo     device         = Context.DevicesInfo.Find(model.ShellTemp.Device.Id);
            ShellTemp      temp           = Context.ShellTemperatures.Find(model.ShellTemp.Id);
            ReadingComment readingComment = Context.ReadingComments.Find(model.Comment.Id);

            if (temp == null || device == null || readingComment == null)
            {
                throw new NullReferenceException("Could not find the shell temperature");
            }

            // see if the temperature already has a comment
            ShellTemperatureComment exists = GetItem(model.Id);

            if (exists == null)
            {
                throw new NullReferenceException("Could not find the item to update");
            }

            exists.Comment          = readingComment;
            exists.ShellTemp        = temp;
            exists.ShellTemp.Device = device;

            Context.SaveChanges();
            return(true);
        }
        public bool Create(SdCardShellTemperatureComment model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model), "The comment object was null");
            }

            // get data from database
            DeviceInfo      device         = Context.DevicesInfo.Find(model.SdCardShellTemp.Device.Id);
            SdCardShellTemp temp           = Context.SdCardShellTemperatures.Find(model.SdCardShellTemp.Id);
            ReadingComment  readingComment = Context.ReadingComments.Find(model.Comment.Id);

            if (temp == null || device == null || readingComment == null)
            {
                throw new NullReferenceException("The temperature, device or comment is null");
            }

            // see if the temperature already has a comment
            SdCardShellTemperatureComment exists = Context.SdCardShellTemperatureComments.FirstOrDefault(x => x.SdCardShellTemp.Id == temp.Id);

            if (exists != null)                  // already exists
            {
                exists.Comment = readingComment; // Update the record
            }
            else
            {
                model.SdCardShellTemp        = temp;
                model.SdCardShellTemp.Device = device;
                model.Comment = readingComment;
                Context.SdCardShellTemperatureComments.Add(model);
            }

            Context.SaveChanges();
            return(true);
        }
        public bool Create(ShellTemperatureComment model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model), "The comment object was null");
            }

            // get data from database
            DeviceInfo     device         = Context.DevicesInfo.Find(model.ShellTemp.Device.Id);
            ShellTemp      temp           = Context.ShellTemperatures.Find(model.ShellTemp.Id);
            ReadingComment readingComment = Context.ReadingComments.Find(model.Comment.Id);

            if (temp == null || device == null || readingComment == null)
            {
                throw new NullReferenceException("The temperature, device or comment is null");
            }

            model.ShellTemp        = temp;
            model.ShellTemp.Device = device;
            model.Comment          = readingComment;
            Context.ShellTemperatureComments.Add(model);

            Context.SaveChanges();
            return(true);
        }
        public void GetSingleItem_InvalidId()
        {
            Guid           id = It.IsAny <Guid>();
            ReadingComment dbReadingComment = readingCommentRepository.GetItem(id);

            Assert.IsNull(dbReadingComment);
        }
 public void GetSingleItem()
 {
     foreach (var readingComment in readingComments)
     {
         ReadingComment dbReadingComment = readingCommentRepository.GetItem(readingComment.Id);
         Assert.IsNotNull(dbReadingComment);
         Assert.AreEqual(readingComment, dbReadingComment);
     }
 }
        public void Create_Test()
        {
            // Arrange
            ReadingComment readingComment = new ReadingComment("MyComment");

            // Act
            bool created = readingCommentRepository.Create(readingComment);

            // Assert
            Assert.IsTrue(created);
        }
        public void Update_AlreadyExists_Test()
        {
            ReadingComment newComment = new ReadingComment("Groot");

            Context.ReadingComments.Add(newComment);

            newComment.Comment = "Marvel";
            bool updated = readingCommentRepository.Update(newComment);

            Assert.IsFalse(updated);
        }
        public void GetItem_ByCommentAlreadyExists()
        {
            foreach (var comment in readingComments)
            {
                // ACt
                ReadingComment readingComment = readingCommentRepository.GetItem(comment.Comment);

                //Assert
                Assert.IsNotNull(readingComment);
            }
        }
        public void GetItem_ByComment()
        {
            // Arrange
            string comment = "MyString";

            // ACt
            ReadingComment readingComment = readingCommentRepository.GetItem(comment);

            //Assert
            Assert.IsNull(readingComment);
        }
        public void Update()
        {
            Random random = new Random();

            foreach (var comment in shellTemperatureComments)
            {
                IList <ReadingComment> selections        = readingComments.Where(x => x.Id != comment.Comment.Id).ToList();
                ReadingComment         newReadingComment = selections[random.Next(0, selections.Count())];

                comment.Comment = newReadingComment;

                bool updated = shellTemperatureCommentRepository.Update(comment);
                Assert.IsTrue(updated);
            }
        }
        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();
        }