private void VerifyUserRepository_ReadSingleWasCalled(Int32 timesCalled) { MockUserRepository .Verify(x => x.ReadSingle( It.IsAny <Int32>()) , Times.Exactly(timesCalled)); }
private void VerifyUserRepositoryQueryWasCalled(Int32 timesCalled) { MockUserRepository .Verify(x => x.Query( It.IsAny <Query <User> >(), It.IsAny <Int32>()) , Times.Exactly(timesCalled)); }
public void WhenCalling_UsersExists_WithValidUserId_RepositoryMethodCalled(int userId) { //arrange MockUserRepository.Setup(s => s.UserExistsAsync(userId)).Returns(Task.FromResult(true)); //act var result = GetService().UserExistsAsync(userId); //assert MockUserRepository.Verify(s => s.UserExistsAsync(userId), Times.Once); }
public void DeleteOnUserService() { //arrange UserService userService = new UserService(MockUnitOfWork.Object); //act userService.Delete(testContext.SingleUser.Id); //assert - expected exception MockUserRepository.Verify(y => y.Delete(It.IsAny <Guid>())); userService.Dispose(); }
public void UpdateOnUserService() { //arrange UserService userService = new UserService(MockUnitOfWork.Object); //set username to that of another user testContext.SingleUser.Username = testContext.SingleUser.Username + "WITHUPDATE"; //act userService.Update(testContext.SingleUser); //assert - expected exception MockUserRepository.Verify(y => y.Update(It.IsAny <User>())); userService.Dispose(); }
public void CreateOnUserService() { //arrange User userToCreate = new User { Id = new Guid("0b21d4b6-eb42-456b-9828-a90cb604bceb"), Username = "******" }; UserService userService = new UserService(MockUnitOfWork.Object); //act Guid id = userService.Create(userToCreate); //assert MockUserRepository.Verify(y => y.Create(It.IsAny <User>())); Assert.IsNotNull(id); Assert.AreEqual(id, userToCreate.Id); userService.Dispose(); }