public void ManipulateFormatDataMonthFail(int day, int month, int year, int newMonth) { var dataItem = new FormatDataItem(); dataItem.SetDate(day, month, year); Assert.Throws <ArgumentException>(() => dataItem.SetMonth(newMonth)); }
public void CloneTest() { var clone = new FormatDataItem().Clone(); Assert.IsNotNull(clone); Assert.IsTrue(clone is IFormatDataItem); }
public void ManipulateFormatDataDaySuccess(int day, int month, int year, int newDay) { var dataItem = new FormatDataItem(); dataItem.SetDate(day, month, year); Assert.DoesNotThrow(() => dataItem.SetDay(newDay)); }
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 CreateFormatData() { Assert.Throws <ArgumentNullException>(() => new FormatDataItem(null)); var formatDataItem = new FormatDataItem(); Assert.IsNotNull(formatDataItem); Assert.IsNotNull(new FormatDataItem(formatDataItem)); Assert.IsTrue(formatDataItem is IFormatDataItem); }
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 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 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 ManipulateFormatDataDateStringSuccess(string date) { var formatDataItem = new FormatDataItem(); Assert.DoesNotThrow(() => formatDataItem.SetDate(date)); }
public void ManipulateFormatDataDateStringFail(string date) { var formatDataItem = new FormatDataItem(); Assert.Throws <ArgumentException>(() => formatDataItem.SetDate(date)); }
public void ManipulateFormatDataBrandNameSuccess(string brandName) { var dataItem = new FormatDataItem(); Assert.DoesNotThrow(() => dataItem.SetBrandName(brandName)); }
public void ManipulateFormatDataBrandNameFail(string brandName) { var dataItem = new FormatDataItem(); Assert.Throws <ArgumentNullException>(() => dataItem.SetBrandName(brandName)); }
public void ManipulateFormatDataPriceSuccess(int price) { var dataItem = new FormatDataItem(); Assert.DoesNotThrow(() => dataItem.SetPrice(price)); }
public void ManipulateFormatDataPriceFail(int price) { var dataItem = new FormatDataItem(); Assert.Throws <ArgumentOutOfRangeException>(() => dataItem.SetPrice(price)); }