public void Ctor_AlwaysReadValueFromFile()
        {
            // Arrange
            File.Delete(TelemetryDataRepository.GetStorageFilePath());

            var repository = new TelemetryDataRepository();

            repository.Data.IsAnonymousDataShared = false;
            repository.Data.InstallationDate      = DateTime.MaxValue;
            repository.Data.LastSavedAnalysisDate = DateTime.MaxValue;
            repository.Data.NumberOfDaysOfUse     = long.MaxValue;
            repository.Data.LastUploadDate        = DateTime.MaxValue;
            repository.Save();
            repository.Dispose();

            // Act
            repository = new TelemetryDataRepository();

            // Assert
            repository.Data.IsAnonymousDataShared.Should().BeFalse();
            repository.Data.InstallationDate.Should().Be(DateTime.MaxValue);
            repository.Data.LastSavedAnalysisDate.Should().Be(DateTime.MaxValue);
            repository.Data.NumberOfDaysOfUse.Should().Be(long.MaxValue);
            repository.Data.LastUploadDate.Should().Be(DateTime.MaxValue);
        }
        public void Save_SavesIntoXmlAllValuesOfData()
        {
            // Arrange
            File.Delete(TelemetryDataRepository.GetStorageFilePath());

            var repository = new TelemetryDataRepository();

            repository.Data.IsAnonymousDataShared = false;
            repository.Data.InstallationDate      = DateTime.MaxValue;
            repository.Data.LastSavedAnalysisDate = DateTime.MaxValue;
            repository.Data.NumberOfDaysOfUse     = long.MaxValue;
            repository.Data.LastUploadDate        = DateTime.MaxValue;

            // Act
            repository.Save();

            // Assert
            var stream     = File.OpenRead(TelemetryDataRepository.GetStorageFilePath());
            var serializer = new XmlSerializer(typeof(TelemetryData));
            var data       = serializer.Deserialize(stream) as TelemetryData;

            data.IsAnonymousDataShared.Should().BeFalse();
            data.InstallationDate.Should().Be(DateTime.MaxValue);
            data.LastSavedAnalysisDate.Should().Be(DateTime.MaxValue);
            data.NumberOfDaysOfUse.Should().Be(long.MaxValue);
            data.LastUploadDate.Should().Be(DateTime.MaxValue);
        }
        public void Instance_AutomaticallyReadFileOnChange()
        {
            // Arrange
            RetryHelper.RetryOnException(5, TimeSpan.FromSeconds(1),
                                         () => File.Delete(TelemetryDataRepository.GetStorageFilePath()));

            var repository = new TelemetryDataRepository();

            repository.Data.IsAnonymousDataShared = false;
            repository.Data.InstallationDate      = DateTime.MaxValue;
            repository.Data.LastSavedAnalysisDate = DateTime.MaxValue;
            repository.Data.NumberOfDaysOfUse     = long.MaxValue;
            repository.Data.LastUploadDate        = DateTime.MaxValue;

            var otherRepository = new TelemetryDataRepository();

            // Act
            repository.Save();
            Task.Delay(700).Wait();

            // Assert
            otherRepository.Data.InstallationDate.Should().Be(DateTime.MaxValue);
            otherRepository.Data.LastSavedAnalysisDate.Should().Be(DateTime.MaxValue);
            otherRepository.Data.NumberOfDaysOfUse.Should().Be(long.MaxValue);
            otherRepository.Data.LastUploadDate.Should().Be(DateTime.MaxValue);
            otherRepository.Data.IsAnonymousDataShared.Should().BeFalse();
        }