public void AddPages_returns_success_result_if_pages_are_empty() { //arrange Mock <IPageRepository> pageRepo = new Mock <IPageRepository>(); Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); pageRepo.Setup(rep => rep.AddRange(null)).Throws <ArgumentNullException>(); pageRepo.Setup(rep => rep.AddRange(It.IsNotNull <IEnumerable <Page> >())); uow.Setup(u => u.PageRepository).Returns(pageRepo.Object); TestManager manager = new TestManager(uow.Object); //act var emptyPagesAdd = manager.AddPages(new Page[] { }).Result; //assert Assert.True(emptyPagesAdd.Succeeded); }
public void AddPages_returns_success_result_if_pages_are_not_empty() { //arrange Mock <IPageRepository> pageRepo = new Mock <IPageRepository>(); Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); pageRepo.Setup(rep => rep.AddRange(It.IsNotNull <IEnumerable <Page> >())) .Callback <IEnumerable <Page> >(pages => _pages.AddRange(pages)); uow.Setup(u => u.PageRepository).Returns(pageRepo.Object); TestManager manager = new TestManager(uow.Object); var oldCount = _pages.Count; //act var emptyPagesAdd = manager.AddPages(_addPages).Result; //assert Assert.True(emptyPagesAdd.Succeeded); Assert.Equal(_pages.Count, oldCount + _addPages.Count); Assert.True(_pages.Any(p => _addPages.Contains(p))); pageRepo.Verify(p => p.AddRange(It.IsNotNull <IEnumerable <Page> >())); }