public void SpellsRepository_CharacterLearnsSpell_ByRecord_ValidCall() { //Arrange List <Spell_Character> KnownSpells = new List <Spell_Character>(); var mockKnownSpells = new Mock <DbSet <Spell_Character> >() .SetupData(KnownSpells, o => { return(KnownSpells.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); Spell_Character expected = new Spell_Character { Character_id = Guid.Parse("11111111-2222-3333-4444-555555555555"), Spell_id = Guid.Parse("45c1a8cc-2e3e-4e29-8eeb-f9fa0cc9e27e"), isPrepared = true }; using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.KnownSpells).Returns(mockKnownSpells.Object); //Act ISpellsRepository toTest = mockContext.Create <SpellsRepository>(); toTest.CharacterLearnsSpell(expected); var actual = KnownSpells.First(); //assert actual.Should().BeEquivalentTo(expected); } }
public void SpellsRepository_CharacterLearnsSpell_ByIDs_ValidCall() { //Arrange List <Spell_Character> KnownSpells = CreateTestData.GetListOfKnownSpells(); List <Spell> spells = CreateTestData.GetListOfSpells(); var mockKnownSpells = new Mock <DbSet <Spell_Character> >() .SetupData(KnownSpells, o => { return(KnownSpells.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); var mockSpells = new Mock <DbSet <Spell> >() .SetupData(spells, o => { return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); //Caleb learns Eldritch blast, somehow! Guid Caleb_id = Guid.Parse("11111111-2222-3333-4444-555555555555"); Guid EldritchBlast_id = Guid.Parse("45c1a8cc-2e3e-4e29-8eeb-f9fa0cc9e27e"); Spell EldritchBlast = new Spell { Spell_id = Guid.Parse("45c1a8cc-2e3e-4e29-8eeb-f9fa0cc9e27e"), Name = "Eldritch Blast", Description = "Cast eldritch blast", Level = 0, School_id = Guid.Parse("11111111-2222-3333-4444-555555555555"), CastingTime = "1 Action", Duration = "Instant", Range = "60 feet", RequiresVerbal = true, RequiresSomantic = true, RequiresMaterial = true, RequiresConcentration = false }; using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.Spells).Returns(mockSpells.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.KnownSpells).Returns(mockKnownSpells.Object); //Act ISpellsRepository toTest = mockContext.Create <SpellsRepository>(); toTest.CharacterLearnsSpell(Caleb_id, EldritchBlast_id); var actual = toTest.GetSpellsKnownBy(Caleb_id); //Assert actual.Should().ContainEquivalentOf(EldritchBlast); } }