Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        //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);
            }
        }
Exemplo n.º 3
0
        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");
        }