public void DeleteAnimal() { string name = string.Format("Spot {0}", Guid.NewGuid()); using (var db = context.GetDb()) { Animal a = new Animal { Name = name, DemSuffix = "D1" }; db.Animals.Add(a); db.SaveChanges(); } try { d.FindElement(By.LinkText("Animals")).Click(); d.FindElement(By.LinkText(name)) .FindElement(By.XPath("../..")) .FindElement(By.LinkText("Delete")) .Click(); SwitchToPopup(); d.FindElement(By.XPath("//input[@type='submit']")).Click(); d.SwitchTo().Window(mainWindow); Assert.IsFalse(d.FindElements(By.TagName("a")).Any(f => f.Text == name), "is on page"); } catch { CleanupEntry(name); throw; } }
public void Initialization() { Animal animal = new Animal(); Assert.AreEqual(Animal.AllowedTypes[0], animal.Type, "type"); Assert.IsEmpty(animal.Owners, "owners"); Assert.IsEmpty(animal.MissionRosters, "missionrosters"); }
public void GetPrimaryOwner() { var owner = new Member { FirstName = "Mary", LastName = "Smith" }; var animal = new Animal(); animal.Owners.Add(new AnimalOwner { Animal = animal, Owner = new Member { FirstName = "Joe", LastName = "Smith" } }); animal.Owners.Add(new AnimalOwner { Animal = animal, Owner = owner, IsPrimary = true }); var primary = animal.GetPrimaryOwner(); Assert.AreSame(owner, primary); }
public ActionResult Create() { ViewData["PageTitle"] = "New Animal"; Animal a = new Animal(); Session.Add("NewAnimalGuid", a.Id); ViewData["NewAnimalGuid"] = Session["NewAnimalGuid"]; return InternalEdit(a); }
public ActionResult Create(FormCollection fields) { if (Session["NewAnimalGuid"] != null && Session["NewAnimalGuid"].ToString() != fields["NewAnimalGuid"]) { throw new InvalidOperationException("Invalid operation. Are you trying to re-create an animal?"); } Session.Remove("NewAnimalGuid"); ViewData["PageTitle"] = "New Animal"; Animal a = new Animal(); this.db.Animals.Add(a); return InternalSave(a, fields); }
public void Report() { var animal = new Animal { Name = "testName", DemSuffix = "H", Comments = "Comments go here" }; Assert.AreEqual(string.Format(Animal.ReportFormat, animal.Name, animal.DemSuffix, animal.Type, animal.Comments), animal.GetReportHtml()); }
public void GetPrimaryOwner_none() { var animal = new Animal(); Assert.IsNull(animal.GetPrimaryOwner()); }
private ActionResult InternalSave(Animal a, FormCollection fields) { TryUpdateModel(a, new string[] { "Name", "DemSuffix", "Comments", "Type" }); if (ModelState.IsValid) { this.db.SaveChanges(); TempData["message"] = "Saved"; return RedirectToAction("ClosePopup"); } return InternalEdit(a); }
private ActionResult InternalEdit(Animal a) { ViewData["TypeList"] = new SelectList(Animal.AllowedTypes, a.Type); return View("Edit", a); }
public void SetAnimalOwner() { string name = string.Format("Fred {0}", Guid.NewGuid()); Guid id; string owner; Guid userId; using (var db = context.GetDb()) { Animal a = new Animal { Name = name, DemSuffix = "D1" }; db.Animals.Add(a); db.SaveChanges(); id = a.Id; Member m = db.Members.First(); owner = m.ReverseName; userId = m.Id; } try { d.Url = context.Url + "/Animals/Detail/" + id.ToString(); d.FindElement(By.LinkText("Add New Owner")).Click(); SwitchToPopup(); d.FindElement(By.XPath("//input[@type='submit']")).Click(); var fieldErrors = d.FindElements(By.ClassName("field-validation-error")); Assert.AreEqual(1, fieldErrors.Count, "error count"); Assert.IsTrue(fieldErrors.All(f => f.Text.StartsWith("Required")), "error text"); d.FindElement(By.Id("name_a")).SendKeys(owner); PickSuggestedUser(userId); d.FindElement(By.Id("IsPrimary")).Click(); d.FindElement(By.XPath("//input[@type='submit']")).Click(); d.SwitchTo().Window(mainWindow); Assert.IsNotNull(d.FindElement(By.LinkText(owner)), "link to owner"); } finally { CleanupEntry(name); } }