Example #1
0
        private IEnumerable <LectionModel> GetSampleLection(LectionModel lection = null)
        {
            List <LectionModel> common = new List <LectionModel>()
            {
                new LectionModel()
                {
                    Id = 1, LecturersId = 1, SubjectsId = 3
                },
                new LectionModel()
                {
                    Id = 2, LecturersId = 2, SubjectsId = 2
                },
                new LectionModel()
                {
                    Id = 3, LecturersId = 3, SubjectsId = 1
                },
            };

            if (lection != null)
            {
                common[lection.Id] = lection;
            }

            return(common);
        }
Example #2
0
        public void FindLectionsById_ValidCall()
        {
            Mock <ILectionsRepository> mockGradeRepository = MockLectionRepository;

            mockGradeRepository.Setup(mr => mr.FindByID(It.IsAny <int>()))
            .Returns((int s) => GetSampleLection().Where(x => x.Id == s).FirstOrDefault());
            _mockLectionRepository = mockGradeRepository.Object;


            int          checkingId = 1;
            LectionModel expected   = _mockLectionRepository.FindByID(checkingId);
            var          t          = GetSampleLection().Where(x => x.Id == checkingId);

            Assert.True(expected != null); // Test if null
            Assert.That(expected.LecturersId, Is.EqualTo(GetSampleLection().FirstOrDefault(x => x.Id == checkingId).LecturersId));
        }
Example #3
0
        public void AddLection_Successful()
        {
            Mock <ILectionsRepository> mockGradeRepository = MockLectionRepository;

            mockGradeRepository.Setup(mr => mr.AddLection(It.IsAny <LectionModel>()))
            .Returns(GetSampleLection().Max(u => u.Id) + 1);
            _mockLectionRepository = mockGradeRepository.Object;

            LectionModel expected = new LectionModel()
            {
                Id          = 3,
                LecturersId = 2,
                SubjectsId  = 3
            };


            int count = _mockLectionRepository.AddLection(expected);

            Assert.IsNotNull(expected);              // Test if null
            Assert.AreEqual(expected.Id + 1, count); // Verify the expected Number pre-insert
        }
Example #4
0
        public void UpdateLections_Successful()
        {
            Mock <ILectionsRepository> mockGradeRepository = MockLectionRepository;

            mockGradeRepository.Setup(mr => mr.UpdateLection(It.IsAny <LectionModel>()))
            .Returns((LectionModel s) => s);
            _mockLectionRepository = mockGradeRepository.Object;

            LectionModel expected = new LectionModel()
            {
                Id          = 3,
                LecturersId = 2,
                SubjectsId  = 3
            };


            var actual = _mockLectionRepository.UpdateLection(expected);

            Assert.IsNotNull(expected);              // Test if null
            Assert.AreEqual(expected.Id, actual.Id); // Verify the expected Number pre-insert
        }
Example #5
0
 // PUT: api/Lections/5
 public IHttpActionResult Put(int id, LectionModel value)
 {
     if (id != value.LectionID)
     {
         return(BadRequest());
     }
     try
     {
         LectionDTO edited = map.Map <LectionDTO>(value);
         _db.LectionService.EditLection(edited);
     }
     catch
     {
         if (!LectionExists(id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(StatusCode(HttpStatusCode.NoContent));
 }
 public void Put(int id, [FromBody] LectionModel value)
 {
     _lection.UpdateLection(value);
 }
 public void Post([FromBody] LectionModel value)
 {
     _lection.AddLection(value);
 }
Example #8
0
 public LectionModel UpdateLection(LectionModel grade)
 {
     return(_lectionRepository.UpdateLection(grade));
 }
Example #9
0
 public int AddLection(LectionModel grade)
 {
     return(_lectionRepository.AddLection(grade));
 }
Example #10
0
 public IHttpActionResult Post(LectionModel value)
 {
     _db.LectionService.CreateLection(map.Map <LectionDTO>(value));
     return(CreatedAtRoute("DefaultApi", new { }, value));
 }
Example #11
0
        // GET: api/Lections/5
        public LectionModel Get(int id)
        {
            LectionModel result = map.Map <LectionModel>(_db.LectionService.GetByID(id));

            return(result);
        }