Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 809715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:46:17+00:00 2026-05-15T00:46:17+00:00

I downloaded Rhino Security today and started going through some of the tests. Several

  • 0

I downloaded Rhino Security today and started going through some of the tests. Several that run perfectly in isolation start getting errors after one that purposely raises an exception runs though. Here is that test:

    [Test]
    public void EntitiesGroup_IfDuplicateName_Error() {
        _authorizationRepository.CreateEntitiesGroup("Admininstrators");

        _session.Flush();

        var ex = Assert.Throws<GenericADOException>(
            () =>
                {
                    _authorizationRepository.CreateEntitiesGroup("Admininstrators");
                    _session.Flush();
                }).InnerException;

        Assert.That(ex.Message, Is.StringContaining("unique"));
    }

And here are the tests and error messages that fail:

    [Test]
    public void User_CanSave() {
        var ayende = new User {Name = "ayende"};
        _session.Save(ayende);
        _session.Flush();
        _session.Evict(ayende);

        var fromDb = _session.Get<User>(ayende.Id);
        Assert.That(fromDb, Is.Not.Null);
        Assert.That(ayende.Name, Is.EqualTo(fromDb.Name));
    }

  ----> System.Data.SQLite.SQLiteException : Abort due to constraint violation column Name is not unique


    [Test]
    public void UsersGroup_CanCreate()
    {
        var group = _authorizationRepository.CreateUsersGroup("Admininstrators");

        _session.Flush();
        _session.Evict(group);

        var fromDb = _session.Get<UsersGroup>(group.Id);
        Assert.NotNull(fromDb);
        Assert.That(fromDb.Name, Is.EqualTo(group.Name));
    }

 failed: NHibernate.AssertionFailure : null id in Rhino.Security.Tests.User entry (don't flush the Session after an exception occurs)

Does anyone see how I can reset the state of the in memory SQLite db after the first test? 

I changed the code to use nunit instead of xunit so maybe that is part of the problem here as well.

Cheers,
Berryl

This is the base class that instantiates the session

public abstract class DatabaseFixture : IDisposable
{
    protected Account _account;
    protected IAuthorizationRepository _authorizationRepository;
    protected IAuthorizationService _authorizationService;
    protected IPermissionsBuilderService _permissionsBuilderService;
    protected IPermissionsService _permissionService;
    protected User _user;

    protected ISession _session;
    protected readonly ISessionFactory _factory;

    protected DatabaseFixture()
    {
        BeforeSetup();

        SillyContainer.SessionProvider = (() => _session);
        var sillyContainer = new SillyContainer();
        ServiceLocator.SetLocatorProvider(() => sillyContainer);

        Assert.NotNull(typeof(System.Data.SQLite.SQLiteConnection));

        var cfg = new Configuration()
            .SetProperty(Environment.ConnectionDriver, typeof(SQLite20Driver).AssemblyQualifiedName)
            .SetProperty(Environment.Dialect, typeof(SQLiteDialect).AssemblyQualifiedName)
            .SetProperty(Environment.ConnectionString, ConnectionString)
            .SetProperty(Environment.ProxyFactoryFactoryClass, typeof(ProxyFactoryFactory).AssemblyQualifiedName)
            .SetProperty(Environment.ReleaseConnections, "on_close")
            .SetProperty(Environment.UseSecondLevelCache, "true")
            .SetProperty(Environment.UseQueryCache, "true")
            .SetProperty(Environment.CacheProvider,typeof(HashtableCacheProvider).AssemblyQualifiedName)
            .AddAssembly(typeof (User).Assembly);

        Security.Configure<User>(cfg, SecurityTableStructure.Prefix);

        _factory = cfg.BuildSessionFactory();

        _session = _factory.OpenSession();

        new SchemaExport(cfg).Execute(false, true, false, _session.Connection, null);

        _session.BeginTransaction();

        SetupEntities();

        _session.Flush();
    }

    protected virtual void BeforeSetup() { }

    public virtual string ConnectionString { get { return "Data Source=:memory:"; } }

    public void Dispose()
    {
        if (_session.Transaction.IsActive)
            _session.Transaction.Rollback();
        _session.Dispose();
    }

    private void SetupEntities()
    {
        _user = new User {Name = "Ayende"};
        _account = new Account {Name = "south sand"};

        _session.Save(_user);
        _session.Save(_account);

        _authorizationService = ServiceLocator.Current.GetInstance<IAuthorizationService>();
        _permissionService = ServiceLocator.Current.GetInstance<IPermissionsService>();
        _permissionsBuilderService = ServiceLocator.Current.GetInstance<IPermissionsBuilderService>();
        _authorizationRepository = ServiceLocator.Current.GetInstance<IAuthorizationRepository>();

        _authorizationRepository.CreateUsersGroup("Administrators");
        _authorizationRepository.CreateEntitiesGroup("Important Accounts");
        _authorizationRepository.CreateOperation("/Account/Edit");


        _authorizationRepository.AssociateUserWith(_user, "Administrators");
        _authorizationRepository.AssociateEntityWith(_account, "Important Accounts");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:46:17+00:00Added an answer on May 15, 2026 at 12:46 am

    How are you instantiating the session?

    Whenever there’s an exception, the session must be discarded. That also means you should almost never share the session between test methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have downloaded and compiled the newest version of Rhino by going ant compile
I've recently downloaded Rhino.Security and I am trying to implement permissions on a entity.
I downloaded a project from TouchMyPixel and when I try to run it with
I downloaded and edited a code that from internet, basically what I want to
I downloaded a binary file that was compiled (a C program) using GCC 4.4.4
I downloaded a few source codes containing C# code that uses windows forms. Is
Downloaded Facebook C# SDK 5.4.1 from here . I've been through the CS-WinForms solution
Downloaded IntelliJ IDEA Community Edition, realized that it has no JavaScript Support and Debugger.
Downloaded ASE from google code, and was looking through tutorials, and available scripts. I
I am new to Rhino Mocks. I have several models. One of them is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.