public void Test_CanResetValue_WhenNotDirty_ShouldReturnFalse() { //---------------Set up test pack------------------- var propertyInfo = typeof(FakeBO).GetProperty("FakeBOName"); var propDescriptor = new PropertyDescriptorPropInfo(propertyInfo); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var canResetValue = propDescriptor.CanResetValue(new FakeBO()); //---------------Test Result ----------------------- Assert.IsFalse(canResetValue); }
public void Test_CanResetValue_When_ShouldReturnTrue() { //---------------Set up test pack------------------- var propertyInfo = typeof(FakeBO).GetProperty("FakeBOName"); var propDescriptor = new PropertyDescriptorPropInfo(propertyInfo); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var fakeBO = new FakeBO { FakeBOName = RandomValueGen.GetRandomString() }; var canResetValue = propDescriptor.CanResetValue(fakeBO); //---------------Test Result ----------------------- Assert.IsFalse(canResetValue); }
public void Test_ShouldSerializeValue_WhenReadOnly_ShouldRetFalse() { //---------------Set up test pack------------------- var propertyInfo = MockRepository.GenerateStub <FakePropertyInfo>(); propertyInfo.Stub(info => info.Name).Return(GetRandomString()); propertyInfo.Stub(info => info.GetSetMethod(false)).Return(null); PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfo(propertyInfo); //---------------Assert Precondition---------------- Assert.IsNull(propertyInfo.GetSetMethod(false)); Assert.IsTrue(propDescriptor.IsReadOnly); //---------------Execute Test ---------------------- var shouldSerializeValue = propDescriptor.ShouldSerializeValue(new FakeBO()); //---------------Test Result ----------------------- Assert.IsFalse(shouldSerializeValue); }
public void Test_SetValue_WhenComponentNotCorrectType_ShouldRaiseError() { //---------------Set up test pack------------------- var propertyInfo = typeof(FakeBO).GetProperty("FakeBOName"); var propDescriptor = new PropertyDescriptorPropInfo(propertyInfo); //---------------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_GetValue_ShouldGetValueFromBO() { //---------------Set up test pack------------------- var propertyInfo = typeof(FakeBO).GetProperty("FakeBOName"); var expectedPropValue = RandomValueGen.GetRandomString(); var fakeBO = new FakeBO { FakeBOName = expectedPropValue }; var propDescriptor = new PropertyDescriptorPropInfo(propertyInfo); //---------------Assert Precondition---------------- Assert.AreEqual(expectedPropValue, propertyInfo.GetValue(fakeBO, null)); Assert.AreEqual(expectedPropValue, fakeBO.FakeBOName); //---------------Execute Test ---------------------- var actualValue = propDescriptor.GetValue(fakeBO); //---------------Test Result ----------------------- Assert.AreEqual(expectedPropValue, actualValue); }
public void Test_SetValue_WhenComponentNull_ShouldRaiseError() { //---------------Set up test pack------------------- var propertyInfo = typeof(FakeBO).GetProperty("FakeBOName"); var propDescriptor = new PropertyDescriptorPropInfo(propertyInfo); 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------------------- var propertyInfo = typeof(FakeBO).GetProperty("FakeBOName"); var initialPropValue = GetRandomString(); var fakeBO = new FakeBO { FakeBOName = initialPropValue }; var propDescriptor = new PropertyDescriptorPropInfo(propertyInfo); //---------------Assert Precondition---------------- Assert.AreEqual(initialPropValue, propertyInfo.GetValue(fakeBO, null)); Assert.AreEqual(initialPropValue, fakeBO.FakeBOName); //---------------Execute Test ---------------------- var expectedNewPropValue = GetRandomString(); propDescriptor.SetValue(fakeBO, expectedNewPropValue); //---------------Test Result ----------------------- Assert.AreEqual(expectedNewPropValue, fakeBO.FakeBOName); }
public void Test_GetValue_ShouldGetValueFromBO() { //---------------Set up test pack------------------- var propertyInfo = typeof (FakeBO).GetProperty("FakeBOName"); var expectedPropValue = RandomValueGen.GetRandomString(); var fakeBO = new FakeBO { FakeBOName = expectedPropValue }; var propDescriptor = new PropertyDescriptorPropInfo(propertyInfo); //---------------Assert Precondition---------------- Assert.AreEqual(expectedPropValue, propertyInfo.GetValue(fakeBO, null)); Assert.AreEqual(expectedPropValue, fakeBO.FakeBOName); //---------------Execute Test ---------------------- var actualValue = propDescriptor.GetValue(fakeBO); //---------------Test Result ----------------------- Assert.AreEqual(expectedPropValue, actualValue); }
public void Test_ShouldSerializeValue_WhenReadOnly_ShouldRetFalse() { //---------------Set up test pack------------------- var propertyInfo = MockRepository.GenerateStub<FakePropertyInfo>(); propertyInfo.Stub(info => info.Name).Return(GetRandomString()); propertyInfo.Stub(info => info.GetSetMethod(false)).Return(null); PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfo(propertyInfo); //---------------Assert Precondition---------------- Assert.IsNull(propertyInfo.GetSetMethod(false)); Assert.IsTrue(propDescriptor.IsReadOnly); //---------------Execute Test ---------------------- var shouldSerializeValue = propDescriptor.ShouldSerializeValue(new FakeBO()); //---------------Test Result ----------------------- Assert.IsFalse(shouldSerializeValue); }