public void Test_SetValue_WhenComponentNull_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "FakeBOName"; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectiveProp(gridColumn); object x = null; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { propDescriptor.SetValue(x, "fdafd"); 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_ShouldSetValueOnBO() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "-FakeBOName-"; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectiveProp(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 expectedValue = RandomValueGen.GetRandomString(); propDescriptor.SetValue(fakeBO, expectedValue); //---------------Test Result ----------------------- Assert.AreEqual(expectedValue, fakeBO.FakeBOName); }
public void Test_SetValue_WhenComponentNotCorrectType_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub <IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "FakeBOName"; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectiveProp(gridColumn); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { propDescriptor.SetValue(100, "fdafd"); 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_WhenComponentNull_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "FakeBOName"; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectiveProp(gridColumn); object x = null; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { propDescriptor.SetValue(x, "fdafd"); 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_WhenComponentNotCorrectType_ShouldRaiseError() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "FakeBOName"; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectiveProp(gridColumn); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { propDescriptor.SetValue(100, "fdafd"); 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_ShouldSetValueOnBO() { //---------------Set up test pack------------------- IClassDef classDef = MockRepository.GenerateStub<IClassDef>(); classDef.ClassType = typeof(FakeBO); var gridColumn = GetGridColumnStub(classDef); gridColumn.PropertyName = "-FakeBOName-"; PropertyDescriptorReflectiveProp propDescriptor = new PropertyDescriptorReflectiveProp(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 expectedValue = RandomValueGen.GetRandomString(); propDescriptor.SetValue(fakeBO, expectedValue); //---------------Test Result ----------------------- Assert.AreEqual(expectedValue, fakeBO.FakeBOName); }