示例#1
0
        public void PostUserSkillsTest()
        {
            //failure to insert
            _userSkillRepository.setInsertFailure(true);
            var result = _skillService.PostUserSkills("1", new int[] { 0, 1 });

            Assert.False(result);
            _userSkillRepository.setThrowsException(true);
            Assert.Throws <Exception>(() => _skillService.PostUserSkills("1", new int[] { 0, 1 })); //testing exception while inserting
            _userSkillRepository.setInsertFailure(false);
            _userSkillRepository.setThrowsException(false);


            //failure to save
            _userSkillRepository.setSaveFailure(true);
            result = _skillService.PostUserSkills("1", new int[] { 0, 1 });
            Assert.False(result);
            _userSkillRepository.setThrowsException(true);
            Assert.Throws <Exception>(() => _skillService.PostUserSkills("1", new int[] { 0, 1 })); //testing exception while saving
            _userSkillRepository.setSaveFailure(false);
            _userSkillRepository.setThrowsException(false);


            //successful execution
            result = _skillService.PostUserSkills("1", new int[] { 0, 1 });
            Assert.True(result);
        }