public void ConvertValidKnownFormatsSuccessTest(ConvertedFormat inputFormat) { foreach (var outputFormat in SignificantFormatsTestData.TestCases) { FormatProcessorBase.ClearFormatProcessorsCache(); string filePath1 = "file1"; string filePath2 = "file2"; FormatDataItem item1 = new FormatDataItem(); item1.SetDate("01.01.2001"); item1.SetBrandName("brand1"); item1.SetPrice(1111); FormatDataItem item2 = new FormatDataItem(); item2.SetDate("02.02.2002"); item2.SetBrandName("brand2"); item2.SetPrice(2222); var converter = new CommonFormatConverter(); Assert.IsNotNull(converter); using (var processor = converter.CreateFormatProcessor(inputFormat)) { processor.AddDataItem(item1); processor.AddDataItem(item2); Assert.IsNotNull(processor); Assert.IsTrue(converter.ConvertProcessor(processor, filePath1, outputFormat)); Assert.DoesNotThrow(() => converter.ConvertProcessor(processor, filePath1, outputFormat)); } Assert.IsTrue(converter.Convert(filePath1, outputFormat, filePath2, inputFormat)); Assert.DoesNotThrow(() => converter.Convert(filePath1, outputFormat, filePath2, inputFormat)); Assert.IsTrue(converter.Convert(filePath2, inputFormat, filePath1, outputFormat)); Assert.DoesNotThrow(() => converter.Convert(filePath2, inputFormat, filePath1, outputFormat)); Assert.IsTrue(File.Exists(filePath1)); Assert.IsTrue(File.Exists(filePath2)); File.Delete(filePath1); File.Delete(filePath2); } }
public void CreateCommonFormatConverter() { FormatProcessorBase.ClearFormatProcessorsCache(); CommonFormatConverter converter = new CommonFormatConverter(); Assert.IsNotNull(converter); }
public void CreateUnknownFormatProcessor(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); Assert.IsNotNull(converter); Assert.Throws <ArgumentException>(() => converter.CreateFormatProcessor(format)); }
public void TryGetSupportedFormatFromPathException(string filePath) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); Assert.IsNotNull(converter); ConvertedFormat format; Assert.Throws <ArgumentException>(() => converter.TryGetSupportedFormatFromPath(filePath, out format)); }
public void Create(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); var processor = converter.CreateFormatProcessor(format) as FormatProcessorBase; Assert.IsNotNull(processor); Assert.IsNotNull(processor.Data); Assert.AreNotEqual(ConvertedFormat.UNKNOWN, processor.Format); Assert.DoesNotThrow(() => processor.GetFormatProcessor()); }
public void Dispose(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); var processor = converter.CreateFormatProcessor(format) as FormatProcessorBase; processor.AddDataCollectionChangedHandler((sender, args) => { }); processor.AddDataCollectionChangedHandler((sender, args) => { }); processor.AddNewDataItem(new DateTime(), string.Empty, 100); processor.AddNewDataItem(new DateTime(2010, 02, 10), "VS", 200); Assert.DoesNotThrow(() => processor.Dispose()); }
public void ConvertKnownFormatArgumentExceptionTest(ConvertedFormat inputFormat) { foreach (var outputFormat in SignificantFormatsTestData.TestCases) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); Assert.IsNotNull(converter); Assert.Throws <ArgumentNullException>(() => converter.ConvertProcessor(null, "outfile", outputFormat)); Assert.Throws <ArgumentException>(() => converter.ConvertProcessor(converter.CreateFormatProcessor(inputFormat), null, outputFormat)); Assert.Throws <ArgumentException>(() => converter.ConvertProcessor(converter.CreateFormatProcessor(inputFormat), string.Empty, outputFormat)); } }
public void AddRemoveDataItem(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); var processor = converter.CreateFormatProcessor(format) as FormatProcessorBase; IFormatDataItem dataItem = new FormatDataItem(); Assert.Throws <ArgumentNullException>(() => processor.AddDataItem(null)); Assert.DoesNotThrow(() => processor.AddDataItem(dataItem, false)); Assert.Throws <InvalidOperationException>(() => processor.AddDataItem(dataItem, false)); Assert.IsFalse(processor.RemoveDataItem(null)); Assert.IsFalse(processor.RemoveDataItem(dataItem.Clone() as IFormatDataItem)); Assert.IsTrue(processor.RemoveDataItem(dataItem)); }
public void CreateKnownFormatProcessor(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); Assert.IsNotNull(converter); var firstProcessor = converter.CreateFormatProcessor(format); Assert.IsNotNull(firstProcessor); var secondProcessor = firstProcessor.GetFormatProcessor(); Assert.IsNotNull(secondProcessor); Assert.AreNotSame(firstProcessor, secondProcessor); secondProcessor.Dispose(); Assert.AreSame(secondProcessor.GetFormatProcessor(), secondProcessor); }
public void TryGetSupportedFormatFromPathTrue(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); Assert.IsNotNull(converter); using (var processor = converter.CreateFormatProcessor(format)) { Assert.IsNotNull(processor); Assert.IsTrue(converter.ConvertProcessor(processor, $"file.{format}", format)); } ConvertedFormat supportedFormat; Assert.IsTrue(converter.TryGetSupportedFormatFromPath($"file.{format}", out supportedFormat)); Assert.AreEqual(supportedFormat, format); }
public void Cache(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); var processor1 = converter.CreateFormatProcessor(format) as FormatProcessorBase; var handler = new NotifyCollectionChangedEventHandler((sender, args) => { }); var dataItem = new FormatDataItem(); processor1.Dispose(); string filePath = "file"; Assert.IsTrue(processor1.IsCached); Assert.Throws <InvalidOperationException>(() => processor1.Dispose()); Assert.Throws <InvalidOperationException>(() => { var someVar = processor1.Data; }); Assert.Throws <InvalidOperationException>(() => { processor1.AddDataCollectionChangedHandler(handler); }); Assert.Throws <InvalidOperationException>(() => { processor1.RemoveDataCollectionChangedHandler(handler); }); Assert.Throws <InvalidOperationException>(() => { processor1.AddDataItem(dataItem); }); Assert.Throws <InvalidOperationException>(() => { processor1.RemoveDataItem(dataItem); }); Assert.Throws <InvalidOperationException>(() => { processor1.ClearData(); }); Assert.Throws <InvalidOperationException>(() => { processor1.GetEnumerator(); }); Assert.Throws <InvalidOperationException>(() => { processor1.ReadFromFile(filePath); }); Assert.Throws <InvalidOperationException>(() => { processor1.SaveToFile(filePath); }); Assert.Throws <InvalidOperationException>(() => { processor1.SetData(null); }); Assert.DoesNotThrow(() => { processor1.SupportsFormat(format.ToString()); }); var processor2 = converter.CreateFormatProcessor(format); Assert.AreSame(processor1, processor2); Assert.False(processor1.IsCached); Assert.DoesNotThrow(() => { var someVar = processor1.Data; }); Assert.DoesNotThrow(() => { processor1.AddDataCollectionChangedHandler(handler); }); Assert.DoesNotThrow(() => { processor1.RemoveDataCollectionChangedHandler(handler); }); Assert.DoesNotThrow(() => { processor1.AddDataItem(dataItem); }); Assert.DoesNotThrow(() => { processor1.RemoveDataItem(dataItem); }); Assert.DoesNotThrow(() => { processor1.ClearData(); }); Assert.DoesNotThrow(() => { processor1.GetEnumerator(); }); Assert.DoesNotThrow(() => { processor1.SaveToFile(filePath); }); Assert.DoesNotThrow(() => { processor1.ReadFromFile(filePath); }); Assert.DoesNotThrow(() => { processor1.SetData(new[] { dataItem }); }); File.Delete(filePath); processor1.Dispose(); Assert.IsTrue(processor1.IsCached); processor2 = processor1.GetFormatProcessor(); Assert.AreSame(processor1, processor2); Assert.False(processor1.IsCached); }
public void TryGetSupportedFormatFromPathFalse() { FormatProcessorBase.ClearFormatProcessorsCache(); string filePath = "file"; var converter = new CommonFormatConverter(); Assert.IsNotNull(converter); ConvertedFormat format; if (!File.Exists(filePath) || string.IsNullOrEmpty(filePath)) { Assert.Throws <ArgumentException>(() => converter.TryGetSupportedFormatFromPath("file", out format)); } else { Assert.IsFalse(converter.TryGetSupportedFormatFromPath("file", out format)); } }
public void ManipulateCollectionHandlers(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); var processor = converter.CreateFormatProcessor(format) as FormatProcessorBase; Assert.Throws <ArgumentNullException>(() => processor.AddDataCollectionChangedHandler(null)); NotifyCollectionChangedEventHandler handler1 = (sender, args) => { }; NotifyCollectionChangedEventHandler handler2 = (sender, args) => { }; Assert.DoesNotThrow(() => processor.AddDataCollectionChangedHandler(handler1)); Assert.Throws <InvalidOperationException>(() => processor.AddDataCollectionChangedHandler(handler1)); Assert.Throws <ArgumentNullException>(() => processor.RemoveDataCollectionChangedHandler(null)); Assert.Throws <InvalidOperationException>(() => processor.RemoveDataCollectionChangedHandler(handler2)); Assert.DoesNotThrow(() => processor.AddDataCollectionChangedHandler(handler2)); Assert.DoesNotThrow(() => processor.RemoveDataCollectionChangedHandler(handler2)); Assert.DoesNotThrow(() => processor.RemoveDataCollectionChangedHandler(handler1)); }
public void ConvertValidKnownFormatsDataTest(ConvertedFormat inputFormat) { string filePath1 = "file1"; string filePath2 = "file2"; FormatDataItem item1 = new FormatDataItem(); item1.SetDate("01.01.2001"); item1.SetBrandName("brand1"); item1.SetPrice(1111); FormatDataItem item2 = new FormatDataItem(); item2.SetDate("02.02.2002"); item2.SetBrandName("brand2"); item2.SetPrice(2222); var converter = new CommonFormatConverter(); foreach (var outputFormat in SignificantFormatsTestData.TestCases) { FormatProcessorBase.ClearFormatProcessorsCache(); using (var processor = converter.CreateFormatProcessor(inputFormat)) { processor.AddDataItem(item1); processor.AddDataItem(item2); Assert.IsTrue((FormatDataItem)processor[0] == item1); Assert.IsTrue((FormatDataItem)processor[1] == item2); converter.ConvertProcessor(processor, filePath1, outputFormat); } using (var processor = converter.CreateFormatProcessor(outputFormat)) { processor.ReadFromFile(filePath1); Assert.IsTrue((FormatDataItem)processor[0] == item1); Assert.IsTrue((FormatDataItem)processor[1] == item2); converter.ConvertProcessor(processor, filePath2, inputFormat); } using (var processor = converter.CreateFormatProcessor(inputFormat)) { processor.ReadFromFile(filePath2); Assert.IsTrue((FormatDataItem)processor[0] == item1); Assert.IsTrue((FormatDataItem)processor[1] == item2); } File.Delete(filePath1); File.Delete(filePath2); } }
public void SupportsFormat(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); var converter = new CommonFormatConverter(); var processor = converter.CreateFormatProcessor(format) as FormatProcessorBase; Assert.IsTrue(processor.Format == format); Assert.IsTrue(processor.SupportsFormat(format.ToString())); Assert.IsTrue(processor.SupportsFormat("." + format.ToString())); foreach (ConvertedFormat frmt in SignificantFormatsTestData.TestCases) { if (frmt != format) { var strFormat = frmt.ToString(); Assert.IsFalse(processor.SupportsFormat(strFormat)); Assert.IsFalse(processor.SupportsFormat("." + strFormat)); } } }
public void ReadWriteFiles(ConvertedFormat format) { FormatProcessorBase.ClearFormatProcessorsCache(); string filePath1 = "file1"; string filePath2 = "file2"; var converter = new CommonFormatConverter(); var processor = converter.CreateFormatProcessor(format) as FormatProcessorBase; Assert.Throws <ArgumentException>(() => processor.ReadFromFile(filePath1)); Assert.Throws <ArgumentException>(() => processor.ReadFromFile(null)); processor.AddNewDataItem(new DateTime(), string.Empty, 100); processor.AddNewDataItem(new DateTime(2010, 02, 10), "VS", 200); Assert.DoesNotThrow(() => processor.SaveToFile(filePath1)); Assert.IsTrue(processor.SaveToFile(filePath1)); Assert.DoesNotThrow(() => processor.ReadFromFile(filePath1)); Assert.IsTrue(processor.ReadFromFile(filePath1)); Assert.DoesNotThrow(() => processor.SaveToFile(filePath2)); Assert.IsTrue(processor.SaveToFile(filePath2)); Assert.DoesNotThrow(() => processor.ReadFromFile(filePath2)); Assert.IsTrue(processor.ReadFromFile(filePath2)); File.Delete(filePath1); File.Delete(filePath2); }