public void CannotAddInvalid(string first, string last, string state) { var tempFile = File.Create("temp.csv"); tempFile.Close(); ForagerFileRepository repo = new ForagerFileRepository("temp.csv"); ForagerService service = new ForagerService(repo); Forager forager = new Forager { Id = "abc-123", FirstName = first, LastName = last, State = state }; Forager noCopy = new Forager { FirstName = "First", LastName = "Last", State = "ST" }; service.Add(noCopy); Result <Forager> result = service.Add(forager); Assert.IsFalse(result.Success); //TOD: assert to check the messages that were returned to validate correct reason for failure File.Delete("temp.csv"); }
//Add forager method private void AddForager() { Forager toAdd = view.MakeForager(); Result <Forager> result = foragerService.Add(toAdd); if (!result.Success) { view.DisplayStatus(false, result.Messages); } else { string successMessage = $"Forager {result.Value.Id} created"; view.DisplayStatus(true, successMessage); } }
public void CanAddValidForager() { var tempFile = File.Create("temp.csv"); tempFile.Close(); ForagerFileRepository repo = new ForagerFileRepository("temp.csv"); ForagerService service = new ForagerService(repo); Forager forager = new Forager { FirstName = "Sally", LastName = "Smith", Id = "abc-123", State = "AL" }; Result <Forager> result = service.Add(forager); Assert.IsTrue(result.Success); Assert.NotNull(result.Value); Assert.AreEqual(36, result.Value.Id.Length); File.Delete("temp.csv"); }