public void UpdateCategoryIsCalled_WhenItemIsFoundAndIsInValidState() { // Arrange var viewMock = new Mock <IEditCategoriesView>(); viewMock.Setup(v => v.ModelState).Returns(new ModelStateDictionary()); Guid categoryId = Guid.NewGuid(); var categoryServiceMock = new Mock <ICategoryService>(); var category = new Category() { Id = categoryId }; categoryServiceMock.Setup(c => c.GetById(categoryId)).Returns(category); EditCategoriesPresenter editCategoriesPresenter = new EditCategoriesPresenter (viewMock.Object, categoryServiceMock.Object); // Act viewMock.Raise(v => v.OnUpdateItem += null, new IdEventArgs(categoryId)); // Assert categoryServiceMock.Verify(c => c.UpdateCategory(category), Times.Once()); }
public void TryUpdateModelIsNotCalled_WhenItemIsNotFound() { // Arrange var viewMock = new Mock <IEditCategoriesView>(); viewMock.Setup(v => v.ModelState).Returns(new ModelStateDictionary()); string errorKey = string.Empty; Guid categoryId = Guid.NewGuid(); var categoryServiceMock = new Mock <ICategoryService>(); categoryServiceMock.Setup(c => c.GetById(categoryId)).Returns <Category>(null); EditCategoriesPresenter editCategoriesPresenter = new EditCategoriesPresenter (viewMock.Object, categoryServiceMock.Object); // Act viewMock.Raise(v => v.OnUpdateItem += null, new IdEventArgs(categoryId)); // Assert viewMock.Verify(v => v.TryUpdateModel(It.IsAny <Category>()), Times.Never()); }
public void AddModelError_WhenItemIsNotFound() { // Arrange var viewMock = new Mock <IEditCategoriesView>(); viewMock.Setup(v => v.ModelState).Returns(new ModelStateDictionary()); string errorKey = string.Empty; Guid categoryId = Guid.NewGuid(); string expectedError = String.Format("Item with id {0} was not found", categoryId); var categoryServiceMock = new Mock <ICategoryService>(); categoryServiceMock.Setup(c => c.GetById(categoryId)).Returns <Category>(null); EditCategoriesPresenter editCategoriesPresenter = new EditCategoriesPresenter (viewMock.Object, categoryServiceMock.Object); // Act viewMock.Raise(v => v.OnUpdateItem += null, new IdEventArgs(categoryId)); // Assert Assert.AreEqual(1, viewMock.Object.ModelState[errorKey].Errors.Count); StringAssert.AreEqualIgnoringCase(expectedError, viewMock.Object.ModelState[errorKey].Errors[0].ErrorMessage); }