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.
ReadonlyAuthorizationTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ReadonlyAuthorizationTests.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 Csla.Test.Security;
12using UnitDriven;
13using System.Diagnostics;
14using System.Security.Claims;
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
25
27{
28#if TESTING
29 [DebuggerNonUserCode]
30 [DebuggerStepThrough]
31#endif
32 [TestClass()]
34 {
35 private static ClaimsPrincipal GetPrincipal(params string[] roles)
36 {
37 var identity = new ClaimsIdentity();
38 foreach (var item in roles)
39 identity.AddClaim(new Claim(ClaimTypes.Role, item));
40 return new ClaimsPrincipal(identity);
41 }
42
43 //[TestMethod()]
44 //public void TestAllowInstanceAndShared()
45 //{
46 // TestResults.Reinitialise();
47 // Csla.ApplicationContext.User = GetPrincipal("Admin");
48 // ReadOnlyPerson person = ReadOnlyPerson.GetReadOnlyPerson();
49 // Assert.AreEqual(true, Csla.ApplicationContext.User.IsInRole("Admin"));
50 // Assert.AreEqual("John", person.FirstName,"Should be able read first name");
51 // Assert.AreEqual("Doe", person.LastName, "Should be able read first name");
52 // Csla.ApplicationContext.User = new ClaimsPrincipal();
53 // TestResults.Reinitialise();
54 // Csla.ApplicationContext.User = GetPrincipal("Admin");
55 // ReadOnlyPerson clone = person.Clone();
56 // Assert.AreEqual(true, Csla.ApplicationContext.User.IsInRole("Admin"));
57 // Assert.AreEqual("John", clone.FirstName, "Should be able read first name of clone");
58 // Assert.AreEqual("Doe", clone.LastName, "Should be able read first name of clone");
59 // Csla.ApplicationContext.User = new ClaimsPrincipal();
60 //}
61
62 //[TestMethod()]
63 //[ExpectedException(typeof(Csla.Security.SecurityException))]
64 //public void TestDenyInstanceAndShared()
65 //{
66
67 // TestResults.Reinitialise();
68 // Csla.ApplicationContext.User = GetPrincipal("Admin");
69 // ReadOnlyPerson person = ReadOnlyPerson.GetReadOnlyPerson();
70 // Assert.AreEqual(true, Csla.ApplicationContext.User.IsInRole("Admin"));
71 // Assert.AreEqual("!", person.MiddleName, "Should not be able read middle name");
72 // Assert.AreEqual("!", person.PlaceOfBirth, "Should not be able read place of birth");
73 // Csla.ApplicationContext.User = new ClaimsPrincipal();
74 //}
75
76 //[TestMethod()]
77 //[ExpectedException(typeof(Csla.Security.SecurityException))]
78 //public void TestDenyInstanceAndSharedForClone()
79 //{
80
81 // TestResults.Reinitialise();
82 // Csla.ApplicationContext.User = GetPrincipal("Admin");
83 // ReadOnlyPerson person = ReadOnlyPerson.GetReadOnlyPerson().Clone();
84 // Assert.AreEqual(true, Csla.ApplicationContext.User.IsInRole("Admin"));
85 // Assert.AreEqual("!", person.MiddleName, "Should not be able read middle name");
86 // Assert.AreEqual("!", person.PlaceOfBirth, "Should not be able read place of birth");
87 // Csla.ApplicationContext.User = new ClaimsPrincipal();
88
89 //}
90 }
91}