public void InitializeContext() { var elementInfo1 = Mocks.Of<IElementInfo>().First(i => i.Name == "FooElementName" && i.DisplayName == "FooElementNameDisplayName"); var element1 = new Mock<IElement>(); element1.SetupGet(e => e.Info).Returns(elementInfo1); element1.As<IAbstractElement>().SetupGet(e => e.Info).Returns(elementInfo1); element1.As<IProductElement>().SetupGet(e => e.Info).Returns(elementInfo1); var elementInfo2 = Mocks.Of<IElementInfo>().First(i => i.Name == "BarElementName" && i.DisplayName == "BarElementNameDisplayName"); var element2 = new Mock<IElement>(); element2.Setup(e => e.InstanceName).Returns("FooElement2NameDisplayName"); element2.SetupGet(e => e.Info).Returns(elementInfo2); element2.As<IAbstractElement>().SetupGet(e => e.Info).Returns(elementInfo2); element2.As<IProductElement>().SetupGet(e => e.Info).Returns(elementInfo2); var viewInfo = new Mock<IViewInfo>(); viewInfo.SetupGet(v => v.Elements).Returns(new[] { elementInfo1, elementInfo2 }); var view = new Mock<IView>(); view.SetupGet(v => v.Info).Returns(viewInfo.Object); view.SetupGet(v => v.Elements).Returns(new[] { element1.Object, element2.Object }); var productInfo = new Mock<IPatternInfo>(); productInfo.SetupGet(pi => pi.Name).Returns("FooProductName"); productInfo.SetupGet(pi => pi.Views).Returns(new[] { viewInfo.Object }); var product = new Mock<IProduct>(); product.Setup(p => p.InstanceName).Returns("TestProduct"); product.As<IProduct>().SetupGet(p => p.Info).Returns(productInfo.Object); product.As<IProductElement>().SetupGet(p => p.Info).Returns(productInfo.Object); product.SetupGet(p => p.Views).Returns(new[] { view.Object }); this.rule = new CardinalityValidationRule(); this.rule.CurrentElement = product.Object; }
public void WhenNoChildElementName_ThenThrows() { var rule = new CardinalityValidationRule(); Assert.Throws<ValidationException>( () => rule.Validate().ToList()); }
public void WhenMinimunIsGreaterThanMaximun_ThenThrows() { var rule = new CardinalityValidationRule(); rule.ChildElementName = "Foo"; rule.Maximum = 1; rule.Minimum = 3; rule.CurrentElement = new Mock<IProduct>().Object; Assert.Throws<InvalidOperationException>(() => rule.Validate().ToList()); }