public void Invoke_InvalidData_SaveNorEditAreCalled() { // prepare var userFromDb = new DataAccess.Models.User() { Id = 1 }; var userUpdated = new UserModel() { Id = 1 }; var mockedUserRepo = new Mock <IUserRepository>(); mockedUserRepo.Setup(r => r.GetById(1)) .Returns(userFromDb); var action = new EditUser(mockedUserRepo.Object); // action var actionResult = action.Invoke(userUpdated); // assert Assert.False(actionResult); mockedUserRepo.Verify(r => r.Save(), Times.Never); mockedUserRepo.Verify(r => r.Edit(It.IsAny <DataAccess.Models.User>()), Times.Never); }
public void Invoke_ValidData_UpdatesName() { // prepare var userFromDb = new DataAccess.Models.User() { Id = 1, Name = "Name", }; var userUpdated = new UserModel() { Id = 1, Name = "Name2", // updated value }; DataAccess.Models.User userSaved = null; var mockedUserRepo = new Mock <IUserRepository>(); mockedUserRepo.Setup(r => r.GetById(1)) .Returns(userFromDb); mockedUserRepo.Setup(r => r.Edit(It.IsAny <DataAccess.Models.User>())) .Callback <DataAccess.Models.User>(u => userSaved = u); var action = new EditUser(mockedUserRepo.Object); // action var actionResult = action.Invoke(userUpdated); // assert Assert.True(actionResult); Assert.Equal("Name2", userSaved.Name); }
private void btnSave_Click(object sender, EventArgs e) { if (!ValidateData()) { MessageBox.Show("Invalid data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (UserId <= 0) { AddUser?.Invoke(); } else { EditUser?.Invoke(); } Close(); }
private void Edit(User user) { IEditView editView = new EditForm(); EditUser?.Invoke(editView, user); }