/
AuthorizationServiceWithSecondLevelCacheFixture.cs
77 lines (67 loc) · 2.66 KB
/
AuthorizationServiceWithSecondLevelCacheFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.IO;
using Microsoft.Practices.ServiceLocation;
using Rhino.Security.Interfaces;
using Xunit;
namespace Rhino.Security.Tests
{
public class AuthorizationServiceWithSecondLevelCacheFixture : DatabaseFixture
{
// we need those to ensure that we aren't leaving the 2nd level
// cache in an inconsistent state after deletion
//TODO: Add entity to group, save, remove and query
//TODO: Add user to group, save, remove and query
//TODO: Add nested users group save, remove and query
public override string ConnectionString
{
get
{
return "Data Source=test.db";
}
}
protected override void BeforeSetup()
{
if (File.Exists("test.db"))
File.Delete("test.db");
}
[Fact]
public void UseSecondLevelCacheForSecurityQuestions()
{
permissionsBuilderService
.Allow("/Account/Edit")
.For(user)
.On("Important Accounts")
.DefaultLevel()
.Save();
session.Flush();
session.Transaction.Commit();
session.Dispose();
using (var s2 = factory.OpenSession())// load into the 2nd level cache
using (s2.BeginTransaction())
{
SillyContainer.SessionProvider = () => s2;
var anotherAuthorizationService = ServiceLocator.Current.GetInstance<IAuthorizationService>();
Assert.True(anotherAuthorizationService.IsAllowed(user, account, "/Account/Edit"));
s2.Transaction.Commit();
}
using (var s2 = factory.OpenSession())//remove the data from the cache
using (s2.BeginTransaction())
{
using (var command = s2.Connection.CreateCommand())
{
command.CommandText = "DELETE FROM security_Permissions";
command.ExecuteNonQuery();
}
s2.Transaction.Commit();
}
using (var s3 = factory.OpenSession())
using (s3.BeginTransaction())
{
// should return true since it loads from cache
SillyContainer.SessionProvider = () => s3;
var anotherAuthorizationService = ServiceLocator.Current.GetInstance<IAuthorizationService>();
Assert.True(anotherAuthorizationService.IsAllowed(user, account, "/Account/Edit"));
s3.Transaction.Commit();
}
}
}
}