public void Test_GetValue_WhenUseRelatedBOProp_ShouldReturnValueFromBO() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBOWSingleRelationship); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "FakeBOW2Props.Prop1"; var propDescriptor = new PropertyDescriptorPropDef(gridColumn); FakeBOW2Props fakeBO = new FakeBOW2Props { Prop1 = RandomValueGen.GetRandomString() }; FakeBOWSingleRelationship fakeBowSingleRelationship = new FakeBOWSingleRelationship { FakeBOW2Props = fakeBO }; //---------------Assert Precondition---------------- Assert.AreSame(classDef.ToString(), gridColumn.ClassDef.ToString()); Assert.AreSame(typeof(FakeBOWSingleRelationship), gridColumn.ClassDef.ClassType); Assert.IsNotNullOrEmpty(fakeBO.Prop1); //---------------Execute Test ---------------------- var actualValue = propDescriptor.GetValue(fakeBowSingleRelationship); //---------------Test Result ----------------------- Assert.AreEqual(fakeBO.Prop1, actualValue); }
public void Test_GetValue_WhenComponentNull_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); PropertyDescriptorPropDef propDescriptor = new PropertyDescriptorPropDef(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_GetValue_ShouldGetValueFromBO() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBOWSingleRelationship); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "FakeBOW2Props.Prop1"; PropertyDescriptorPropDef propDescriptor = new PropertyDescriptorPropDef(gridColumn); FakeBOW2Props fakeBO = new FakeBOW2Props {Prop1 = RandomValueGen.GetRandomString()}; FakeBOWSingleRelationship fakeBOwSingleRelationship = new FakeBOWSingleRelationship {FakeBOW2Props = fakeBO}; //---------------Assert Precondition---------------- Assert.AreSame(classDef, gridColumn.ClassDef); Assert.AreSame(typeof(FakeBOWSingleRelationship), gridColumn.ClassDef.ClassType); Assert.IsNotNullOrEmpty(fakeBO.Prop1); //---------------Execute Test ---------------------- var actualValue = propDescriptor.GetValue(fakeBOwSingleRelationship); //---------------Test Result ----------------------- Assert.AreEqual(fakeBO.Prop1, actualValue); }
public void Test_GetValue_WhenComponentNotCorrectType_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); PropertyDescriptorPropDef propDescriptor = new PropertyDescriptorPropDef(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_ShouldGetValueFromBO() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "FakeBOName"; PropertyDescriptorPropDef propDescriptor = new PropertyDescriptorPropDef(gridColumn); 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.AreEqual(fakeBO.FakeBOName, actualValue); }
public void Test_GetValue_WhenComponentNull_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); PropertyDescriptorPropDef propDescriptor = new PropertyDescriptorPropDef(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_GetValue_WhenComponentNotCorrectType_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); PropertyDescriptorPropDef propDescriptor = new PropertyDescriptorPropDef(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); } }