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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:28:52+00:00 2026-05-26T17:28:52+00:00

I have a service containing the following method, which queries a repository, like so:

  • 0

I have a service containing the following method, which queries a repository, like so:

public IEnumerable<Variable> ListVariables(int instanceId, int instanceVersionId, TypeGroup typeGroup)
{
    return
        _variableRepository.Where(x => x.InstanceVersion.Instance.Id == instanceId && x.InstanceVersion.Version == instanceVersionId && x.VariableType.VariableTypeGroup.Id == Convert.ToInt32(typeGroup));
}   

I am trying to write a unit test to mock this call, like so:

[Test]
        public void ListVariables_Returns_Variables_From_Repository()
        {
            IEnumerable<Variable> reposVariables = new List<Variable>
                                                    {
                                                        new Variable {InstanceVersion = new InstanceVersion(), VariableType = new VariableType(), Value = "test value1"},
                                                        new Variable {InstanceVersion = new InstanceVersion(), VariableType = new VariableType(), Value = "test value2"},
                                                        new Variable {InstanceVersion = new InstanceVersion(), VariableType = new VariableType(), Value = "test value3"},
                                                        new Variable {InstanceVersion = new InstanceVersion(), VariableType = new VariableType(), Value = "test value4"}
                                                    };

            var mockVariableRepository = new Mock<IVariableRepository>();
            mockVariableRepository.Setup(y => y.Where(x => x.InstanceVersion.Instance.Id == 1 && x.InstanceVersion.Version == 1 && x.VariableType.VariableTypeGroup.Id == 1)).Returns(reposVariables).Verifiable();

            var service = CreateSpiralService(variableRepository: mockVariableRepository.Object);

            var result = service.ListVariables(1,1,TypeGroup.Information).ToList<Variable>();

            mockVariableRepository.Verify(y => y.Where(x => x.InstanceVersion.Instance.Id == 1 && x.InstanceVersion.Version == 1 && x.VariableType.VariableTypeGroup.Id == 1), Times.Once()); ;
            Assert.AreEqual(reposVariables, result);
        }

but when I run it, I get the following error:

Moq.MockException : 
Expected invocation on the mock once, but was 0 times: y => y.Where(x => (x.InstanceVersion.Instance.Id == 1 && x.InstanceVersion.Version == 1) && x.VariableType.VariableTypeGroup.Id == 1)

Configured setups:
y => y.Where(x => (x.InstanceVersion.Instance.Id == 1 && x.InstanceVersion.Version == 1) && x.VariableType.VariableTypeGroup.Id == 1), Times.Never

Performed invocations:
IReadOnlyNoIdRepository`1.Where(x => (((x.InstanceVersion.Instance.Id == value(Core.Services.Spiral.SpiralService+<>c__DisplayClass8).instanceId) AndAlso (x.InstanceVersion.Version == value(Core.Services.Spiral.SpiralService+<>c__DisplayClass8).instanceVersionId)) AndAlso (x.VariableType.VariableTypeGroup.Id == ToInt32(Convert(value(Core.Services.Spiral.SpiralService+<>c__DisplayClass8).typeGroup)))))

It seems that the expression I pass in as part of the repository setup in my test fixture is not matching the expression defined in the service itself. Subsequently, the Assert at the end does not hold true, as it “expects a list with 4 items, but actually returns a list of 0 items”

Does anyone have any idea what could be going wrong?

  • 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-26T17:28:53+00:00Added an answer on May 26, 2026 at 5:28 pm

    Upon further discussion with colleagues, this appears to be an issue with NHibernate itself. It does not match the two (identical) conditions in the Where statement.

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

Sidebar

Related Questions

I currently have service classes that look something like this public class UserService :
Well im trying a simple i have a simple web service like page containing
I have a WCF service where methods are alot like the following. Now, I
I have a simple WCF service method: [OperationContract] public SetupGameResult SetupGame(long player1Id, long player2Id,
I have a service contract that defines a method with a parameter of type
I have a vb.net application which runs as a service. I also have another
I have the following domain class: public class Product { public virtual Guid Id
I have a WCF Service Library containing five service contracts. The library is hosted
I have the following requirement. I have with me a database containing the contact
I have a VS2008 solution containing two projects, a web service (the actual work

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.