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