public void Add_WhenStudentIsValid_ShouldAddTheStudent()
        {
            var studentDto = new StudentDto()
            {
                FirstName = "Andrew",
                LastName = "Fuller",
                Age = 29,
                Grade = 4,
                SchoolId = 1
            };

            var student = new Student()
            {
                Id = 1,
                FirstName = studentDto.FirstName,
                LastName = studentDto.FirstName,
                Age = studentDto.Age,
                Grade = studentDto.Grade,
            };

            bool isStudentAdded = false;
            var repository = Mock.Create<IRepository>();

            Mock.Arrange(() => repository.Create(Arg.IsAny<Student>()))
                .DoInstead(() => isStudentAdded = true)
                .Returns(student);

            var controller = new StudentsController(repository);
            SetupController(controller);

            HttpResponseMessage response = controller.Post(studentDto);

            Assert.IsTrue(isStudentAdded);
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }
        public HttpResponseMessage Post(StudentDto value)
        {
            var newStudent = new Student
            {
                SchoolId = value.SchoolId,
                FirstName = value.FirstName,
                LastName = value.LastName,
                Age = value.Age,
                Grade = value.Grade
            };

            HttpResponseMessage response;

            try
            {
                apiControllerHelper.Post<Student>(newStudent);

                if (value.Marks != null)
                {
                    foreach (var mark in value.Marks)
                    {
                        apiControllerHelper.Post<Mark>(new Mark
                        {
                            StudentId = newStudent.Id,
                            Subject = mark.Subject,
                            Value = mark.Value
                        });
                    }
                }

                var createdStudentDto = new StudentDto()
                {
                    Id = newStudent.Id,
                    FirstName = newStudent.FirstName,
                    LastName = newStudent.LastName,
                    Age = newStudent.Age,
                    Grade = newStudent.Grade
                };

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

                response.Headers.Location = new Uri(resourceLink);
            }
            catch (Exception ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
            }

            return response;
        }