Skip to main content
edited title
Source Link
sam
  • 23
  • 2

trying to use Factory pattern to create new MailMessage object by passing Abstracting an objectEmail Notification Service & testing the the logic of a different type and I'm trying to test the code which failsused abstract factory

[TestFixture] public class EmailMailMessageFactoryTests { private EmailNotification _emailNotification;

[TestFixture]
public class EmailMailMessageFactoryTests
{
    private EmailNotification _emailNotification;

[SetUp]
public void SetUp()
{
    _emailNotification = new EmailNotification("[email protected]", "[email protected];[email protected]", "subject", "body", true)
    {
        AttachmentsPaths = new List<string> { "1", "2" },
        CC = "[email protected]",
        BCC = "[email protected]"
    };
}

[Test]
public void CreateMailMessage_WhenCalled_CreatesMailMessage()
{
    var emailMailMessageFactory = new EmailMailMessageFactory("[email protected]");

    var result = emailMailMessageFactory.CreateMailMessage(_emailNotification);

    Assert.That(result.From.Address, Is.EqualTo(_emailNotification.From));
    Assert.That(result.To[0].Address, Is.EqualTo(_emailNotification.To));
    Assert.That(result.Subject, Is.EqualTo(_emailNotification.Subject));
    Assert.That(result.Body, Is.EqualTo(_emailNotification.Body));
    Assert.That(result.IsBodyHtml, Is.EqualTo(_emailNotification.IsBodyHtml));
    
    Assert.That(result.Attachments.Count, Is.EqualTo(_emailNotification.AttachmentsPaths.Count));
    //this assert fails "FileNotFoundException"

    Assert.That(result.CC[0].Address, Is.EqualTo(_emailNotification.CC));
    Assert.That(result.Bcc[0].Address, Is.EqualTo(_emailNotification.BCC));
}

trying to use Factory pattern to create new MailMessage object by passing an object of a different type and I'm trying to test the code which fails

[TestFixture] public class EmailMailMessageFactoryTests { private EmailNotification _emailNotification;

[SetUp]
public void SetUp()
{
    _emailNotification = new EmailNotification("[email protected]", "[email protected];[email protected]", "subject", "body", true)
    {
        AttachmentsPaths = new List<string> { "1", "2" },
        CC = "[email protected]",
        BCC = "[email protected]"
    };
}

[Test]
public void CreateMailMessage_WhenCalled_CreatesMailMessage()
{
    var emailMailMessageFactory = new EmailMailMessageFactory("[email protected]");

    var result = emailMailMessageFactory.CreateMailMessage(_emailNotification);

    Assert.That(result.From.Address, Is.EqualTo(_emailNotification.From));
    Assert.That(result.To[0].Address, Is.EqualTo(_emailNotification.To));
    Assert.That(result.Subject, Is.EqualTo(_emailNotification.Subject));
    Assert.That(result.Body, Is.EqualTo(_emailNotification.Body));
    Assert.That(result.IsBodyHtml, Is.EqualTo(_emailNotification.IsBodyHtml));
    
    Assert.That(result.Attachments.Count, Is.EqualTo(_emailNotification.AttachmentsPaths.Count));
    //this assert fails "FileNotFoundException"

    Assert.That(result.CC[0].Address, Is.EqualTo(_emailNotification.CC));
    Assert.That(result.Bcc[0].Address, Is.EqualTo(_emailNotification.BCC));
}

Abstracting an Email Notification Service & testing the the logic of the used abstract factory

[TestFixture]
public class EmailMailMessageFactoryTests
{
    private EmailNotification _emailNotification;

[SetUp]
public void SetUp()
{
    _emailNotification = new EmailNotification("[email protected]", "[email protected];[email protected]", "subject", "body", true)
    {
        AttachmentsPaths = new List<string> { "1", "2" },
        CC = "[email protected]",
        BCC = "[email protected]"
    };
}

[Test]
public void CreateMailMessage_WhenCalled_CreatesMailMessage()
{
    var emailMailMessageFactory = new EmailMailMessageFactory("[email protected]");

    var result = emailMailMessageFactory.CreateMailMessage(_emailNotification);

    Assert.That(result.From.Address, Is.EqualTo(_emailNotification.From));
    Assert.That(result.To[0].Address, Is.EqualTo(_emailNotification.To));
    Assert.That(result.Subject, Is.EqualTo(_emailNotification.Subject));
    Assert.That(result.Body, Is.EqualTo(_emailNotification.Body));
    Assert.That(result.IsBodyHtml, Is.EqualTo(_emailNotification.IsBodyHtml));
    
    Assert.That(result.Attachments.Count, Is.EqualTo(_emailNotification.AttachmentsPaths.Count));
    //this assert fails "FileNotFoundException"

    Assert.That(result.CC[0].Address, Is.EqualTo(_emailNotification.CC));
    Assert.That(result.Bcc[0].Address, Is.EqualTo(_emailNotification.BCC));
}
edited title
Source Link
sam
  • 23
  • 2

I need to know if I used a "factory pattern" in a right way trying to be ableuse Factory pattern to convertcreate new MailMessage object by passing an object of type1a different type and I'm trying to another object of type2test the code which fails

Maybe I'm misusing what's called Factory Pattern in my code! thanks

thanks in advance

I need to know if I used a "factory pattern" in a right way to be able to convert an object of type1 to another object of type2

Maybe I'm misusing what's called Factory Pattern in my code! thanks in advance

trying to use Factory pattern to create new MailMessage object by passing an object of a different type and I'm trying to test the code which fails

Maybe I'm misusing what's called Factory Pattern in my code!

thanks in advance

edited title
Link
sam
  • 23
  • 2

am I using the Factory pattern right in my code & howneed to know if I can test it?used a "factory pattern" in a right way to be able to convert an object of type1 to another object of type2

added 123 characters in body
Source Link
sam
  • 23
  • 2
Loading
added 3730 characters in body
Source Link
sam
  • 23
  • 2
Loading
formatting
Source Link
dfhwze
  • 13.9k
  • 3
  • 38
  • 101
Loading
added 27 characters in body
Source Link
sam
  • 23
  • 2
Loading
Source Link
sam
  • 23
  • 2
Loading