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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:44:40+00:00 2026-05-16T21:44:40+00:00

For my tests I need to mock out the data client, in my case

  • 0

For my tests I need to mock out the data client, in my case they are Oracle.

I have created my data access layer to allow this to be passed in:

public static Int32? GetUserRoleId(string userName, OracleConnection cn, OracleCommand cmd)

I am using Moq, though I can switch to another framework if needed, and when I go to create the Mock objects like this:

Mock<OracleConnection> mockOracleConnection = new Mock<OracleConnection>();
Mock<OracleCommand> mockOracleCommand = new Mock<OracleCommand>();

I get this error:

Failure: System.ArgumentException : Type to mock must be an interface or an abstract or non-sealed class.

Conclusion:
This was more simple than I thought! Just mock the DAL layer function like this:

mockDao.Setup(a => a.GetUserRoleId(userName, It.IsAny<OracleConnection>(), It.IsAny<OracleCommand>())).Returns(1);
  • 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-16T21:44:41+00:00Added an answer on May 16, 2026 at 9:44 pm

    You can make changes to use IDbConnection and IDbCommand (use interfaces and have a factory to provide the real objects in main code and mock objects in test – normally using Dependency Injection)

    Moq can only mock Interfaces and virtual methods.

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

Sidebar

Related Questions

I need help figuring out why my rspec tests are running slowly. I am
Sometimes in Salesforce tests you need to create User objects to run part of
For performance tests I need a way to measure the time needed for a
In some of my tests i need to check the order of Lists and
I've got some tests that need to count the number of warnings raised by
I am writing some Selenium tests and I need to be able to find
I need to cover some tests with JUnit. My method returns java.io.File. What are
I need some images as input for my tests. Where to locate the files
If you need to choose the language to write your integration tests, what language
I'm writing a service using Thrift and need to apply some tests to ensure

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.