Пример #1
0
        public void Delete_existingModel_shouldRemoveModel()
        {
            var newUser = CreateUser();
            var mockRepository = new Mock<IUserRepository>();
            var controller = new UserController {UserRepository = mockRepository.Object};

            controller.Delete(newUser.Id.Value);

            mockRepository.Verify(x => x.Delete(newUser.Id.Value));
        }
Пример #2
0
        public void Post_validModel_shouldInsertModel()
        {
            var newUser = CreateUser();
            var mockRepository = new Mock<IUserRepository>();
            var controller = new UserController {UserRepository = mockRepository.Object};

            controller.Post(newUser);

            mockRepository.Verify(x => x.Insert(newUser));
        }
Пример #3
0
        public void Get_userExists_shouldReturnUser()
        {
            var expected = CreateUser();
            var mockRepository = new Mock<IUserRepository>();
            mockRepository.Setup(x => x.Get(expected.Id.Value)).Returns(expected);
            var controller = new UserController {UserRepository = mockRepository.Object};

            var actual = controller.Get(expected.Id.Value);

            Assert.AreEqual(expected, actual);
        }
Пример #4
0
        public void Get_allUsersExist_shouldReturnUsers()
        {
            var expected = CreateUser();
            var mockRepository = new Mock<IUserRepository>();
            mockRepository.Setup(x => x.GetAll()).Returns(new[]{ expected, expected });
            var controller = new UserController {UserRepository = mockRepository.Object};

            var actual = controller.Get();

            Assert.AreEqual(expected, actual.First());
        }
Пример #5
0
        public void Put_existingIdvalidModel_shouldUpdateModel()
        {
            var newUser = CreateUser();
            var mockRepository = new Mock<IUserRepository>();
            mockRepository.Setup(x => x.Get(newUser.Id.Value)).Returns(newUser);
            var controller = new UserController {UserRepository = mockRepository.Object};
            newUser.ServiceId = Guid.NewGuid();

            controller.Put(newUser.Id.Value, newUser);

            mockRepository.Verify(x => x.Update(newUser.Id.Value, newUser));
        }