public void DeleteUserInvalidUserTest() { Mock <IUserRepository> userRepositoryMock = new Mock <IUserRepository>(); userRepositoryMock.Setup(x => x.Delete(It.IsAny <Models.EFModels.User>())).Verifiable(); userRepositoryMock.Setup(x => x.GetById(It.IsAny <int>())).Verifiable(); AuthenticationService.AuthenticationService service = new AuthenticationService.AuthenticationService(userRepositoryMock.Object, Mock.Of <IRoleRepository>()); OperationResult result = service.DeleteUser(new Models.ServiceModels.User { Login = "******", FullName = "ivan", Roles = new List <Models.ServiceModels.Role>() { new Models.ServiceModels.Role("Admin") } }); Assert.That(result, Is.Not.Null); Assert.That(result.Success, Is.False); Assert.That(result.Errors, Is.Not.Empty); Assert.That(result.Errors.Contains(OperationErrors.UserNotExistErr), Is.True); Assert.That(result.Errors.Count, Is.EqualTo(1)); userRepositoryMock.Verify(x => x.Delete(It.IsAny <Models.EFModels.User>()), Times.Never); userRepositoryMock.Verify(x => x.GetById(It.IsAny <int>()), Times.Once); }
public void DeleteUserNotExistUserTest() { Mock <IUserRepository> userRepositoryMock = new Mock <IUserRepository>(); userRepositoryMock.Setup(x => x.Delete(It.IsAny <Models.EFModels.User>())).Verifiable(); userRepositoryMock.Setup(x => x.GetById(It.IsAny <int>())).Verifiable(); AuthenticationService.AuthenticationService service = new AuthenticationService.AuthenticationService(userRepositoryMock.Object, Mock.Of <IRoleRepository>()); OperationResult result = service.DeleteUser(null); Assert.That(result, Is.Not.Null); Assert.That(result.Success, Is.False); Assert.That(result.Errors, Is.Not.Empty); Assert.That(result.Errors.Contains(OperationErrors.NullErr), Is.True); Assert.That(result.Errors.Count, Is.EqualTo(1)); userRepositoryMock.Verify(x => x.Delete(It.IsAny <Models.EFModels.User>()), Times.Never); userRepositoryMock.Verify(x => x.GetById(It.IsAny <int>()), Times.Never); }