Hello,
In my Silverlight application, I have a ProductViewModel that holds a
SelectedItem (type of Product). The Component property inside the
Product normally throws an error when a null value is assigned to it.
I want to validate whether this scenario works correctly via Moq.
Here is the test method:
/// <summary>
/// Test method to validate a product with an empty component
is invalid.
/// </summary>
[Test]
public void TestValidateComponentRequired()
{
var productModel = new Product();
var productViewModel = new Mock<ProductViewModel>();
productViewModel.SetupProperty<Product>(p =>
p.SelectedItem, productModel); // SelectedItem will return
productModel
Product productModel2 =
productViewModel.Object.SelectedItem; // SelectedItem returns
productModel successfully
// HERE, p.SelectedItem returns null and I cannot setup
Component to throw an exception when it is assigned null
productViewModel.SetupSet(p => p.SelectedItem.Component =
null).Throws<Exception>().Verifiable();
try { productViewModel.Object.SelectedItem.Component =
null; }
catch { }
productViewModel.Verify();
}
--
Post:
moq...@googlegroups.com
Unsubscribe:
moqdisc-u...@googlegroups.com