예제 #1
0
        public void OnNextTest_SomeFlashObservations_TheyAreWrittenCorrectlyToTheFile()
        {
            var filePath = "testFile.txt";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            List <FlashObservation> flashObservations = FlashObservationBaseData.InitializeFlashObservations();

            using var stream = new MemoryStream();
            var serializer = new BinarySerializer <FlashObservation>();

            serializer.Serialize(stream, flashObservations[0]);
            serializer.Serialize(stream, flashObservations[1]);
            serializer.Serialize(stream, flashObservations[2]);

            stream.Position = 0;
            using var readerOfExpectedContent = new StreamReader(stream);
            string expected = readerOfExpectedContent.ReadToEnd();

            readerOfExpectedContent.Close();

            using (var saveToFileProcessor = new SaveToFileProcessor <FlashObservation>(new SerializeProcessor <FlashObservation>(serializer), filePath))
            {
                saveToFileProcessor.OnNext(flashObservations[0]);
                saveToFileProcessor.OnNext(flashObservations[1]);
                saveToFileProcessor.OnNext(flashObservations[2]);
            }

            var actual = File.ReadAllText(filePath);

            Assert.Equal(expected, actual);
        }
예제 #2
0
        public XmlFileStorageTests()
        {
            if (File.Exists(_filePath))
            {
                File.Delete(_filePath);
            }

            _xmlFileStorage = new XmlFileStorage <FlashObservation>(_filePath);

            using var fileProcessor = new SaveToFileProcessor <FlashObservation>(new SerializeToXmlProcessor <FlashObservation>(), _filePath);
            var data = FlashObservationBaseData.InitializeFlashObservations();

            fileProcessor.OnNext(data[0]);
            fileProcessor.OnNext(data[1]);
            fileProcessor.OnNext(data[2]);
            fileProcessor.OnNext(data[3]);
            fileProcessor.OnCompleted();
        }
        public void OnNextTest_SomeFlashObservations_TheyAreWrittenCorrectlyToTheStream()
        {
            List <FlashObservation> flashObservations = FlashObservationBaseData.InitializeFlashObservations();

            var filePath = "data.json";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var processor = new SerializeToJsonProcessor <FlashObservation>();

            using var saveProcessor = new SaveToFileProcessor <FlashObservation>(processor, filePath);

            saveProcessor.OnNext(flashObservations[0]);
            saveProcessor.OnNext(flashObservations[1]);
            saveProcessor.OnNext(flashObservations[2]);
            saveProcessor.OnNext(flashObservations[3]);
            saveProcessor.OnCompleted();
        }
예제 #4
0
        public void SaveToFileProcessor_SaveToTxtFile_WithoutDecorate(double x, double y, double intensity, int duration)
        {
            // Arrange
            var processor   = new SaveToFileProcessor <FlashObservation>(new JsonSerializeProcessor <IEnergyObservation>());
            var observation = new FlashObservation(duration, intensity, new Coordinates(x, y), DateTime.UtcNow);

            // Act
            processor.FilePath = FileName;
            processor.OnNext(observation);

            // Assert
            Assert.True(File.Exists(FileName));
        }
예제 #5
0
        public void SaveToFileProcessor_SaveToJsonFile_WithDecorate(double x, double y, double intensity, int duration)
        {
            // Arrange
            var fileStream = new FileStream(FileName, FileMode.OpenOrCreate);
            var serializer = new JsonSerializeProcessor <IEnergyObservation> {
                Stream = fileStream
            };
            var processor   = new SaveToFileProcessor <IEnergyObservation>(serializer);
            var observation = new FlashObservation(duration, intensity, new Coordinates(x, y), DateTime.UtcNow);

            // Act
            processor.FilePath = JsonFileName;
            processor.OnNext(observation);

            // Assert
            Assert.True(File.Exists(JsonFileName));
            fileStream.Close();
        }
예제 #6
0
        protected override IEnergyObservationAnalizer GetAnalyzer()
        {
            if (File.Exists(_filePath))
            {
                File.Delete(_filePath);
            }

            using (var fileProcessor = new SaveToFileProcessor <FlashObservation>(new SerializeToXmlProcessor <FlashObservation>(), _filePath))
            {
                foreach (var flashObservation in ListStorage)
                {
                    fileProcessor.OnNext(flashObservation);
                }

                fileProcessor.OnCompleted();
            }

            return(new XmlAnalyzer <FlashObservation>(XDocument.Load(_filePath)));
        }