Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The Test - Taken from 'http://dimecasts.net/Content/WatchEpisode/12' and re-written in 'AAA' syntax from Record and Playback. */
- [TestClass]
- public class UnitTest1
- {
- [TestMethod]
- public void EmailerServiceTest()
- {
- //Arrange
- var emailerService = MockRepository.GenerateMock<IEmailerService>();
- emailerService.Expect(x => x.SendEmail("", "")).IgnoreArguments().Return(true).Repeat.Any();
- //Act
- var emailer = new Emailer(emailerService);
- emailer.SendBatchEmails();
- //Assert Call ignore arguments becasue you don't care what they are
- emailerService.AssertWasCalled(x => x.SendEmail("", ""), y => y.IgnoreArguments());
- emailerService.VerifyAllExpectations();
- }
- [TestMethod, ExpectedException(typeof(Exception))]
- public void EmailerServiceTestException()
- {
- //Arrange
- var emailerService = MockRepository.GenerateMock<IEmailerService>();
- emailerService.Expect(x => x.SendEmail("", "")).IgnoreArguments().Return(false);
- //Act
- var emailer = new Emailer(emailerService);
- emailer.SendBatchEmails();
- //emailerService.AssertWasNotCalled(x => x.SendEmail("", ""), y => y.IgnoreArguments());
- }
- }
- //The Class
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TestLib
- {
- public interface IEmailerService
- {
- bool SendEmail(string email, string message);
- }
- public class EmailerService
- {
- public bool SendEmail(string email, string message)
- {
- return false;
- }
- }
- public class Emailer
- {
- private IEmailerService _emailerService;
- public Emailer(IEmailerService emailerService)
- {
- this._emailerService = emailerService;
- }
- public void SendBatchEmails()
- {
- var emails = new Dictionary<string, string>
- {
- };
- foreach(KeyValuePair<string, string> email in emails)
- {
- if(!_emailerService.SendEmail(email.Key, email.Value))
- {
- throw new Exception(" You've Err'd");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment