public void SpellManagerUserAccess_RemoveSpell_ValidCall() { //Arrange List <Spell> spells = CreateTestData.GetListOfSpells(); var mockSet = new Mock <DbSet <Spell> >() .SetupData(spells, o => { return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0)); }); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <SpellsContext>() .Setup(x => x.Set <Spell>()).Returns(mockSet.Object); mockContext.Mock <SpellsContext>() //When a removal of a spell object is called, perform a callback to the charList collection, using the same spell object as an argument. //This callback then fires, removing the object from the list. .Setup(x => x.Set <Spell>().Remove(It.IsAny <Spell>())) .Callback <Spell>((entity) => spells.Remove(entity)); //Act IUnitOfWork UoW = mockContext.Create <UnitOfWork>(); ISpellManagerUserAccess toTest = UserAccessFactory.getSpellManagerUserAccess(UoW); var toBeDeleted = CreateTestData.GetSampleSpell(); toTest.RemoveSpell(toBeDeleted); var NotExpected = CreateTestData.GetSampleSpell(); //Assert spells.Should().NotContain(toBeDeleted); } }
public void SPellManagerUserAccess_AddSpellMaterials_ValidCall() { //Arrange List <Material> Materials = new List <Material>(); 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()) { var expected = CreateTestData.GetSampleMaterial(); var id = expected.Spell_id; mockContext.Mock <SpellsContext>() .Setup(x => x.Materials).Returns(mockSet.Object); //Act IUnitOfWork UoW = mockContext.Create <UnitOfWork>(); ISpellManagerUserAccess toTest = UserAccessFactory.getSpellManagerUserAccess(UoW); toTest.AddSpellMaterials(expected); 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 SpellManagerUserAccess_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 IUnitOfWork UoW = mockContext.Create <UnitOfWork>(); ISpellManagerUserAccess toTest = UserAccessFactory.getSpellManagerUserAccess(UoW); toTest.DeleteSpellMaterialsById(toBeDeleted.Spell_id); //Assert Materials.Should().NotContain(toBeDeleted); } }