Example #1
0
        public void Test_ReadById_in_trainerManager_after_Create()
        {
            _trainer1 = _trainerManager.Create(_trainer1);
            Assert.AreNotEqual(null, _trainer1);

            int id = _trainerManager.ReadByID(_trainer1.Id).Id;

            Assert.AreEqual(_trainer1.Id, id);
        }
Example #2
0
        public void Test_Update_existing_event_with_existing_trainer_in_eventManager()
        {
            //Create new Trainer, and add it to the Database.
            var _trainer = _trainerManager.Create(new Trainer()
            {
                Id          = 1,
                FirstName   = "Event Test First Name 1",
                LastName    = "Event Test Last Name 1",
                Description = "Test Disc 'event'",
            });

            Assert.AreEqual(_trainer.Id, _trainerManager.ReadByID(_trainer.Id).Id);

            //Get the Event with Id 1 from the Database, and make sure its is not null.
            var _event = _eventManager.ReadByID(1);

            Assert.AreNotEqual(null, _event);

            //Add the Trainer we just added to the Database, to the Event we just got from the Database.
            _event.Trainers.Add(_trainer);

            //Update the Event in the database with the foringkey to the Trainer.
            _event = _eventManager.Update(_event);

            //Read the Trainer we now have a foringkey connection to, from the Database, based on the FirstName of the Trainer in the Event.
            _trainer = _trainerManager.ReadByID(_event.Trainers.FirstOrDefault(eventTrainer => eventTrainer.FirstName == _trainer.FirstName).Id);

            //Check if the Trainer is not null.
            Assert.AreNotEqual(null, _trainer);

            //Check if the Trainer Id we got from the Database matches the Event we updated.
            Assert.AreEqual(_trainer.Id, _event.Trainers.FirstOrDefault(eventTrainer => eventTrainer.Id == _trainer.Id).Id);
        }