Ejemplo n.º 1
0
        public void WhenUpdatingUser_ThenDelegatesToUserRepository()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
            userRepositoryMock.Setup(u => u.Create(It.IsAny<MileageStats.Model.User>()))
                .Callback<MileageStats.Model.User>(u => u.UserId = 12);

            var services = new UserServices(userRepositoryMock.Object);

            User user = new User() {AuthorizationId = "authId"};
            services.CreateUser(user);
            user.AuthorizationId = "newAuthId";
            services.UpdateUser(user);

            userRepositoryMock.Verify(r => r.Update(It.IsAny<MileageStats.Model.User>()), Times.Once());
        }
Ejemplo n.º 2
0
        public void WhenUpdatingUserAndRepositoryThrows_ThenWrapsException()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
            userRepositoryMock.Setup(u => u.Update(It.IsAny<MileageStats.Model.User>()))
                .Throws<InvalidOperationException>();

            var services = new UserServices(userRepositoryMock.Object);

            var ex = Assert.Throws<BusinessServicesException>(
                () => services.UpdateUser(new User() {AuthorizationId = "authId"}));
            Assert.IsType<InvalidOperationException>(ex.InnerException);
        }