0
Answer

Unit test private methods or refactor to internal?

Radim Motycka

Radim Motycka

10y
1k
1

Hi,

Pls advice I am quite new in TDD, and lets say I have class below, there are also some private methods.

Should I test them? I read some articles and they are against testing private methods.
 
What do you think?
 
thx a lot 
 

namespace EWSMailProcessor

{

public class AttachementsDownloader : IAttachementsDownloader

{

private readonly ExchangeService exchangeService;

private EmailMessage message;

public AttachementsDownloader(IKrukExchangeServiceFactory krukExchangeService)

{

this.exchangeService = krukExchangeService.CreateConnection();

}

public AttachementsDownloader()

//: this(new KrukExchangeServiceFactory())

{}

public IEnumerable<IEmail> DownloadEmailAttachment(SearchFilter searchFilter)

{

FindItemsResults<Item> findResults = this.exchangeService.FindItems(WellKnownFolderName.Inbox, searchFilter, new ItemView(100));

foreach (Item item in findResults.Items)

{

message = EmailMessage.Bind(this.exchangeService, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments, ItemSchema.HasAttachments));

if (HasEmailAttachement)

{

FileAttachment fileAttachment = message.Attachments[0] as FileAttachment;

fileAttachment.Load();

Email email = CreateEmailModel(item, message, fileAttachment);

yield return email;

// MoveMessageToArchive(message);

}

}

}

private Email CreateEmailModel(Item item, EmailMessage message, FileAttachment fileAttachment)

{

Email email = new Email();

email.MessageSubject = item.Subject;

email.Attachment = new System.IO.MemoryStream(fileAttachment.Content);

email.EmailMessage = message;

return email;

}

private FolderId FindArchiveFolderId()

{

Folder rootfolder = Folder.Bind(this.exchangeService, WellKnownFolderName.MsgFolderRoot);

rootfolder.Load();

List<FolderId> folderIdList = (from folder in rootfolder.FindFolders(new FolderView(40)) where folder.DisplayName == "Archiv" select folder.Id).ToList();

return folderIdList[0];

}

private void MoveMessageToArchive(EmailMessage message)

{

message.Move(FindArchiveFolderId());

}

public bool HasEmailAttachement

{

get

{

return message.HasAttachments;

}

}

}

}