Invalid setup on a non-overridable member ?

794 views
Skip to first unread message

Diogo Menezes

unread,
Jul 14, 2010, 11:10:31 PM7/14/10
to moq...@googlegroups.com
Hi all, 

Im  trying to do this test method.

[TestMethod]
        public void Ao_Ler_Stream_Com_1_Linha_Deve_Ler_1_Linha()
        {
            var ms = new MemoryStream();

            var persistidor         = new Mock<IPersistidor>().Object;
            var importadorMock = new Mock<Importador>(ms, null, persistidor);

            importadorMock.Object.Processar();

            importadorMock.Verify(imp => imp.Persistidor.Persistir(It.IsAny<string>()), Times.Exactly(1));
        }  

But the method is throwing this exception: 

Test method TestProject.Dado_Um_Importador_Qualquer.Ao_Ler_Stream_Com_1_Linha_Deve_Ler_1_Linha threw exception:  System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->  System.ArgumentException: Invalid setup on a non-overridable member:
mock => mock.Persistidor.

Why it is happening ? IPersistidor is an interface so it can not be defined as virtual

--
Abraços,

Diogo Menezes
http://dmenezes.com.br
http://twitter.com/diogolmenezes

Daniel Cazzulino

unread,
Jul 15, 2010, 11:17:59 AM7/15/10
to moq...@googlegroups.com
the Importador.Persistidor property is the one that needs to be virtual.

/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471



Diogo Menezes

unread,
Jul 15, 2010, 11:59:44 AM7/15/10
to moq...@googlegroups.com
Thank´s ! You are the man :) fixed !

2010/7/15 Daniel Cazzulino <dan...@cazzulino.com>

Daniel Cazzulino

unread,
Jul 15, 2010, 3:54:06 PM7/15/10
to moq...@googlegroups.com
:)


/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Reply all
Reply to author
Forward
0 new messages