public void CreatePage_returns_succeeded_if_add_new_page() { //arrange Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); Mock <IPageRepository> repo = new Mock <IPageRepository>(); repo.Setup(r => r.Add(It.IsNotNull <Page>())) .Callback <Page>(p => _pages.Add(p)) .Verifiable(); uow.Setup(u => u.SaveChanges()) .ReturnsAsync(1) .Verifiable(); uow.Setup(u => u.PageRepository).Returns(repo.Object); TestManager manager = new TestManager(uow.Object); var pagesCount = _pages.Count(); //act var addResult = manager.CreatePage(new Page()).Result; //assert Assert.True(addResult.Succeeded); Assert.Equal(pagesCount + 1, _pages.Count); }
public void CreatePage_returns_failed_result_if_page_is_null() { //arrange Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); TestManager manager = new TestManager(uow.Object); //act var pageAddResult = manager.CreatePage(null).Result; //assert Assert.False(pageAddResult.Succeeded); }
public void CreatePage_returns_failed_if_no_changes() { //arrange Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); Mock <IPageRepository> repo = new Mock <IPageRepository>(); uow.Setup(u => u.SaveChanges()).ReturnsAsync(0); repo.Setup(r => r.Add(It.IsNotNull <Page>())); uow.Setup(u => u.PageRepository).Returns(repo.Object); TestManager manager = new TestManager(uow.Object); //act var addIfFailed = manager.CreatePage(new Page()).Result; //assert Assert.False(addIfFailed.Succeeded); Assert.NotNull(addIfFailed.Errors); Assert.Equal("SaveChanges returned 0", addIfFailed.Errors.ElementAt(0)); }