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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:50:31+00:00 2026-05-14T01:50:31+00:00

I have googled this a little and didn’t really find the answer I needed.

  • 0

I have googled this a little and didn’t really find the answer I needed.

I am working on a webpage in C# with SQL Server and LINQ for a customer.
I want the users to be able to send messages to each other. So what I do is that I unit test this with data that actually goes into the database.

The problem is that I now depend on having at least 2 users who I know the ID of. Furthermore I have to clean up after my self. This leads to rather large unit tests that test alot in one test.

Lets say I would like to update a user. That would mean that I would have to ceate the user, update it, and then delete it. This a lot of assertions in one unit test and if it fails with updating i have to manually delete it.

If I would do it any other way, without saving the data to DB, I would not for sure be able to know that the data was present in the database after updating etc.

What is the proper way to do this without having a test that tests a lot of functionality in one test?

  • 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-14T01:50:32+00:00Added an answer on May 14, 2026 at 1:50 am

    Do all the test inside of a System.Transactions.TransactionScope block, and simply do not call Scope.Complete() … All changes will be rolled back when you exit, and other users will not be able to see the temporary data you create in the database, so the test process will only affect the test machine..

    You can enter a new user, read the database to verify that it was entered correctly, and whatever else you need to check, within the block of the TransactionScope…

    Have the single unit test method impersonate the two different users, all within the one transaction …

    e.g. code

       using (var scop = new System.Transactions.TransactionScope())
       {
           // all your test code and Asserts that access the database, 
           // writes and reads, from any class, ...
           // to commit at the very end of this block,
           // you would call
           // scop.Complete();  // ..... but don't and all will be rolled back
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Emacs. I have googled this but no good answer there.
I am sure I am just missing something. But I have googled this for
I need to replace a string in certain documents. I have googled this code,
I have googled a lot on this and i have found integrations of Linkedin
So I have googled whole day, got few answers how to do this, and
Ok I am still learning this... I have Googled and done some research but
My apologies if this is an easy one. I have Googled it up the
This is for certain a newbie mistake, I have googled for plenty of hours
I have tried to figure this out and googled through a fair few stack
I googled this many times but now I have to ask it here. I

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.