public void SendEmail_NoEmailService_Throws() { string to = "destination", header = "Great opportunity", body = "I am the Nigerian finance minister"; MyEmailClient ec = new MyEmailClient(); Assert.Throws <NullReferenceException>(() => ec.TryToSendEmail(to, header, body)); }
public void SendEmail_InvalidValues_Throws() { string to = "destination", header = "Great opportunity", body = "I am the Nigerian finance minister"; MyEmailClient ec = new MyEmailClient(); //ec.EmailService = new FakeEmailService(); var mock = new Mock <IEmailService>(); Assert.Throws <Exception>(() => ec.TryToSendEmail( null, header, body)); Assert.Throws <Exception>(() => ec.TryToSendEmail( to, null, body)); Assert.Throws <Exception>(() => ec.TryToSendEmail( to, header, null)); /*Assert.Throws<Exception>(() => ec.TryToSendEmail( * to, null, null)); <- onödig */ // TODO: test empty strings as well }
public void SendEmail_CorrectValues_Success() { string to = "destination", header = "Great opportunity", body = "I am the Nigerian finance minister"; MyEmailClient ec = new MyEmailClient(); ec.Name = "Antonio"; ec.Email = "*****@*****.**"; var mock = new Mock <IEmailService>(); ec.EmailService = mock.Object; //FakeEmailService fake = new FakeEmailService(); //ec.EmailService = fake; ec.TryToSendEmail(to, header, body); string from = ec.Name + " <" + ec.Email + ">"; mock.Verify(x => x.SendEmail(to, from, header, body), Times.Once()); // Assert.Equal(1, fake.HowManyTimesHasSendEmailBeenCalled); }