private void Unsubscribe(string unsubscribeToken) { // now unsubscribe homeController.Unsubscribe(listName, unsubscribeToken); // validate that we are unsubscribed using var db = dbProvider.GetDatabase(); MailListSubscription reg = db.Subscriptions.FirstOrDefault(); Assert.AreNotEqual(default(DateTime), reg.UnsubscribedDate); }
private string Subscribe() { using (var db = dbProvider.GetDatabase()) { db.Lists.Add(new MailList { Name = listName, FromEmailAddress = fromAddress, FromEmailName = fromName, Company = company, PhysicalAddress = fullAddress, Website = website }); db.SaveChanges(); } expectedSubject = "Hello Bob"; expectedBody = "<!-- Subject: Hello Bob --> Body: Last Name Smith, Subscribe: https://testdomain.com/SubscribeWelcome/TestList?token={subscribe-token}, Unsubscribe: "; homeController.SubscribeInitialPost(listName, new Dictionary <string, string> { { "ff_firstName", "Bob" }, { "ff_lastName", "Smith" }, { "ff_emailAddress", mailAddress }, { "ff_company_optional", null } }).Sync(); // check database for registration MailListSubscription reg = null; using (var db = dbProvider.GetDatabase()) { reg = db.Subscriptions.FirstOrDefault(); Assert.NotNull(reg); Assert.AreEqual("Bob", reg.Fields["firstName"]); Assert.AreEqual("Smith", reg.Fields["lastName"]); Assert.AreEqual(mailAddress, reg.EmailAddress); Assert.IsEmpty(reg.Fields["company"] as string); Assert.IsNotNull(reg.SubscribeToken); Assert.IsNull(reg.UnsubscribeToken); Assert.AreEqual(default(DateTime), reg.SubscribedDate); Assert.AreEqual(default(DateTime), reg.UnsubscribedDate); Assert.AreNotEqual(default(DateTime), reg.Expires); } // verify the subscribe confirm has no errors homeController.SubscribeConfirm(listName); Assert.AreEqual(1, sentMailCount); sentMailCount = 0; // perform the final subscribe action expectedSubject = "Hello2 Bob"; expectedBody = "<!-- Subject: Hello2 Bob --> Body2: Last Name Smith, Subscribe: , Unsubscribe: https://testdomain.com/Unsubscribe/TestList?token={unsubscribe-token}"; homeController.SubscribeWelcome(listName, reg.SubscribeToken).Sync(); Assert.AreEqual(1, sentMailCount); sentMailCount = 0; // validate there is an unsubscribe in the db using (var db = dbProvider.GetDatabase()) { reg = db.Subscriptions.FirstOrDefault(); Assert.AreEqual(listName, reg.ListName); Assert.AreEqual("127.0.0.1", reg.IPAddress); Assert.IsNotNull(reg.UnsubscribeToken); Assert.AreNotEqual(default(DateTime), reg.SubscribedDate); Assert.AreEqual(default(DateTime), reg.UnsubscribedDate); Assert.AreEqual(DateTime.MaxValue, reg.Expires); } return(reg.UnsubscribeToken); }