Exemplo n.º 1
0
        public void CreateInstructor_UnderNormalConditions_ReturnsOkResponse()
        {
            //Arrange
            var instructorToBeCreated = new InstructorDto()
            {
                InstructorId   = 10,
                InstructorName = "Wayne Gretzky",
                IsActive       = true
            };

            Mock.Arrange(() => _instructorService.Create(instructorToBeCreated))
            .Returns(instructorToBeCreated)
            .OccursOnce();

            var instructorController = new InstructorController(_instructorService)
            {
                Request = new HttpRequestMessage()
                {
                    RequestUri = new Uri("http://localhost/api/instructor/create")
                }
            };


            //Act
            var actual        = instructorController.Post(instructorToBeCreated) as CreatedNegotiatedContentResult <InstructorDto>;
            var actualContent = actual.Content;

            //Assert
            Mock.Assert(_instructorService);
            Assert.That(actual, Is.Not.Null);
            Assert.That(actualContent, Is.EqualTo(instructorToBeCreated));
            Assert.That(actual, Is.TypeOf <CreatedNegotiatedContentResult <InstructorDto> >());
        }
Exemplo n.º 2
0
 public IHttpActionResult Post(InstructorDto instructor)
 {
     using (_instructorService)
     {
         var response = _instructorService.Create(instructor);
         return(Created(new Uri(Request.RequestUri, $"{response.InstructorId}"), response));
     }
 }
Exemplo n.º 3
0
        public void Create()
        {
            var id         = Guid.NewGuid();
            var instructor = new Instructor
            {
                Id          = id,
                Name        = Name,
                Designation = Designation,
                Skill       = Skill
            };


            _instructorService.Create(instructor);
            //_studentService.Edit(student);
        }
        public async Task <object> CreateInstructor(InstructorViewModel model)
        {
            Instructor instructor = new SimpleAutoMapper <Instructor>().Map(model);

            try
            {
                if (await CheckPermissionToCreateUpdateInstructor(instructor))
                {
                    Response response = await _service.Create(instructor);

                    return(this.SendResponse(response));
                }
                return(Forbid());
            }
            catch (Exception e)
            {
                Response.StatusCode = StatusCode(500).StatusCode;
                return(null);
            }
        }