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); } }
public void SpellsRepository_CharacterForgetsSpell_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 forgets Web of Fire! Guid Caleb_id = Guid.Parse("11111111-2222-3333-4444-555555555555"); Spell WebOfFire = new Spell { Spell_id = Guid.Parse("51b4c563-2040-4c7d-a23e-cab8d5d3c73b"), Name = "Widogast's Web Of Fire", Description = "The caster deals a shitton of fire damage to the target.", Level = 4, School_id = Guid.Parse("11111111-2222-3333-4444-555555555555"), CastingTime = "1 Action", Duration = "Instant", Range = "120 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.CharacterForgetsSpell(Caleb_id, WebOfFire.Spell_id); var actual = toTest.GetSpellsKnownBy(Caleb_id); actual.Should().NotContain(WebOfFire); } }
public void SpellsRepository_GetSpellsKnownBy_ValidCall() { //Arrange //Create list of spells List <Spell> spells = CreateTestData.GetListOfSpells(); //Create list of Character_Spell List <Spell_Character> knownSpells = CreateTestData.GetListOfKnownSpells(); //We'll be looking for spells that Caleb knows! List <Spell> expected = new List <Spell>(); Spell WebOfFire = new Spell { Spell_id = Guid.Parse("51b4c563-2040-4c7d-a23e-cab8d5d3c73b"), Name = "Widogast's Web Of Fire", Description = "The caster deals a shitton of fire damage to the target.", Level = 4, School_id = Guid.Parse("11111111-2222-3333-4444-555555555555"), CastingTime = "1 Action", Duration = "Instant", Range = "120 feet", RequiresVerbal = true, RequiresSomantic = true, RequiresMaterial = true, RequiresConcentration = false }; expected.Add(WebOfFire); Spell nineSidedTower = new Spell { Spell_id = Guid.Parse("46d10bb8-84d2-408d-a928-5847ff99461f"), Name = "Widogast's Nascent Nine-sided Tower", Description = "A flavored Magnificent Mansion", Level = 7, School_id = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"), CastingTime = "1 minute", Range = "100 feet", Duration = "24 hours", RequiresVerbal = true, RequiresSomantic = true, RequiresMaterial = false, RequiresConcentration = true }; expected.Add(nineSidedTower); var spellMockSet = new Mock <DbSet <Spell> >() .SetupData(spells, o => { return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); var knownSpellsMockSet = new Mock <DbSet <Spell_Character> >() .SetupData(knownSpells, o => { return(knownSpells.Single(x => x.Character_id.CompareTo(o.First()) == 0)); }); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.Spells).Returns(spellMockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.KnownSpells).Returns(knownSpellsMockSet.Object); //Act ISpellsRepository toTest = mockContext.Create <SpellsRepository>(); var Caleb_id = Guid.Parse("11111111-2222-3333-4444-555555555555"); var actual = toTest.GetSpellsKnownBy(Caleb_id).ToList(); //Assert actual.Should().NotBeEmpty(); actual.Should().NotBeNull(); actual.Should().BeOfType <List <Spell> >(); actual.Should().BeEquivalentTo(expected); } }