public void Test_GetValue_WhenComponentNull_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); object x = null; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { propDescriptor.GetValue(x); Assert.Fail("Expected to throw an ArgumentNullException"); } //---------------Test Result ----------------------- catch (ArgumentNullException ex) { StringAssert.Contains("component", ex.ParamName); StringAssert.Contains("Value cannot be null.", ex.Message); } }
public void Test_Construct_ShouldConstruct() { //---------------Set up test pack------------------- IUIGridColumn gridColumn = GetGridColumnStub(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- PropertyDescriptor propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Test Result ----------------------- Assert.IsNotNull(propDescriptor); }
public void Test_IsReadOnly_WhenNotIsEditable_ShouldReturnTrue() { //---------------Set up test pack------------------- var gridColumn = GetGridColumnStub(); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.IsFalse(gridColumn.Editable); //---------------Execute Test ---------------------- var isReadOnly = propDescriptor.IsReadOnly; //---------------Test Result ----------------------- Assert.IsTrue(isReadOnly, "If gridColumn is not editable propDescriptor.ReadOnly should be true."); }
public void Test_Alignment_ShouldReturnAlignmentFromColumn() { //---------------Set up test pack------------------- IUIGridColumn gridColumn = GetGridColumnStub(); var expectedAlignment = RandomValueGen.GetRandomEnum <PropAlignment>(); gridColumn.Alignment = expectedAlignment; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.AreEqual(expectedAlignment, gridColumn.Alignment); //---------------Execute Test ---------------------- var alignment = propDescriptor.Alignment; //---------------Test Result ----------------------- Assert.AreEqual(expectedAlignment, alignment); }
public void Test_Name_ShouldBeGridColumnPropertyName() { //---------------Set up test pack------------------- IUIGridColumn gridColumn = GetGridColumnStub(); string expectedName = RandomValueGen.GetRandomString(); gridColumn.PropertyName = expectedName; PropertyDescriptor propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var actualPropDescriptorName = propDescriptor.Name; //propDescriptor.DisplayName //---------------Test Result ----------------------- Assert.AreEqual(expectedName, actualPropDescriptorName); }
public void Test_DisplayName_ShouldBeGridColumnDisplayName() { //---------------Set up test pack------------------- IUIGridColumn gridColumn = GetGridColumnStub(); var expectedDispalyName = RandomValueGen.GetRandomString(); gridColumn.Stub(column => column.GetHeading()).Return(expectedDispalyName); PropertyDescriptor propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.AreEqual(expectedDispalyName, gridColumn.GetHeading()); //---------------Execute Test ---------------------- var actualPropDescriptorDisplayName = propDescriptor.DisplayName; //---------------Test Result ----------------------- Assert.AreEqual(expectedDispalyName, actualPropDescriptorDisplayName); }
public void Test_ComponentType_ShouldReturnGridColumnsClassDefsClassType() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); IUIGridColumn gridColumn = GetGridColumnStub(classDef); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.IsNotNull(gridColumn.ClassDef); Assert.IsNotNull(gridColumn.ClassDef.ClassType); //---------------Execute Test ---------------------- var componentType = propDescriptor.ComponentType; //---------------Test Result ----------------------- Assert.AreSame(typeof(FakeBO), componentType); }
public void Test_PropertyType_ShouldReturnPropertyTypeFromColumn() { //---------------Set up test pack------------------- IUIGridColumn gridColumn = GetGridColumnStub(); Type expectedPropType = typeof(DateTime); gridColumn.Stub(column => column.GetPropertyType()).Return(expectedPropType); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.AreEqual(expectedPropType, gridColumn.GetPropertyType()); //---------------Execute Test ---------------------- var propertyType = propDescriptor.PropertyType; //---------------Test Result ----------------------- Assert.AreEqual(expectedPropType, propertyType); }
public void Test_Width_ShouldReturnWidthFromColumn() { //---------------Set up test pack------------------- IUIGridColumn gridColumn = GetGridColumnStub(); var expectedWidth = RandomValueGen.GetRandomInt(0, 33); gridColumn.Width = expectedWidth; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.AreEqual(expectedWidth, gridColumn.Width); //---------------Execute Test ---------------------- var width = propDescriptor.Width; //---------------Test Result ----------------------- Assert.AreEqual(expectedWidth, width); }
public void Test_LookupList_WhenSetOnProp_ShouldReturnList() { //---------------Set up test pack------------------- IUIGridColumn gridColumn = GetGridColumnStub(); ILookupList expectedLookupList = MockRepository.GenerateStub <ILookupList>(); gridColumn.Stub(column => column.LookupList).Return(expectedLookupList); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.IsNotNull(gridColumn.LookupList); //---------------Execute Test ---------------------- ILookupList lookupList = propDescriptor.LookupList; //---------------Test Result ----------------------- Assert.AreSame(expectedLookupList, lookupList); }
public void Test_GetValue_WhenComponentNotCorrectType_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { propDescriptor.GetValue(100); Assert.Fail("Expected to throw an InvalidCastException"); } //---------------Test Result ----------------------- catch (InvalidCastException ex) { StringAssert.Contains("You cannot GetValue since the component is not of type ", ex.Message); } }
public void Test_SetValue_WhenPropInfoNull_ShouldDoNothing() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "-FakeBOName-"; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn, null); FakeBO fakeBO = new FakeBO { FakeBOName = RandomValueGen.GetRandomString() }; //---------------Assert Precondition---------------- Assert.AreSame(classDef, gridColumn.ClassDef); Assert.AreSame(typeof(FakeBO), gridColumn.ClassDef.ClassType); Assert.IsNotNullOrEmpty(fakeBO.FakeBOName); //---------------Execute Test ---------------------- propDescriptor.SetValue(fakeBO, RandomValueGen.GetRandomString()); //---------------Test Result ----------------------- Assert.IsTrue(true, "If got here all is good"); }
public void Test_GetValue_WhenPropInfoNull_ShouldReturnNull() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "FakeBOName"; var propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn, null); FakeBO fakeBO = new FakeBO { FakeBOName = RandomValueGen.GetRandomString() }; //---------------Assert Precondition---------------- Assert.AreSame(classDef, gridColumn.ClassDef); Assert.AreSame(typeof(FakeBO), gridColumn.ClassDef.ClassType); Assert.IsNotNullOrEmpty(fakeBO.FakeBOName); //---------------Execute Test ---------------------- var actualValue = propDescriptor.GetValue(fakeBO); //---------------Test Result ----------------------- Assert.IsNull(actualValue); }
public void Test_GetValue_WhenComponentNotCorrectType_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { propDescriptor.GetValue(100); Assert.Fail("Expected to throw an InvalidCastException"); } //---------------Test Result ----------------------- catch (InvalidCastException ex) { StringAssert.Contains("You cannot GetValue since the component is not of type ", ex.Message); } }
public void Test_GetValue_WhenPropInfoNull_ShouldReturnNull() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "FakeBOName"; var propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn, null); FakeBO fakeBO = new FakeBO { FakeBOName = RandomValueGen.GetRandomString() }; //---------------Assert Precondition---------------- Assert.AreSame(classDef, gridColumn.ClassDef); Assert.AreSame(typeof(FakeBO), gridColumn.ClassDef.ClassType); Assert.IsNotNullOrEmpty(fakeBO.FakeBOName); //---------------Execute Test ---------------------- var actualValue = propDescriptor.GetValue(fakeBO); //---------------Test Result ----------------------- Assert.IsNull(actualValue); }
public void Test_ComponentType_ShouldReturnGridColumnsClassDefsClassType() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); IUIGridColumn gridColumn = GetGridColumnStub(classDef); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.IsNotNull(gridColumn.ClassDef); Assert.IsNotNull(gridColumn.ClassDef.ClassType); //---------------Execute Test ---------------------- var componentType = propDescriptor.ComponentType; //---------------Test Result ----------------------- Assert.AreSame(typeof(FakeBO), componentType); }
public void Test_Alignment_ShouldReturnAlignmentFromColumn() { //---------------Set up test pack------------------- IUIGridColumn gridColumn = GetGridColumnStub(); var expectedAlignment = RandomValueGen.GetRandomEnum<PropAlignment>();gridColumn.Alignment = expectedAlignment; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.AreEqual(expectedAlignment, gridColumn.Alignment); //---------------Execute Test ---------------------- var alignment = propDescriptor.Alignment; //---------------Test Result ----------------------- Assert.AreEqual(expectedAlignment, alignment); }
public void Test_LookupList_WhenSetOnProp_ShouldReturnList() { //---------------Set up test pack------------------- IUIGridColumn gridColumn = GetGridColumnStub(); ILookupList expectedLookupList = MockRepository.GenerateStub<ILookupList>(); gridColumn.Stub(column => column.LookupList).Return(expectedLookupList); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); //---------------Assert Precondition---------------- Assert.IsNotNull(gridColumn.LookupList); //---------------Execute Test ---------------------- ILookupList lookupList = propDescriptor.LookupList; //---------------Test Result ----------------------- Assert.AreSame(expectedLookupList, lookupList); }
public void Test_GetValue_WhenComponentNull_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn); object x = null; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { propDescriptor.GetValue(x); Assert.Fail("Expected to throw an ArgumentNullException"); } //---------------Test Result ----------------------- catch (ArgumentNullException ex) { StringAssert.Contains("component", ex.ParamName); StringAssert.Contains("Value cannot be null.", ex.Message); } }
public void Test_SetValue_WhenPropInfoNull_ShouldDoNothing() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "-FakeBOName-"; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectivePropSpy(gridColumn, null); FakeBO fakeBO = new FakeBO { FakeBOName = RandomValueGen.GetRandomString() }; //---------------Assert Precondition---------------- Assert.AreSame(classDef, gridColumn.ClassDef); Assert.AreSame(typeof(FakeBO), gridColumn.ClassDef.ClassType); Assert.IsNotNullOrEmpty(fakeBO.FakeBOName); //---------------Execute Test ---------------------- propDescriptor.SetValue(fakeBO, RandomValueGen.GetRandomString()); //---------------Test Result ----------------------- Assert.IsTrue(true, "If got here all is good"); }