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.
SeverityTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="SeverityTests.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 SeverityTests
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 AllThree()
39 {
40 IDataPortal<SeverityRoot> dataPortal = _testDIContext.CreateDataPortal<SeverityRoot>();
41
42 SeverityRoot root = dataPortal.Create();
43 root.Validate();
44
45 Assert.AreEqual(3, root.BrokenRulesCollection.Count, "3 rules should be broken (total)");
46
47 Assert.IsFalse(root.IsValid, "Object should not be valid");
48
49 Assert.AreEqual(1, root.BrokenRulesCollection.ErrorCount, "Only one rule should be broken");
50 Assert.AreEqual("Always error", root.BrokenRulesCollection.GetFirstBrokenRule("Test").Description, "'Always error' should be broken (GetFirstBrokenRule)");
51 Assert.AreEqual("Always error", root.BrokenRulesCollection.GetFirstMessage("Test", Csla.Rules.RuleSeverity.Error).Description, "'Always error' should be broken");
52
53 Assert.AreEqual(1, root.BrokenRulesCollection.WarningCount, "Only one warning should be broken");
54 Assert.AreEqual("Always warns", root.BrokenRulesCollection.GetFirstMessage("Test", Csla.Rules.RuleSeverity.Warning).Description, "'Always warns' should be broken");
55
56 Assert.AreEqual(1, root.BrokenRulesCollection.InformationCount, "Only one info should be broken");
57 Assert.AreEqual("Always info", root.BrokenRulesCollection.GetFirstMessage("Test", Csla.Rules.RuleSeverity.Information).Description, "'Always info' should be broken");
58 }
59
60 [TestMethod]
61 public void NoError()
62 {
63 IDataPortal<NoErrorRoot> dataPortal = _testDIContext.CreateDataPortal<NoErrorRoot>();
64
65 NoErrorRoot root = dataPortal.Create();
66 root.Validate();
67 Assert.AreEqual(2, root.BrokenRulesCollection.Count, "2 rules should be broken (total)");
68
69 Assert.IsTrue(root.IsValid, "Object should be valid");
70 Assert.AreEqual(0, root.BrokenRulesCollection.ErrorCount, "No rules (errors) should be broken");
71
72 Assert.AreEqual(1, root.BrokenRulesCollection.WarningCount, "Only one warning should be broken");
73 Assert.AreEqual("Always warns", root.BrokenRulesCollection.GetFirstMessage("Test", Csla.Rules.RuleSeverity.Warning).Description, "'Always warns' should be broken");
74
75 Assert.AreEqual(1, root.BrokenRulesCollection.InformationCount, "Only one info should be broken");
76 Assert.AreEqual("Always info", root.BrokenRulesCollection.GetFirstMessage("Test", Csla.Rules.RuleSeverity.Information).Description, "'Always info' should be broken");
77 }
78 }
79}
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...