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.
ShortCircuitTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ShortCircuitTests.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.Collections.Generic;
10using System.Text;
11using UnitDriven;
12using Csla.TestHelpers;
13
14#if NUNIT
15using NUnit.Framework;
16using TestClass = NUnit.Framework.TestFixtureAttribute;
17using TestInitialize = NUnit.Framework.SetUpAttribute;
18using TestCleanup = NUnit.Framework.TearDownAttribute;
19using TestMethod = NUnit.Framework.TestAttribute;
20#elif MSTEST
21using Microsoft.VisualStudio.TestTools.UnitTesting;
22#endif
23
25{
26 [TestClass()]
27 public class ShortCircuitTests
28 {
29 private static TestDIContext _testDIContext;
30
32 public static void ClassInitialize(TestContext testContext)
33 {
34 _testDIContext = TestDIContextFactory.CreateDefaultContext();
35 }
36
37 [TestMethod]
38 public void ShortCircuitOnNew()
39 {
40 IDataPortal<ShortCircuit> dataPortal = _testDIContext.CreateDataPortal<ShortCircuit>();
41
42 ShortCircuit root = dataPortal.Create();
43 root.CheckRules();
44 Assert.AreEqual(1, root.BrokenRulesCollection.ErrorCount, "Only one rule should be broken");
45 Assert.AreEqual("Test required", root.BrokenRulesCollection.GetFirstBrokenRule("Test").Description, "'Test required' should be broken");
46 }
47
48 [TestMethod]
50 {
51 IDataPortal<ShortCircuit> dataPortal = _testDIContext.CreateDataPortal<ShortCircuit>();
52
53 ShortCircuit root = dataPortal.Create();
54 root.CheckRules();
55 root.Test = "some data";
56 Assert.AreEqual(1, root.BrokenRulesCollection.ErrorCount, "Only one rule should be broken with data");
57 Assert.AreEqual("Always error", root.BrokenRulesCollection.GetFirstBrokenRule("Test").Description, "'Always fails' should be broken");
58 root.Test = "";
59 Assert.AreEqual(1, root.BrokenRulesCollection.ErrorCount, "Only one rule should be broken when empty");
60 Assert.AreEqual("Test required", root.BrokenRulesCollection.GetFirstBrokenRule("Test").Description, "'Test required' should be broken");
61 }
62
63 [TestMethod]
64 public void HigherThreshold()
65 {
66 IDataPortal<ShortCircuit> dataPortal = _testDIContext.CreateDataPortal<ShortCircuit>();
67
68 ShortCircuit root = dataPortal.Create();
69 root.CheckRules();
70 Assert.AreEqual(1, root.BrokenRulesCollection.ErrorCount, "Only one rule should be broken");
71 Assert.AreEqual("Test required", root.BrokenRulesCollection.GetFirstBrokenRule("Test").Description, "'Test required' should be broken");
72
73 root.Threshold = 100;
74 root.CheckRules();
75 Assert.AreEqual(2, root.BrokenRulesCollection.ErrorCount, "Two rules should be broken after checkrules");
76 root.Test = "some data";
77 Assert.AreEqual(1, root.BrokenRulesCollection.ErrorCount, "One rule should be broken with data");
78 Assert.AreEqual("Always error", root.BrokenRulesCollection.GetFirstBrokenRule("Test").Description, "'Always fails' should be broken");
79 root.Test = "";
80 Assert.AreEqual(2, root.BrokenRulesCollection.ErrorCount, "Two rules should be broken when empty");
81 }
82 }
83}
static void ClassInitialize(TestContext testContext)
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...