Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 public DiveService(IDiveRepository diveRepository)
 {
     this.diveRepository = diveRepository;
 }
Exemplo n.º 3
0
 public void TestCleanUp()
 {
     _DiveMock     = null;
     _MockLstDives = null;
     _DiveRepo     = null;
 }
Exemplo n.º 4
0
 public DivingService(IDiveRepository diveRepo)
 {
     _diveRepository = diveRepo;
 }