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.
EditableGetSetRuleValidationTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="EditableGetSetValidationTests.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 System.ComponentModel;
10using UnitDriven;
12using Csla.Core;
14using Csla.TestHelpers;
15
16#if NUNIT
17using NUnit.Framework;
18using TestClass = NUnit.Framework.TestFixtureAttribute;
19using TestInitialize = NUnit.Framework.SetUpAttribute;
20using TestCleanup = NUnit.Framework.TearDownAttribute;
21using TestMethod = NUnit.Framework.TestAttribute;
22#elif MSTEST
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24#endif
26{
27#if TESTING
28 //[System.Diagnostics.DebuggerNonUserCode]
29#endif
30 [TestClass]
32 {
33 #region Constant(s)
34
35 private const string ID = "CSLA_TEST";
36
37 #endregion
38
39 private static TestDIContext _testDIContext;
40
42 public static void ClassInitialize(TestContext context)
43 {
44 _testDIContext = TestDIContextFactory.CreateDefaultContext();
45 }
46
47 #region Tests
48
49 [TestMethod]
51 {
52 IDataPortal<EditableGetSetRuleValidation> dataPortal = _testDIContext.CreateDataPortal<EditableGetSetRuleValidation>();
53
55
56 try
57 {
58 // get the required property and verify that it has the value that it was set to.
60 Assert.Fail("This property has a backing feild and an exception should of been thrown.");
61 }
62 catch (Exception ex)
63 {
64 Assert.IsTrue(true, ex.Message);
65 }
66 }
67
68 [TestMethod]
70 {
71 IDataPortal<EditableGetSetRuleValidation> dataPortal = _testDIContext.CreateDataPortal<EditableGetSetRuleValidation>();
72
74
75 try
76 {
77 // Set the required property and verify that it has the value that it was set to.
79 Assert.Fail("This property has a backing feild and an exception should of been thrown.");
80 }
81 catch (Exception ex)
82 {
83 Assert.IsTrue(true, ex.Message);
84 }
85 }
86
87 [TestMethod]
89 {
90 IDataPortal<EditableGetSetRuleValidation> dataPortal = _testDIContext.CreateDataPortal<EditableGetSetRuleValidation>();
91
93
94 // Verify that the id properties are not set.
95 Assert.IsTrue(egsv.Id.Equals(string.Empty));
96 Assert.IsTrue(egsv.MemberBackedId.Equals(string.Empty));
97
98 try
99 {
100 Assert.IsTrue(egsv.MemberBackedIdWithNoRelationshipTypes.Equals(string.Empty));
101 Assert.Fail("This property has a backing feild and an exception should of been thrown.");
102 }
103 catch (Exception ex)
104 {
105 Assert.IsTrue(true, ex.Message);
106 }
107
108 // Verify that the object is not valid.
109 Assert.IsFalse(egsv.IsValid, egsv.BrokenRulesCollection.ToString());
110
111 // Set the required property and verify that it has the value that it was set to.
112 egsv.Id = ID;
113 Assert.IsTrue(ID.Equals(egsv.Id));
114
115 // Set the required property and verify that it has the value that it was set to.
116 egsv.MemberBackedId = ID;
117 Assert.IsTrue(ID.Equals(egsv.MemberBackedId));
118
119 try
120 {
121 // Set the required property and verify that it has the value that it was set to.
122 egsv.MemberBackedIdWithNoRelationshipTypes = ID;
123 Assert.IsTrue(ID.Equals(egsv.MemberBackedIdWithNoRelationshipTypes));
124 }
125 catch (Exception ex)
126 {
127 Assert.IsTrue(true, ex.Message);
128 }
129
130 // Verify that the object is not valid.
131 Assert.IsFalse(egsv.IsValid, egsv.BrokenRulesCollection.ToString());
132 }
133
134 #endregion
135 }
136}
static EditableGetSetRuleValidation NewEditableGetSetValidation(IDataPortal< EditableGetSetRuleValidation > dataPortal)
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.
Definition: IDataPortalT.cs:17