public void CharacterCommons_spellExists_returnTrue() { //Arrange List <Spell> listOfSpells = CreateTestData.GetListOfSpells(); var mockSet = new Mock <DbSet <Spell> >() .SetupData(listOfSpells, o => { return(listOfSpells.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); var realSpell = CreateTestData.GetSampleSpell(); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.Spells).Returns(mockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.Set <Spell>()).Returns(mockSet.Object); IUnitOfWork uow = UoW_Factory.getUnitofWork(mockContext); IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow); //act ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access); var actual = toTest.spellExists(realSpell.Spell_id); //Assert actual.Should().BeTrue(); } }
public void CharacterCommons_spellExists_returnFalse() { //Arrange List <Spell> listOfSpells = CreateTestData.GetListOfSpells(); var mockSet = new Mock <DbSet <Spell> >() .SetupData(listOfSpells, o => { return(listOfSpells.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); var false_id = Guid.Parse("720f467c-7621-4dcf-a82f-7af50f253068"); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.Spells).Returns(mockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.Set <Spell>()).Returns(mockSet.Object); IUnitOfWork uow = UoW_Factory.getUnitofWork(mockContext); IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow); //act ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access); Action act = () => toTest.spellExists(false_id); //Assert act.Should().Throw <InvalidOperationException>().WithMessage("Sequence contains no matching element"); } }
private void LearnSpells(IEnumerable <KnownSpellRowCM> knownSpells, Guid character_id) { CreateModelMapper <KnownSpellRowCM, Spell_Character> mapper = new CreateModelMapper <KnownSpellRowCM, Spell_Character>(); List <Guid> alreadyLearned = new List <Guid>(); foreach (KnownSpellRowCM cm in knownSpells) { if (_commons.spellExists(cm.Spell_id) && alreadyLearned.Contains(cm.Spell_id) == false) { Spell_Character record = mapper.mapViewModelToDataModel(cm); record.Character_id = character_id; _userAccess.CharacterLearnsSpell(record); alreadyLearned.Add(cm.Spell_id); } else { continue; } } }