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.
ValidationRules/DataAnnotationsTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DataAnnotationsTests.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Tests for functionality around Data Annotations attributes</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.ComponentModel.DataAnnotations;
11using System.Linq;
12using System.Text;
13using System.Threading.Tasks;
14using Csla.TestHelpers;
15using Microsoft.VisualStudio.TestTools.UnitTesting;
16
18{
19 [TestClass]
21 {
22 private static TestDIContext _testDIContext;
23
24 [ClassInitialize]
25 public static void Initialize(TestContext testcontext)
26 {
27 _testDIContext = TestDIContextFactory.CreateDefaultContext();
28 }
29
30 [TestMethod]
32 {
33 // Arrange
34 IDataPortal<TestObject> dataPortal = _testDIContext.CreateDataPortal<TestObject>();
35 TestObject testObject = dataPortal.Create();
36 int expected = 0;
37 int actual;
38
39 // Act
40 actual = testObject.BrokenRulesCollection.Count;
41
42 // Assert
43 Assert.AreEqual(expected, actual);
44
45 }
46
47 #region Private Helper Classes
48
49 private class TestObject : BusinessBase<TestObject>
50 {
51 public static PropertyInfo<string> TestPropertyProperty = RegisterProperty<string>(nameof(TestProperty));
52
53 [Required]
54 [DIBasedTest]
55 public string TestProperty
56 {
57 get { return GetProperty(TestPropertyProperty); }
58 set { SetProperty(TestPropertyProperty, value); }
59 }
60
61 [Create]
62 private void Create()
63 {
64 using (BypassPropertyChecks)
65 {
66 LoadProperty(TestPropertyProperty, "Test");
67 }
68 BusinessRules.CheckRules();
69 }
70 }
71
72 #endregion
73 }
74}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
Maintains metadata about a property.
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.
Definition: IDataPortalT.cs:17
object Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...