コード例 #1
0
        public void GetSubjects_ReturnsOkResult()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            // act
            var result = sc.GetSubjects(null);

            // assert
            Assert.IsInstanceOf <OkObjectResult>(result.Result);
        }
コード例 #2
0
        public void GetSubject_InValidSubject_ReturnsNotFoundResult()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            // act
            var result = sc.GetSubject(6);

            // assert
            Assert.IsInstanceOf <NotFoundResult>(result.Result);
        }
コード例 #3
0
        public void GetSubjects_ReturnsSubjectDtoList()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            // act
            var result = sc.GetSubjects(null).Result as OkObjectResult;

            // Assert
            Assert.IsInstanceOf <List <SubjectDto> >(result.Value);
        }
コード例 #4
0
        public void GetTitles_ReturnsAllItems()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            TitlesController           tc   = new TitlesController(fake);

            // act
            var             result = tc.GetTitles().Result as OkObjectResult;
            List <TitleDto> titles = result.Value as List <TitleDto>;

            // assert
            Assert.AreEqual(5, titles.Count);
        }
コード例 #5
0
        public void GetSubjects_ReturnsAllItems()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            // act
            var result = sc.GetSubjects(null).Result as OkObjectResult;
            List <SubjectDto> subjects = result.Value as List <SubjectDto>;

            // assert
            Assert.AreEqual(5, subjects.Count);
        }
コード例 #6
0
        public void DeleteSubject_ValidSubject_ReturnsNoContext()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            // act
            var deleteResult           = sc.DeleteSubject(1);
            var getresult              = sc.GetSubjects(null).Result as OkObjectResult;
            List <SubjectDto> subjects = getresult.Value as List <SubjectDto>;

            // assert
            Assert.IsInstanceOf <NoContentResult>(deleteResult);
            Assert.AreEqual(4, subjects.Count);
        }
コード例 #7
0
        public void GetSubject_ReturnsCorrectSubject()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            // act
            var        result  = sc.GetSubject(1).Result as OkObjectResult;
            SubjectDto subject = result.Value as SubjectDto;

            // assert
            Assert.AreEqual(1, subject.subjectId);
            Assert.AreEqual("Daniel", subject.firstName);
            Assert.AreEqual("Garsden", subject.lastName);
            Assert.AreEqual("19/08/1976", subject.dateOfBirth.ToString("d"));
        }
コード例 #8
0
        public void UpdateSubject_InValidSubject_ReturnsNotFound()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            SubjectDto subject = new SubjectDto
            {
                firstName   = "Mark",
                lastName    = "Garsden",
                dateOfBirth = new DateTime(1980, 2, 11),
                titleId     = 1
            };

            // act
            var result = sc.UpdateSubject(6, subject);

            // assert
            Assert.IsInstanceOf <NotFoundResult>(result);
        }
コード例 #9
0
        public void AddSubject_ValidObject_ReturnsCreateAtRouteResult()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            SubjectForCreationDto subject = new SubjectForCreationDto
            {
                FirstName   = "Zita",
                LastName    = "Garsden Kabok",
                DateOfBirth = new DateTime(1980, 05, 03),
                TitleId     = 2
            };

            // act
            var result = sc.CreateSubject(subject);

            // assert
            Assert.IsInstanceOf <CreatedAtRouteResult>(result);
        }
コード例 #10
0
        public void AddSubject_InValidObject_ReturnsBadRequestResult()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            SubjectForCreationDto subject = new SubjectForCreationDto
            {
                LastName    = "Garsden Kabok",
                DateOfBirth = new DateTime(1980, 05, 03),
                TitleId     = 2
            };

            sc.ModelState.AddModelError("firstName", "Required");

            // act
            var result = sc.CreateSubject(subject);

            // assert
            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
コード例 #11
0
        public void UpdateSubject_InValidSubjectData_ReturnsBadRequest()
        {
            // arrange
            FakeSubjectOrderRepository fake = new FakeSubjectOrderRepository();
            SubjectsController         sc   = new SubjectsController(fake);

            SubjectDto subject = new SubjectDto
            {
                firstName   = "",
                lastName    = "Garsden",
                dateOfBirth = new DateTime(1980, 2, 11),
                titleId     = 1
            };

            sc.ModelState.AddModelError("firstName", "Required");

            // act
            var result = sc.UpdateSubject(1, subject);

            // assert
            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }