public void Setup() { Dive Diveone = new Dive(1, "Cyprus", 15, 30); Dive Divetwo = new Dive(2, "Crete", 17, 100); _MockLstDives = new List <Dive>(); _MockLstDives.Add(Diveone); _MockLstDives.Add(Divetwo); _DiveMock = new Mock <IDiveRepository>(); //All Dives _DiveMock.Setup(m => m.GetAll()).Returns(_MockLstDives); ///GetByID _DiveMock.Setup(m => m.GetSingle(It.Is <int>(i => i == 1 || i == 2 || i == 3 || i == 4))).Returns <int>(r => new Dive { Id = r, Location = string.Format("Fake Dive {0}", r) }); //Add Dive _DiveMock.Setup(m => m.Add(It.IsAny <Dive>())).Callback(new Action <Dive>( x => { _MockLstDives.Add(x); } )); //Delete Dive _DiveMock.Setup(x => x.Delete(It.IsAny <Dive>())).Callback(new Action <Dive>(x => { _MockLstDives.RemoveAll(d => d.Id == x.Id); } )); //Update Dive _DiveMock.Setup(x => x.Update(It.IsAny <Dive>())).Callback(new Action <Dive>(x => { var found = _MockLstDives.Find(c => c.Id == x.Id); found.Location = x.Location; })); _DiveRepo = _DiveMock.Object; }
public DiveService(IDiveRepository diveRepository) { this.diveRepository = diveRepository; }
public void TestCleanUp() { _DiveMock = null; _MockLstDives = null; _DiveRepo = null; }
public DivingService(IDiveRepository diveRepo) { _diveRepository = diveRepo; }