public void DeleteUser_Should_Delete_User_In_Database()
        {
            var user = new User("damdud", "*****@*****.**", "admin123");

            var result_user = _sut.CreateUser(user);

            A.CallTo(() => _repository.Persist(user)).Returns(result_user);
            A.CallTo(() => _repository.GetById(1)).Returns(result_user);

            var result = _repository.GetById(1);

            //Assert.That(result, Is.EqualTo(user));

            _sut.DeleteUser(1);

            A.CallTo(() => _repository.Delete(A<User>._)).MustHaveHappened();
            A.CallTo(() => _repository.GetById(1)).Returns(null);

            //var result = _repository.GetById(1);
            var result2 = _repository.GetById(1);

            //A.CallTo(() => _repository.GetById(1)).Equals(null);

            Assert.That(result2, Is.EqualTo(null));
            Assert.That(result, Is.EqualTo(result_user));
        }
        public void CreateUser_Should_Persist_User_In_Database()
        {
            var user = new User("damdud", "*****@*****.**", "admin123");

            var result_user = _sut.CreateUser(user);

            A.CallTo(() => _repository.Persist(user)).MustHaveHappened();
            A.CallTo(() => _repository.Persist(user)).Returns(result_user);
        }
        public void GetPassword_Should_Return_User_Password()
        {
            var user = new User("damdud", "*****@*****.**", "admin123");
            var result = _sut.CreateUser(user);

            A.CallTo(() => _repository.Persist(user)).MustHaveHappened();
            A.CallTo(() => _repository.GetById(A<int>._)).Returns(user);
            var result2 = _sut.GetPassword(1);

            Assert.That(result2, Is.EqualTo(user.Password));
        }
        public void IncreaseReputation_Should_Increase_Reputation_User_In_Database()
        {
            var user = new User("damdud", "*****@*****.**", "admin123");
            var result_user = _sut.CreateUser(user);

            A.CallTo(() => _repository.Persist(user)).Returns(result_user);

            var changed_user = _sut.IncreaseReputation(1, 5);

            A.CallTo(() => _repository.GetById(1)).MustHaveHappened();
            A.CallTo(() => _repository.GetById(1)).Returns(changed_user);
        }
        public void GetUserById_Should_Return_User()
        {
            var user = new User("damdud", "*****@*****.**", "haslo123");

            _sut.CreateUser(user);

            A.CallTo(() => _repository.Persist(A<User>._)).Returns(user);
            A.CallTo(() => _repository.GetById(A<int>._)).Returns(user);
            //var create = _sut.CreateCategory(category);
            var result = _sut.GetUserById(12);

            Assert.That(result, Is.EqualTo(user));
        }
        public void GetPassword_From_Deleted_Account_Should_Return_Null()
        {
            var user = new User("damdud", "*****@*****.**", "admin123");
            var result_user = _sut.CreateUser(user);
            var result_pass = _sut.GetPassword(1);
            _sut.DeleteUser(1);
            _sut.GetPassword(1);

            A.CallTo(() => _repository.Persist(user)).MustHaveHappened();
            A.CallTo(() => _repository.Persist(user)).Returns(result_user);

            A.CallTo(() => _repository.GetById(1)).MustHaveHappened();
            A.CallTo(() => _repository.GetById(1)).Returns(user);
            A.CallTo(() => _repository.Delete(A<User>.Ignored)).MustHaveHappened();

            //drugie wywołanie GetPassword(1) wywoła znowu GetById(1), które powinno zwrócić null'a
            A.CallTo(() => _repository.GetById(1)).Returns(null);
        }
예제 #7
0
 public User CreateUser(User user)
 {
     return _repository.Persist(user);
 }