public void ShouldAdd() { //arrange //create a new file using File class. close the file var tempFile = File.Create("temp.csv"); tempFile.Close(); ForagerFileRepository repo = new ForagerFileRepository("temp.csv"); //create a new forager Forager toAdd = new Forager { FirstName = "Testy", LastName = "Smith", Id = "abc-123", State = "WI" }; //act //use Add() to add forager to that new file repo.Add(toAdd); //use FindAll to read back the result List <Forager> all = repo.FindAll(); //assert //that the result length is 1 Assert.AreEqual(1, all.Count); //that the result forager is the one created in here Assert.AreEqual(toAdd.FirstName, all[0].FirstName); Assert.AreEqual(toAdd.LastName, all[0].LastName); Assert.AreEqual(toAdd.State, all[0].State); //delete file as cleanup File.Delete("temp.csv"); }
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"); }
public void ShouldFindAll() { ForagerFileRepository repo = new ForagerFileRepository(@"data\foragers.csv"); List <Forager> all = repo.FindAll(); Assert.AreEqual(1000, all.Count); }
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"); }