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); }
public void EmailDesignerViewModel_Handles_UpdateResourceMessageResourceIdAreNotTheSame_EmailSourceIsNotUpdated() { //------------Setup for test-------------------------- var emailSource = new EmailSource { ResourceID = Guid.NewGuid(), ResourceName = "Email1", UserName = "******", Password = "******" }; var emailSources = CreateEmailSources(2); var modelItem = ModelItemUtils.CreateModelItem(new DsfSendEmailActivity { SelectedEmailSource = emailSource }); var viewModel = CreateViewModel(new List<EmailSource> { emailSource }, modelItem); var updatedEmailSource = new EmailSource(emailSources[0].ToXml()) { ResourceID = Guid.NewGuid(), UserName = "******", Password = "******" }; //var xaml = new StringBuilder var resourceModel = new Mock<IContextualResourceModel>(); resourceModel.Setup(r => r.WorkflowXaml).Returns(new StringBuilder(updatedEmailSource.ToXml().ToString())); var message = new UpdateResourceMessage(resourceModel.Object); //------------Execute Test--------------------------- viewModel.Handle(message); //------------Assert Results------------------------- var selectedSource = viewModel.SelectedEmailSourceModelItemValue; Assert.AreNotEqual(updatedEmailSource.UserName, selectedSource.UserName); Assert.AreNotEqual(updatedEmailSource.Password, selectedSource.Password); }
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); } }
public void EmailSourceToXmlExpectedSerializesProperties() { var expected = new EmailSource { Host = "smtp.mydomain.com", Port = 25, EnableSsl = false, UserName = "******", Password = "******", Timeout = 1000, TestFromAddress = "*****@*****.**", TestToAddress = "*****@*****.**" }; var xml = expected.ToXml(); var actual = new EmailSource(xml); Assert.AreEqual(expected.ResourceType, actual.ResourceType); Assert.AreEqual(expected.Host, actual.Host); Assert.AreEqual(expected.Port, actual.Port); Assert.AreEqual(expected.EnableSsl, actual.EnableSsl); Assert.AreEqual(expected.UserName, actual.UserName); Assert.AreEqual(expected.Password, actual.Password); Assert.AreEqual(expected.Timeout, actual.Timeout); Assert.IsNull(actual.TestFromAddress); Assert.IsNull(actual.TestToAddress); }