4

I'm having problems with a test. For some reason, that I haven't figured out, I can't access a n object's public property.

My class is the following:

public class FakeSMTPConnector : ISMTPConnector
{
    private bool _MailSent = false;
    public bool MailSent
    {
        get { return _MailSent; }
        set { _MailSent = value; }
    }

    private MailMessage _Message = null;
    public MailMessage Message
    {
        get { return _Message; }
        set { _Message = value; }
    }


    public FakeSMTPConnector()
    {

    }

    public void SendMail(MailMessage mail)
    {
        _MailSent = true;
        _Message = mail;
    }
}

I'm using this to simulate an SMTPConnection and send an email message. A class that handles email messages will then use this SMTPconnector to fake the delivery.

My test is as follows:

[Test]
    public void EnviarMensagemContactoSentTest()
    {
        //arrange
        FakeSMTPConnector connector = new FakeSMTPConnector();
        EmailManager manager = new EmailManager(connector);

        //act
        manager.SendMessage("a@a.com", "abc", "def", "ghi");

        //assert
        Assert.IsNotNull(manager, "Manager instance not created");
        Assert.IsTrue(connector.MailSent, "Message not sent");
        Assert.IsNotNull(connector.Message);
    }

When Nunit attempts the last assert, that acesses the Message property, it fails with an exception that doesn't make much sense:

System.MissingMethodException : Method not found: 'System.Net.Mail.MailMessage Project.FakeSMTPConnector.get_Message()'.

Am I doing anything wrong? I'm getting started adding tests and doing some refoactoring on a project so alot of this is kinda new and might be that I'm making somee confusion onsomething real basic up in my head...

Thanks!

MytyMyky
  • 608
  • 7
  • 15

2 Answers2

2

I know this is old, but I had the same issue. Cleaning Solution and then doing a Rebuild did not work for me.

Removing the offending dll from the GAC (C:\Windows\assembly) fixed it for me.

  • 2
    Can you elaborate? Do you mean the re-build didn't remove the dll, and you had to manually remove it to re-build? – BrDaHa Jun 06 '13 at 19:43
  • I had the same issue, because the software (with the same version number) I was debugging has already been installed in my laptop. My test project will not call the code but the assembly in `GAC (C:\Windows\assembly)`. The paths of modules used can be examined in `Modules` window. – Edward Jul 21 '21 at 08:47
0

Restarting Visual Studio did it for me.

Felix
  • 3,783
  • 5
  • 34
  • 53