Smocks icon indicating copy to clipboard operation
Smocks copied to clipboard

Sequence contains more than one element

Open DavidKlempfner opened this issue 6 years ago • 0 comments

I am getting System.InvalidOperationException: 'Sequence contains more than one element' StackTrace:

   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Smocks.IL.Resolvers.MethodResolver.FindMethod(IEnumerable`1 candidates, String name, TypeReference[] parameterTypes, Boolean isGeneric, GenericBindingContext bindingContext)
   at Smocks.IL.Resolvers.MethodResolver.Resolve(MethodReference methodReference, GenericBindingContext bindingContext)
   at Smocks.IL.Resolvers.MethodResolver.Resolve(MethodReference methodReference)
   at Smocks.IL.ILGeneratorInstructionVisitor.VisitInlineTok(Instruction instruction, MethodReference methodReference)
   at Smocks.IL.InstructionExtensions.VisitInlineTok[T](Instruction instruction, IInstructionVisitor`1 visitor)
   at Smocks.IL.InstructionExtensions.Accept[T](Instruction instruction, IInstructionVisitor`1 visitor)
   at Smocks.IL.DynamicMethodCompiler.AddInstructions(IILGenerator generator, IEnumerable`1 instructions, Dictionary`2 locals)
   at Smocks.IL.DynamicMethodCompiler.Compile[T](TypeReference[] parameters, IEnumerable`1 instructions, IEnumerable`1 variables)
   at Smocks.IL.ExpressionDecompiler`1.Decompile(MethodBody body, Instruction instruction, Object target, Int32 expectedStackSize, Int32 stackEntriesToSkip)
   at Smocks.IL.ExpressionDecompiler`1.Decompile(MethodBody body, Instruction instruction, Object target)
   at Smocks.IL.SetupExtractor.<GetSetupsFromInstructions>d__10.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Smocks.Smock.CreateAssemblyRewriter(Delegate delegate, Configuration configuration)
   at Smocks.Smock.RunAction(Action`1 action, Configuration configuration)
   at Smocks.Smock.Run(Configuration configuration, Action`1 action)
   at Smocks.Smock.Run(Action`1 action)
   at Abc.Validation.ServiceInterface.Tests.SubBranchRepositoryTests.When_duplicate_ids_present_expect_exception() in C:\SubBranchRepositoryTests.cs:line 32

when running this code:

Guid duplicateId = new Guid("d3ae99d2-2b1f-4bde-889d-c99387fccd33");
            List<SubBranch> fakeSubBranches = new List<SubBranch>
                {
                    new SubBranch {  Id = duplicateId },
                    new SubBranch {  Id = duplicateId }
                };

            Mock<IDbConnection> dbConnectionMock = new Mock<IDbConnection>();

            Smock.Run(context =>
            {                
                context.Setup(() => OrmLiteReadApi.Select<SubBranch>(dbConnectionMock.Object)).Returns(fakeSubBranches);
            });

Please see this StackOverflow question for more info: https://stackoverflow.com/questions/53626381/mocking-ormlitereadapi-extension-methods

DavidKlempfner avatar Dec 05 '18 06:12 DavidKlempfner