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 3441032
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:30:10+00:00 2026-05-18T08:30:10+00:00

How do I test for state in a S#arp Architecture project? For example, I

  • 0

How do I test for state in a S#arp Architecture project?

For example, I have a custom RoleProvider. I want to test the method provider.AddUsersToRoles(string[], string[]).

So I start with:

// Arrange
const string ficticiousRole = "Management";
var userToExpect = UserInstanceFactory.CreateValidTransientUser();
var roleToExpect = RoleInstanceFactory.CreateValidTransientRole();

userRepository.Expect(r => r.GetByUsername(userToExpect.Username))
              .Return(userToExpect);
roleRepository.Expect(r => r.GetByName(ficticiousRole))
              .Return(roleToExpect);

var userNames = new List<string>();
var roleNames = new List<string>();
userNames.Add(userToExpect.Username);
roleNames.Add(ficticiousRole);

Then I add the user to a role. Then I check if the user is in this role.

// Act
roleProvider.AddUsersToRoles(userNames.ToArray(), roleNames.ToArray());
var isNewUserInRole = roleProvider.IsUserInRole(userToExpect.Username, ficticiousRole);

// Assert
Assert.IsTrue(isNewUserInRole);

The problem is that I’m using Rhino Mocks. I have limited knowledge of Rhino Mocks, but from what I understand (according to Ayende Rahien) you use Rhino Mocks to test for operations, not state.

So I guess an in-memory SqlLite db would be more suitable? What’s the best way to do this in S#arp Arch?

  • 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-18T08:30:11+00:00Added an answer on May 18, 2026 at 8:30 am

    You can’t do that with Rhino Mocks since that is simply a mocking framework that fakes things like database calls, etc. It sounds like you actually want to test persistence to the database which is basically database integration testing. In that case, you would most definitely want to use an in-memory database such as SqlLite (if possible!) as opposed to hitting a SQL Server instance.

    What you want to do is at the beginning of each test or test class is tear down the database if it exists already, rebuild the database, populate the database with some seed data and then test your database interaction. This way, you can ensure you have a known database state before each test is run.

    One thing I did on a project was grouped all of my read-only tests into one test class so that I only had to do the database rebuild step once for the class and moved all my delete, update and insert tests into other test classes that rebuilt the database before each and every test. Given enough tests, this can be quite time consuming and may want to be relegated to CI server.

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

Sidebar

Related Questions

I want to test for transition from one state to another. I have defined
Our Test DB is suddenly missing rows. We want them back. Is there a
Given test.txt containing: test message I want to end up with: testing a message
I'm trying to get a web app working based on the S#arp Architecture. At
I'm trying to write a basic test game state singleton in cocos2d, but for
Is there some global state somewhere that I can access the currently-running test name?
I have a stored procedure in a test instance of a sql server (named
I am using AppFabric as the session state provider in my ASP.Net MVC2 app,
I have a project that adds elements to an AutoCad drawing. I noticed that
Test Driven Development has been the rage in the .NET community for the last

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.