Dev2.Runtime.ServiceModel.Data.EmailSource.ToXml C# (CSharp) Method

ToXml() public method

public ToXml ( ) : System.Xml.Linq.XElement
return System.Xml.Linq.XElement
        public override XElement ToXml()
        {
            var result = base.ToXml();
            var connectionString = string.Join(";",
                string.Format("Host={0}", Host),
                string.Format("UserName={0}", UserName),
                string.Format("Password={0}", Password),
                string.Format("Port={0}", Port),
                string.Format("EnableSsl={0}", EnableSsl),
                string.Format("Timeout={0}", Timeout)
                );

            result.Add(
                new XAttribute("ConnectionString", DpapiWrapper.Encrypt(connectionString)),
                new XAttribute("Type", ResourceType),
                new XElement("TypeOf", ResourceType)
                );

            return result;
        }

Usage Example

        public void EmailDesignerViewModel_TestEmailCommand_WhenToAddressIsVariable_ShouldBeError()
        {
            //------------Setup for test--------------------------
            const string ExpectedUri = AppLocalhost + "/wwwroot/sources/Service/EmailSources/Test";
            const string TestToAddress = "[[var1]]";
            const string TestFromAccount = "*****@*****.**";
            const string TestFromPassword = "******";

            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 };
            modelItem.SetProperty("FromAccount", TestFromAccount);
            modelItem.SetProperty("Password", TestFromPassword);
            expectedSource.UserName = TestFromAccount;
            expectedSource.Password = TestFromPassword;
            expectedSource.TestFromAddress = TestFromAccount;


            var webRequestInvoker = new Mock<IWebRequestInvoker>();
            webRequestInvoker.Setup(w => w.ExecuteRequest("POST", ExpectedUri, It.IsAny<string>(), null, It.IsAny<Action<string>>()))
                .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-------------------------
            Assert.IsNotNull(viewModel.Errors);
            Assert.AreEqual("Variable [[var1]] cannot be used while testing.", viewModel.Errors[0].Message);
            Assert.IsFalse(viewModel.IsFromAccountFocused);
            viewModel.Errors[0].Do();
            Assert.IsTrue(viewModel.IsFromAccountFocused);
        }
All Usage Examples Of Dev2.Runtime.ServiceModel.Data.EmailSource::ToXml