コード例 #1
0
        public void AddTest_AddOneVailid()
        {
            var schoolName = "Test name";
            var school = new School()
            {
                Name = schoolName,
            };

            var addedSchool = this.schoolRepo.Add(school);
            var foundSchool = this.dbContext.Set<School>().Find(addedSchool.Id);
            Assert.IsNotNull(foundSchool);
            Assert.AreEqual(schoolName, foundSchool.Name);
        }
コード例 #2
0
        // POST api/Schools
        public HttpResponseMessage PostSchool(SchoolModel school)
        {
            if (ModelState.IsValid)
            {
                var schoolTable = new School()
                {
                    Name = school.Name,
                    Location = school.Location
                };
                //db.Schools.Add(schoolModel);
                //db.SaveChanges();
                repository.Add(schoolTable);

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, school);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = schoolTable.SchoolId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #3
0
        public void AllTest_GetAll_WhereAllIs2()
        {
            int alreadyIn = this.schoolRepo.All().Count();

            var schoolName = "Test name";
            var school = new School()
            {
                Name = schoolName,
            };

            var secondSchool = new School()
            {
                Name = schoolName,
            };

            var addedSchool = this.schoolRepo.Add(school);
            var secondAddedSchool = this.schoolRepo.Add(secondSchool);

            var foundMarks = this.schoolRepo.All().ToList();
            Assert.IsNotNull(foundMarks);
            Assert.AreEqual(alreadyIn + 2, foundMarks.Count);
        }
コード例 #4
0
        public HttpResponseMessage PostSchool(SchoolModel model)
        {
            var entityToAdd = new School()
            {
                Name = model.SchoolName,
                Location = model.Location
            };

            var createdEntity = this.schoolsRepository.Add(entityToAdd);


            var createdModel = new SchoolModel()
            {
                Id = createdEntity.Id,
                SchoolName = createdEntity.Name,
                Location = createdEntity.Location
            };

            var response = Request.CreateResponse<SchoolModel>(HttpStatusCode.Created, createdModel);
            var resourceLink = Url.Link("DefaultApi", new { id = createdModel.Id });

            response.Headers.Location = new Uri(resourceLink);
            return response;
        }
コード例 #5
0
        public void RemoveTest_OneAddOneRemove()
        {
            int alreadyIn = this.schoolRepo.All().Count();

            var schoolName = "Test name";
            var mark = new School()
            {
                Name = schoolName,
            };

            var addedSchool = this.schoolRepo.Add(mark);
            bool isDeleted = this.schoolRepo.Delete(addedSchool.Id);

            Assert.IsTrue(isDeleted);
            Assert.AreEqual(alreadyIn, this.schoolRepo.All().Count());
        }
コード例 #6
0
 public School Update(int id, School entity)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
 public School Add(School entity)
 {
     this.entitySet.Add(entity);
     this.dbContext.SaveChanges();
     return entity;
 }