public void SpellsRepository_DeleteSpellMaterialsById_ValidCall() { //Arrange List <Material> Materials = CreateTestData.GetListOfMaterials(); var mockSet = new Mock <DbSet <Material> >() .SetupData(Materials, o => { return(Materials.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.Materials).Returns(mockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.Materials.Remove(It.IsAny <Material>())) .Callback <Material>((entity) => Materials.Remove(entity)); var toBeDeleted = CreateTestData.GetSampleMaterial(); //act ISpellsRepository toTest = mockContext.Create <SpellsRepository>(); toTest.DeleteSpellMaterialsById(toBeDeleted.Spell_id); //Assert Materials.Should().NotContain(toBeDeleted); } }
public void SpellsRepository_GetSpellMaterials_ValidCall() { //Arrange List <Material> Materials = CreateTestData.GetListOfMaterials(); var mockSet = new Mock <DbSet <Material> >() .SetupData(Materials, o => { return(Materials.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.Materials).Returns(mockSet.Object); Material expected = new Material() { Spell_id = Guid.Parse("caf8b2d1-7903-493c-bc3a-ec2fc554d533"), materials = "Diamonds worth 300 gp, which the spell consumes." }; //act ISpellsRepository toTest = mockContext.Create <SpellsRepository>(); var actual = toTest.GetSpellMaterials(expected.Spell_id); //Assert actual.Should().NotBeNull(); expected.Should().NotBeNull(); actual.Should().BeOfType <Material>(); expected.Should().BeOfType <Material>(); actual.Should().BeEquivalentTo(expected); } }
public void CMBUilder_buildSpellDetailsCM_ValidCall() { //Arrange List <Spell> spells = CreateTestData.GetListOfSpells(); var spellsMockSet = new Mock <DbSet <Spell> >() .SetupData(spells, o => { return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); List <School> spellSchools = CreateTestData.GetListOfSchools(); var schoolsMockSet = new Mock <DbSet <School> >() .SetupData(spellSchools, o => { return(spellSchools.Single(x => x.School_id.CompareTo(o.First()) == 0)); }); List <Material> materials = CreateTestData.GetListOfMaterials(); var materialsMockSet = new Mock <DbSet <Material> >() .SetupData(materials, o => { return(materials.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); var VoltaicBolt_id = Guid.Parse("a9756f3d-55d0-40cd-8083-6b547e4932ab"); //I expect to get the details CM for Brenatto's Voltaic Bolt var expected = new SpellDetailsCM { Spell_id = Guid.Parse("a9756f3d-55d0-40cd-8083-6b547e4932ab"), Name = "Brenatto's Voltaic Bolt", Description = "The caster's next ranged attack deals an additional 3d6 lightning damage", Level = 1, School = "Evocation", CastingTime = "1 Bonus Action", Duration = "1 round", Range = "30 feet", RequiresVerbal = false, RequiresSomantic = true, RequiresMaterial = true, RequiresConcentration = false, Material = "A bit of fleece" }; using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.Set <Spell>()).Returns(spellsMockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.Spells).Returns(spellsMockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.Set <School>()).Returns(schoolsMockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.Schools).Returns(schoolsMockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.Materials).Returns(materialsMockSet.Object); mockContext.Mock <SpellsContext>() .Setup(x => x.Set <Material>()).Returns(materialsMockSet.Object); IUnitOfWork uow = UoW_Factory.getUnitofWork(mockContext); IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow); //Act ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access); var actual = toTest.buildSpellDetailsCM(VoltaicBolt_id); //Assert actual.Should().BeEquivalentTo(expected); } }