/// <summary> /// Method to send email /// </summary> /// <param name="recipient">The email address of the recipient</param> /// <param name="textContent">The text content of the email</param> /// <param name="htmlContent">The HTML content of the email</param> public void Send(string recipient, string textContent, string htmlContent = null) { EmailNotificationRegister emailNotification = new EmailNotificationRegister(recipient, textContent, htmlContent); notificationSender.RegisterTask(JsonConvert.SerializeObject(emailNotification), Subject.EMAIL); }
public void RegisterTask_EmailNotification_NotificationRegistered() { // Arrange EmailNotificationRegister notification = new EmailNotificationRegister("*****@*****.**", "plain text content"); string payload = JsonConvert.SerializeObject(notification); byte[] body = Encoding.UTF8.GetBytes(payload); Mock <IBasicProperties> basicPropertiesMock = new Mock <IBasicProperties>(); basicPropertiesMock.Setup(x => x.Persistent) .Verifiable(); Mock <IModel> modelMock = new Mock <IModel>(); modelMock.Setup(x => x.QueueDeclare(It.IsAny <string>(), It.Is <bool>(x => x), It.Is <bool>(x => x == false), It.Is <bool>(x => x == false), null)) .Verifiable(); modelMock.Setup(x => x.BasicQos(It.Is <uint>(x => x == 0), It.Is <ushort>(x => x == 1), It.Is <bool>(x => x == false))) .Verifiable(); modelMock.Setup(x => x.CreateBasicProperties()) .Returns(basicPropertiesMock.Object) .Verifiable(); modelMock.Setup(x => x.BasicPublish(It.IsAny <string>(), It.Is <string>(x => x == Subject.EMAIL.ToString()), It.Is <bool>(x => x == false), It.IsAny <IBasicProperties>(), It.IsAny <ReadOnlyMemory <byte> >())) .Verifiable(); Mock <IConnection> connectionMock = new Mock <IConnection>(); connectionMock.Setup(x => x.CreateModel()) .Returns(modelMock.Object); Mock <IRabbitMQConnectionFactory> connectionFactoryMock = new Mock <IRabbitMQConnectionFactory>(); connectionFactoryMock.CallBase = true; connectionFactoryMock.Setup(x => x.CreateConnection()) .Returns(connectionMock.Object); ITaskPublisher taskPublisher = new TaskPublisher(connectionFactoryMock.Object); // Act taskPublisher.RegisterTask(payload, Subject.EMAIL); // Assert connectionFactoryMock.Verify(); connectionMock.Verify(); modelMock.Verify(); }