CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
XamlPropertyInfoTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="XamlPropertyInfoTests.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using Csla;
11#if !NUNIT
12using System.Diagnostics;
13using Microsoft.VisualStudio.TestTools.UnitTesting;
14using System.Windows.Data;
15#else
16using NUnit.Framework;
17using TestClass = NUnit.Framework.TestFixtureAttribute;
18using TestInitialize = NUnit.Framework.SetUpAttribute;
19using TestCleanup = NUnit.Framework.TearDownAttribute;
20using TestMethod = NUnit.Framework.TestAttribute;
21#endif
22
24{
25 [TestClass]
27 {
28 [TestMethod]
29 public void NewObject()
30 {
31 var obj = new TestRoot();
32
33 var pi = new Csla.Xaml.PropertyInfo(true);
34 pi.DataContext = obj;
35 var binding = new System.Windows.Data.Binding("Name");
36 binding.Source = obj;
37 binding.Mode = System.Windows.Data.BindingMode.OneWay;
38 pi.SetBinding(Csla.Xaml.PropertyInfo.PropertyProperty, binding);
39
40 Assert.IsTrue(obj.IsValid, "object valid");
41 Assert.IsTrue(pi.IsValid, "pi valid");
42
43 obj.CheckRules();
44 Assert.IsFalse(obj.IsValid, "object invalid");
45 Assert.IsFalse(pi.IsValid, "pi invalid");
46
47 obj.Name = "Rocky";
48 Assert.IsTrue(obj.IsValid, "object valid after set");
49 Assert.IsTrue(pi.IsValid, "pi valid after set");
50 }
51 }
52
54 public class TestRoot : BusinessBase<TestRoot>
55 {
56 public static PropertyInfo<string> NameProperty = RegisterProperty<string>(c => c.Name);
57 public string Name
58 {
59 get { return GetProperty(NameProperty); }
60 set { SetProperty(NameProperty, value); }
61 }
62
63 protected override void AddBusinessRules()
64 {
65 base.AddBusinessRules();
66 BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(NameProperty));
67 }
68
69 public void CheckRules()
70 {
71 BusinessRules.CheckRules();
72 OnUnknownPropertyChanged();
73 }
74 }
75}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
Maintains metadata about a property.
Business rule for a required string.
Definition: CommonRules.cs:106
static PropertyInfo< string > NameProperty
Expose metastate information about a property.
object Source
Gets or sets the Source.
static readonly DependencyProperty PropertyProperty
Gets or sets the source business property to which this control is bound.
@ Serializable
Prevents updating or inserting until the transaction is complete.