Permalink
Browse files

Cleanup test

  • Loading branch information...
1 parent 6d8a95b commit 5483f5d692308e6b1273c6ef14c8880428ec7bb7 @PeterForstmeier PeterForstmeier committed Feb 6, 2011
@@ -22,8 +22,6 @@ public class BaseDataItem : BaseTextItem, IDataRenderer, IExportColumnBuilder, I
{
private string columnName;
-// private string dbValue;
-
#region Constructor
@@ -207,64 +207,48 @@ public override void Bind()
#endregion
+
public override void Fill(IDataItem item)
{
- if (current != null) {
- BaseDataItem baseDataItem = item as BaseDataItem;
-
- if (baseDataItem != null) {
+ if (item is BaseDataItem)
+ {
+ if (item.ColumnName.Contains(".")) {
+ string[] splittedNames = SplitNames(ref item);
- if (baseDataItem.ColumnName.Contains(".")) {
-
- string[] splittedNames = SplitNames(ref baseDataItem);
-
-
- PropertyDescriptor p = this.listProperties.Find(splittedNames[0], true);
-
- var propCollection = ExtendedTypeDescriptor.GetProperties(p.PropertyType);
-
-
- foreach (ExtendedPropertyDescriptor element in propCollection)
- {
- Console.WriteLine ("{0} - {1} - {2}",element.Name,element.ComponentType,element.PropertyType);
- }
-
-
- PropertyDescriptor ppp = propCollection.Find(splittedNames[1], true);
- object classValue = p.GetValue(this.Current);
- var v = ppp.GetValue(classValue);
-
- baseDataItem.DBValue = v.ToString();
-
-// Console.WriteLine("{0} - {1}",p.Name,p.PropertyType);
-
-
+ // PropDes for SubClass
+
+ PropertyDescriptor classProperty = this.listProperties.Find(splittedNames[0], true);
+ if (classProperty == null)
+ {
+ WrongColumnName (item);
}
else
-
{
- PropertyDescriptor p = this.listProperties.Find(baseDataItem.ColumnName, true);
-
- if (p != null)
- {
- var o = p.GetValue(this.Current);
-
- if (o != null) {
-// baseDataItem.DBValue = p.GetValue(this.Current).ToString();
- baseDataItem.DBValue = o.ToString();
- } else {
- baseDataItem.DBValue = String.Empty;
- }
-
- } else {
- baseDataItem.DBValue = string.Format(CultureInfo.InvariantCulture,"<{0}> missing!", baseDataItem.ColumnName);
- }
+ //all Props for SubClass
+ var propCollection = ExtendedTypeDescriptor.GetProperties(classProperty.PropertyType);
+
+ var subProperty = propCollection.Find(splittedNames[1], true);
+
+ var classValue = classProperty.GetValue(this.Current);
+ SetReturnValue(subProperty,classValue,item);
+ }
+ }
+ else
+ {
+ PropertyDescriptor p = this.listProperties.Find(item.ColumnName, true);
+ if (p != null) {
+ SetReturnValue(p,this.Current,item);
+ } else {
+ WrongColumnName (item);
}
-
- return;
}
+ return;
+ }
+ else
+ {
+
//image processing from IList
BaseImageItem baseImageItem = item as BaseImageItem;
@@ -277,80 +261,42 @@ public override void Fill(IDataItem item)
}
}
}
-
- object getvalueFromproperty(PropertyDescriptor p)
- {
- throw new NotImplementedException();
- }
- string[] SplitNames(ref BaseDataItem baseDataItem)
+
+ void WrongColumnName(IDataItem item)
{
- var i = baseDataItem.ColumnName.IndexOf(".");
- char[] delimiters = new char[] { '.' };
- var splittedNames = baseDataItem.ColumnName.Split(delimiters);
- return splittedNames;
+ item.DBValue = string.Format(CultureInfo.InvariantCulture, "Error : <{0}> missing!", item.ColumnName);
}
+
-
-
- public void old_Fill(IDataItem item)
+ void SetReturnValue(PropertyDescriptor p,object component,IDataItem item)
{
- if (current != null) {
- BaseDataItem baseDataItem = item as BaseDataItem;
- if (baseDataItem != null) {
- PropertyDescriptor p = this.listProperties.Find(baseDataItem.ColumnName, true);
-
- if (p != null)
- {
-// Console.WriteLine("PPPPPPPPPPPP {0}",p.PropertyType);
- var o = p.GetValue(this.Current);
- if (o != null) {
- baseDataItem.DBValue = p.GetValue(this.Current).ToString();
- } else {
- baseDataItem.DBValue = String.Empty;
- }
-
- } else {
- baseDataItem.DBValue = string.Format(CultureInfo.InvariantCulture,"<{0}> missing!", baseDataItem.ColumnName);
- }
- return;
- }
+ if (p != null)
+ {
+ var o = p.GetValue(component);
- //image processing from IList
- BaseImageItem baseImageItem = item as BaseImageItem;
-
- if (baseImageItem != null) {
- PropertyDescriptor p = this.listProperties.Find(baseImageItem.ColumnName, true);
- if (p != null) {
- baseImageItem.Image = p.GetValue(this.Current) as System.Drawing.Image;
- }
- return;
+ if (o != null) {
+ item.DBValue = o.ToString();
+ } else {
+ item.DBValue = String.Empty;
}
+
+ } else {
+ WrongColumnName(item);
}
}
-
- #region test
- /*
- public override CurrentItems FillDataRow()
+
+ string[] SplitNames(ref IDataItem item)
{
- CurrentItems ci = base.FillDataRow();
- DataRow row = this.Current as DataRow;
-
- if (row != null) {
- CurrentItem c = null;
-
- foreach (DataColumn dc in table.Columns)
- {
- c = new CurrentItem();
- c.ColumnName = dc.ColumnName;
- c.Value = row[dc.ColumnName];
- ci.Add(c);
- }
- }
- return ci;
+ var i = item.ColumnName.IndexOf(".");
+ char[] delimiters = new char[] { '.' };
+ var splittedNames = item.ColumnName.Split(delimiters);
+ return splittedNames;
}
- */
+
+
+ #region test
public override CurrentItemsCollection FillDataRow()
{
@@ -89,7 +89,7 @@ public void DataNavigator_Return_ErrMessage_If_ColumnName_NotExist ()
items.Add(item);
dataNav.Fill(items);
string str = "<" + item.ColumnName +">";
- Assert.That(item.DBValue.Contains(str));
+ Assert.That(item.DBValue.StartsWith("Error"));
}
@@ -288,8 +288,6 @@ public void SortDescendingByOneColumn()
Contributor view = dataNav.Current as Contributor;
string actual = view.Last;
Assert.GreaterOrEqual(compareTo,actual);
-// string ss = String.Format("< {0} > <{1}>",compareTo,actual);
-// Console.WriteLine(ss);
compareTo = actual;
}
Assert.IsTrue(dataNav.IsSorted);
@@ -392,33 +390,7 @@ public void RangeEnumeratorThrowExceptionIfStartGreateEnd ()
#endregion
#region get included class
- [Test]
- public void checkIfPropIsClass()
- {
- IDataManager dm = ICSharpCode.Reports.Core.DataManager.CreateInstance(this.contributorCollection,new ReportSettings());
- IDataNavigator dn = dm.GetNavigator;
- int start = 0;
- MyDummyClass dummy = new MyDummyClass();
-
- while (dn.MoveNext()) {
- dummy.DummyString = "dummy" + start.ToString();
- dummy.DummyInt = start;
- Contributor view = dn.Current as Contributor;
- view.DummyClass = dummy;
- Console.WriteLine(view.Last);
- start ++;
- }
-
- dn.Reset();
- dn.MoveNext();
- start = 0;
- while (dn.MoveNext()) {
- Contributor view = dn.Current as Contributor;
- Console.WriteLine("{0} - {1} - {2}",view.Last,view.DummyClass.DummyInt,view.DummyClass.DummyString);
- start ++;
- }
- Console.WriteLine(start);
- }
+
ContributorCollection ModifyCollection ()
{
@@ -438,15 +410,15 @@ ContributorCollection ModifyCollection ()
[Test]
- public void Prop ()
+ public void Collection_Contains_Subclass ()
{
var modifyedCollection = this.ModifyCollection();
IDataManager dm = ICSharpCode.Reports.Core.DataManager.CreateInstance(modifyedCollection,new ReportSettings());
IDataNavigator dn = dm.GetNavigator;
+
ReportItemCollection searchCol = new ReportItemCollection();
searchCol.Add(new BaseDataItem ()
{
- Name ="GroupItem",
ColumnName ="DummyClass.DummyString"
}
);
@@ -466,14 +438,63 @@ public void Prop ()
var a = (BaseDataItem)searchCol[0];
var b = (BaseDataItem)searchCol[1];
var c = modifyedCollection[dn.CurrentRow];
-// Console.WriteLine ("{0} - {1} - {2}",a.DBValue,b.DBValue,c.DummyClass.DummyString);
Assert.AreEqual(a.DBValue,c.DummyClass.DummyString);
Assert.AreEqual(b.DBValue,c.GroupItem);
}
}
- #region Setup/TearDown
+
+ [Test]
+ public void SubClassName_Is_Wrong ()
+ {
+ var modifyedCollection = this.ModifyCollection();
+ IDataManager dm = ICSharpCode.Reports.Core.DataManager.CreateInstance(modifyedCollection,new ReportSettings());
+ IDataNavigator dn = dm.GetNavigator;
+ ReportItemCollection searchCol = new ReportItemCollection();
+ searchCol.Add(new BaseDataItem ()
+ {
+ ColumnName ="wrong.DummyString",
+ DataType = "System.Int32"
+ }
+ );
+
+ dn.Reset();
+ dn.MoveNext();
+
+ while (dn.MoveNext()) {
+ dn.Fill(searchCol);
+ var a = (BaseDataItem)searchCol[0];
+ Assert.That(a.DBValue.StartsWith("Error"));
+ }
+ }
+
+ [Test]
+ public void SubPropertyName_Is_Wrong ()
+ {
+ var modifyedCollection = this.ModifyCollection();
+ IDataManager dm = ICSharpCode.Reports.Core.DataManager.CreateInstance(modifyedCollection,new ReportSettings());
+ IDataNavigator dn = dm.GetNavigator;
+ ReportItemCollection searchCol = new ReportItemCollection();
+ searchCol.Add(new BaseDataItem ()
+ {
+ Name ="GroupItem",
+ ColumnName ="DummyClass.Wrong",
+ DataType = "System.Int32"
+ }
+ );
+ dn.Reset();
+ dn.MoveNext();
+ while (dn.MoveNext()) {
+ dn.Fill(searchCol);
+ var a = (BaseDataItem)searchCol[0];
+ Assert.That(a.DBValue.StartsWith("Error"));
+ }
+ }
+
#endregion
+
+ #region Setup/TearDown
+
[TestFixtureSetUp]
public void Init()
{

0 comments on commit 5483f5d

Please sign in to comment.