public void ValidateAuthorTest() { string Author = "Adil Ahmed"; string error = string.Empty; Assert.IsTrue(ValidatePostInput.ValidateAuthor(Author, out error)); }
public void ValidateValidUriTest() { string uri = "http://wwww.google.com"; string error = string.Empty; Assert.IsTrue(ValidatePostInput.ValidateUri(uri, out error)); }
public void ValidateRankTest() { string input = "-1"; int rank = 0; string error = string.Empty; ValidatePostInput.ValidateRank(input, out rank, out error); Assert.AreEqual(error, "Rank must be greater than 0."); }
public void ValidateCommentsTest() { string input = "Adil"; int Points = 0; string error = string.Empty; ValidatePostInput.ValidateComments(input, out Points, out error); Assert.AreNotEqual(input, Points); }
public void ValidatePointsTest() { string input = "10"; int Points = 0; string error = string.Empty; ValidatePostInput.ValidatePoints(input, out Points, out error); Assert.AreEqual(10, Points); }
public void ValidateInvalidUriTest() { string uri = "Bad URI"; string error = string.Empty; ValidatePostInput.ValidateUri(uri, out error); Assert.AreEqual("Incorrectly formed URL - Bad URI", error); }
/// <summary> /// Get input from users for all post entries /// </summary> static void Parse() { string error = string.Empty; string Title; string uri; string Author; int Points; int Comments; int Rank; try { PostLogic postLogic = new PostLogic(); Console.WriteLine("Number of posts {0}", Program.Posts); for (int i = 1; i <= Program.Posts; i++) { while (true) { Console.WriteLine("Please enter the title for Post No {0}", i); Title = Console.ReadLine(); if (!ValidatePostInput.ValidateTitle(Title, out error)) { Console.WriteLine(error); } else { break; } } while (true) { Console.WriteLine("Please enter the uri for Post No {0}", i); uri = Console.ReadLine(); if (!ValidatePostInput.ValidateUri(uri, out error)) { Console.WriteLine(error); } else { break; } } while (true) { Console.WriteLine("Please enter the Author for Post No {0}", i); Author = Console.ReadLine(); if (!ValidatePostInput.ValidateAuthor(Author, out error)) { Console.WriteLine(error); } else { break; } } while (true) { Console.WriteLine("Please enter the Points for Post No {0}", i); if (!ValidatePostInput.ValidatePoints(Console.ReadLine(), out Points, out error)) { Console.WriteLine(error); } else { break; } } while (true) { Console.WriteLine("Please enter the Comments for Post No {0}", i); if (!ValidatePostInput.ValidateComments(Console.ReadLine(), out Comments, out error)) { Console.WriteLine(error); } else { break; } } while (true) { Console.WriteLine("Please enter the Rank for Post No {0}", i); if (!ValidatePostInput.ValidateRank(Console.ReadLine(), out Rank, out error)) { Console.WriteLine(error); } else { break; } } Posts post = new Posts() { title = Title, uri = uri, author = Author, points = Points, comments = Comments, rank = Rank }; postLogic.CreateList(post); } Console.WriteLine("JSON post is as follows..."); Console.WriteLine(postLogic.CreateJSON()); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }