Beispiel #1
0
 private void VerifyUserRepository_ReadSingleWasCalled(Int32 timesCalled)
 {
     MockUserRepository
     .Verify(x => x.ReadSingle(
                 It.IsAny <Int32>())
             , Times.Exactly(timesCalled));
 }
Beispiel #2
0
 private void VerifyUserRepositoryQueryWasCalled(Int32 timesCalled)
 {
     MockUserRepository
     .Verify(x => x.Query(
                 It.IsAny <Query <User> >(),
                 It.IsAny <Int32>())
             , Times.Exactly(timesCalled));
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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();
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
        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();
        }