public async Task SendDocumentNotificationInvalidTests()
        {
            //Arrange
            var sendList = new List <string>
            {
                "*****@*****.**",
                "*****@*****.**"
            };
            DocumentSubscriberNotificationModel notification =
                new DocumentSubscriberNotificationModel
            {
                DocumentName   = "Unit test document.txt",
                UploaderName   = "MR UNIT TEST",
                UserName       = "******",
                EmailRecipient = sendList
            };

            //Act
            var response =
                await new SendEmailService().SendDocumentNotification(null, SendEmailServiceTests.Rooturl);

            //Assert
            Assert.IsFalse(response);

            notification.UserName = null;

            //Act
            response =
                await new SendEmailService().SendDocumentNotification(null, SendEmailServiceTests.Rooturl);

            //Assert
            Assert.IsFalse(response);

            notification.UserName     = "******";
            notification.DocumentName = null;

            //Act
            response =
                await new SendEmailService().SendDocumentNotification(null, SendEmailServiceTests.Rooturl);

            //Assert
            Assert.IsFalse(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send an email document subscription notification
        /// </summary>
        /// <param name="notification"></param>
        /// <param name="rooturl"></param>
        /// <returns></returns>
        public async Task <bool> SendDocumentNotification(DocumentSubscriberNotificationModel notification, string rooturl)
        {
            bool result = false;

            if (notification == null || string.IsNullOrEmpty(notification.UserName) || string.IsNullOrEmpty(notification.DocumentName) || string.IsNullOrEmpty(rooturl))
            {
                return(false);
            }

            string url     = $"{rooturl}api/sendemail?emailname={RoutingTasksTypeConstants.DocumentNotification}";
            string payload = new SerializerServices().SerializeObject(notification);

            HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().PostData(url, content);
                result = response.IsSuccessStatusCode;
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserName", notification.UserName },
                    { "WebServicesEndpoint", rooturl },
                    { "DocumentName", notification.DocumentName }
                };
                service.TrackEvent(LoggingServiceConstants.SendDocumentNotification, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Send the notifications to the document subscribers
        /// </summary>
        /// <param name="document"></param>
        /// <param name="rooturl"></param>
        /// <returns></returns>
        public async Task <bool> NotifySubscribers(DocumentsModel document, string rooturl)
        {
            if (document?.Subscribers == null || !document.Subscribers.Any() || string.IsNullOrEmpty(document.Name) || string.IsNullOrEmpty(document.UploadedByUsername))
            {
                return(false);
            }
            bool result = true;

            foreach (var subscriber in document.Subscribers)
            {
                var notification =
                    new DocumentSubscriberNotificationModel
                {
                    UserName       = subscriber.Username,
                    DocumentName   = document.Name,
                    UploaderName   = document.UploadedByUsername,
                    EmailRecipient = new List <string>()
                };
                notification.EmailRecipient.Add(subscriber.Email);
                var response = await new SendEmailService().SendDocumentNotification(notification, rooturl);
                result = result && response;
            }
            return(result);
        }