public void AddSkill_AppendsNewSkill() { //Arrange var skillId = Guid.NewGuid(); var newSkill = new API.Dto.Skill { Id = skillId, Name = "Skill1", PrimaryStatId = API.Dto.AbilityType.Cha, HasArmourCheckPenalty = true, Ranks = 5, Class = true, UseUntrained = true, Total = 8 }; _skillsService.CachedSvcSkills = new Dictionary <Guid, API.Dto.Skill>(); //Act _skillsService.AddSkill(newSkill); var result = _skillsService.GetAllSkills(); //Assert result.FirstOrDefault().Should().Be(newSkill); }
public void AddSkillTest() { //failure to insert _skillRepository.setInsertFailure(true); var result = _skillService.AddSkill(new Skill { Id = 1, SkillName = "C#" }); Assert.False(result); _skillRepository.setThrowsException(true); Assert.Throws <Exception>(() => _skillService.AddSkill(new Skill { Id = 1, SkillName = "C#" })); _skillRepository.setInsertFailure(false); _skillRepository.setThrowsException(false); //failure to save _skillRepository.setSaveFailure(true); result = _skillService.AddSkill(new Skill { Id = 1, SkillName = "C#" }); Assert.False(result); _skillRepository.setThrowsException(true); Assert.Throws <Exception>(() => _skillService.AddSkill(new Skill { Id = 1, SkillName = "C#" })); _skillRepository.setSaveFailure(false); _skillRepository.setThrowsException(false); //successful execution result = _skillService.AddSkill(new Skill { Id = 1, SkillName = "C#" }); Assert.True(result); }