public void SaveLog_SaveWithSomeDuplicates_LogExtendedSinceLastEntry()
        {
            using (var tf = new TempTestFolder(nameof(DeviceLogWriterTests)))
            {
                // Arrange
                var deviceLogWriter = new DeviceLogWriter();
                var device          = GetDeviceMock();

                var data_0 = GenerateEmptryEntries(LOG_BLOCK_LENGTH);
                var data_A = GenerateDatedEntries(LOG_BLOCK_LENGTH, DateTime.Today.AddHours(1));
                var data_B = GenerateDatedEntries(LOG_BLOCK_LENGTH, DateTime.Today.AddHours(2));
                var data_C = GenerateDatedEntries(LOG_BLOCK_LENGTH, DateTime.Today.AddHours(3));

                var daily_A0B   = CombineToDailyLog(data_A, data_0, data_B);
                var daily_B0C   = CombineToDailyLog(data_B, data_0, data_C);
                var daily_A0B0C = CombineToDailyLog(data_A, data_0, data_B, data_0, data_C);

                var logPath  = deviceLogWriter.SaveLog(tf.FolderPath, daily_A0B, device, true);
                var expected = daily_A0B0C.Entries.Select(d => d.ToString());

                // Act
                deviceLogWriter.SaveLog(tf.FolderPath, daily_B0C, device, true);

                // Assert
                var actual = ReadLogFile(logPath);

                Assert.IsTrue(actual.SequenceEqual(expected));
            }
        }
        public void SaveLog_SaveNoDatedEntries_LogReprintedAfterSaved()
        {
            using (var tf = new TempTestFolder(nameof(DeviceLogWriterTests)))
            {
                // Arrange
                var deviceLogWriter = new DeviceLogWriter();
                var device          = GetDeviceMock();

                var data_A = GenerateEmptryEntries(LOG_BLOCK_LENGTH);
                var data_B = GenerateEmptryEntries(LOG_BLOCK_LENGTH);

                var daily_A  = CombineToDailyLog(data_A);
                var daily_B  = CombineToDailyLog(data_B);
                var daily_AB = CombineToDailyLog(data_A, data_B);

                var logPath  = deviceLogWriter.SaveLog(tf.FolderPath, daily_A, device, true);
                var expected = daily_AB.Entries.Select(d => d.ToString());

                // Act
                deviceLogWriter.SaveLog(tf.FolderPath, daily_B, device, true);

                // Assert
                var actual = ReadLogFile(logPath);

                Assert.IsTrue(actual.SequenceEqual(expected));
            }
        }
        public void SaveLog_SaveWithDuplicatedBeginning_ExtendedSinceLastEntry()
        {
            using (var tf = new TempTestFolder(nameof(DeviceLogWriterTests)))
            {
                // Arrange
                var deviceLogWriter = new DeviceLogWriter();
                var device          = GetDeviceMock();

                var data_0 = GenerateEmptryEntries(LOG_BLOCK_LENGTH);
                var data_A = GenerateDatedEntries(LOG_BLOCK_LENGTH, DateTime.Today.AddHours(1));
                var data_B = GenerateDatedEntries(LOG_BLOCK_LENGTH, DateTime.Today.AddHours(2));

                var daily_A0  = CombineToDailyLog(data_A, data_0);
                var daily_A0B = CombineToDailyLog(data_A, data_0, data_B);
                // Extended log starts after last dated entry, so one undated block is expected to be duplicated
                var daily_A00B = CombineToDailyLog(data_A, data_0, data_0, data_B);

                var logPath  = deviceLogWriter.SaveLog(tf.FolderPath, daily_A0, device, true);
                var expected = daily_A00B.Entries.Select(d => d.ToString());

                // Act
                deviceLogWriter.SaveLog(tf.FolderPath, daily_A0B, device, true);

                // Assert
                var actual = ReadLogFile(logPath);

                Assert.IsTrue(actual.SequenceEqual(expected));
            }
        }