public void CreateBook(string author, string title, string day, string mounts, string year) { valid.ValidateBook(author, title, day, mounts, year); repo.Create(new Book { Author = author, Title = title, EditionDate = DateTimeOffset.Parse($"{day}/{mounts}/{year}") }); }
public void Validate_Empty_Title() { var mockSet = new Mock <DbSet <Book> >(); mockSet.As <IQueryable <Book> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Book> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Book> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Book> >().Setup(m => m.GetEnumerator()).Returns(() => data.GetEnumerator()); var mockContext = new Mock <ApplicationContext>(); mockContext.Setup(c => c.Books).Returns(mockSet.Object); var validateBook = new IsValid(mockContext.Object); validateBook.ValidateBook("Author", "", "01", "12", "1996"); }
public void Validate_NonNumeric_Year()//Field mounths contain non-numeric elements { var mockSet = new Mock <DbSet <Book> >(); mockSet.As <IQueryable <Book> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Book> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Book> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Book> >().Setup(m => m.GetEnumerator()).Returns(() => data.GetEnumerator()); var mockContext = new Mock <ApplicationContext>(); mockContext.Setup(c => c.Books).Returns(mockSet.Object); var validateBook = new IsValid(mockContext.Object); validateBook.ValidateBook("Author", "Title", "01", "12", "1996* ///"); }