Esempio n. 1
0
        void TestEmailAccount()
        {
            var testEmailAccount = GetTestEmailAccount();

            if (string.IsNullOrEmpty(testEmailAccount))
            {
                return;
            }
            CanTestEmailAccount = false;

            var testSource = new EmailSource(SelectedEmailSource.ToXml());

            if (!string.IsNullOrEmpty(FromAccount))
            {
                testSource.UserName = FromAccount;
                testSource.Password = Password;
            }
            testSource.TestFromAddress = testSource.UserName;
            testSource.TestToAddress   = testEmailAccount;

            Uri uri      = new Uri(new Uri(AppSettings.LocalHost), "wwwroot/sources/Service/EmailSources/Test");
            var jsonData = testSource.ToString();

            var requestInvoker = CreateWebRequestInvoker();

            requestInvoker.ExecuteRequest("POST", uri.ToString(), jsonData, null, OnTestCompleted);
        }
Esempio n. 2
0
        void TestEmailAccount()
        {
            var testEmailAccount = GetTestEmailAccount();

            if (string.IsNullOrEmpty(testEmailAccount))
            {
                Errors = new List <IActionableErrorInfo> {
                    new ActionableErrorInfo(() => IsToFocused = true)
                    {
                        Message = "Please supply a To address in order to Test."
                    }
                };
                return;
            }
            CanTestEmailAccount = false;

            var testSource = new EmailSource(SelectedEmailSource.ToXml());

            if (!string.IsNullOrEmpty(FromAccount))
            {
                testSource.UserName = FromAccount;
                testSource.Password = Password;
            }
            testSource.TestFromAddress = testSource.UserName;
            testSource.TestToAddress   = testEmailAccount;
            if (EmailAddresssIsAVariable(testEmailAccount))
            {
                return;
            }
            Uri uri      = new Uri(new Uri(AppSettings.LocalHost), "wwwroot/sources/Service/EmailSources/Test");
            var jsonData = testSource.ToString();

            var requestInvoker = CreateWebRequestInvoker();

            requestInvoker.ExecuteRequest("POST", uri.ToString(), jsonData, null, OnTestCompleted);
        }
        void Verify_TestEmailAccount(bool isTestResultValid, bool hasFromAccount)
        {
            //------------Setup for test--------------------------
            const string ExpectedUri      = AppLocalhost + "/wwwroot/sources/Service/EmailSources/Test";
            const string TestToAddress    = "*****@*****.**";
            const string TestFromAccount  = "*****@*****.**";
            const string TestFromPassword = "******";

            var result = new ValidationResult {
                IsValid = isTestResultValid
            };

            if (!isTestResultValid)
            {
                result.ErrorMessage = "Unable to connect to SMTP server";
            }

            var emailSource = new EmailSource
            {
                ResourceID   = Guid.NewGuid(),
                ResourceName = "EmailTest",
                UserName     = "******",
                Password     = "******",
            };

            var modelItem = CreateModelItem();

            modelItem.SetProperty("SelectedEmailSource", emailSource);
            modelItem.SetProperty("To", TestToAddress);


            var expectedSource = new EmailSource(emailSource.ToXml())
            {
                TestToAddress = TestToAddress
            };

            if (hasFromAccount)
            {
                modelItem.SetProperty("FromAccount", TestFromAccount);
                modelItem.SetProperty("Password", TestFromPassword);
                expectedSource.UserName        = TestFromAccount;
                expectedSource.Password        = TestFromPassword;
                expectedSource.TestFromAddress = TestFromAccount;
            }
            else
            {
                expectedSource.TestFromAddress = emailSource.UserName;
            }

            var expectedPostData = expectedSource.ToString();

            string postData          = null;
            var    webRequestInvoker = new Mock <IWebRequestInvoker>();

            webRequestInvoker.Setup(w => w.ExecuteRequest("POST", ExpectedUri, It.IsAny <string>(), null, It.IsAny <Action <string> >()))
            .Callback((string method, string url, string data, List <Tuple <string, string> > headers, Action <string> asyncCallback) =>
            {
                postData = data;
                asyncCallback(new Dev2JsonSerializer().Serialize(result));
            }).Returns(string.Empty)
            .Verifiable();

            var viewModel = CreateViewModel(new List <EmailSource> {
                emailSource
            }, modelItem);

            viewModel.WebRequestInvoker = webRequestInvoker.Object;

            Assert.IsTrue(viewModel.CanTestEmailAccount);

            //------------Execute Test---------------------------
            viewModel.TestEmailAccountCommand.Execute(null);

            //------------Assert Results-------------------------
            webRequestInvoker.Verify(w => w.ExecuteRequest("POST", ExpectedUri, It.IsAny <string>(), null, It.IsAny <Action <string> >()));
            Assert.IsNotNull(postData);
            Assert.AreEqual(expectedPostData, postData);
            Assert.IsTrue(viewModel.CanTestEmailAccount);
            if (isTestResultValid)
            {
                Assert.IsNull(viewModel.Errors);
            }
            else
            {
                Assert.IsNotNull(viewModel.Errors);
                Assert.AreEqual(result.ErrorMessage, viewModel.Errors[0].Message);
                Assert.IsFalse(viewModel.IsFromAccountFocused);
                viewModel.Errors[0].Do();
                Assert.IsTrue(viewModel.IsFromAccountFocused);
            }
        }