Ejemplo n.º 1
0
        public void GetById_ShouldGetStudent()
        {
            var fakeRepo = new FakeStudentRepository();

            var student1 = new Student()
            {
                StudentId = 1,
                FirstName = "Minko",
                LastName  = "Markov",
                School    = new School(),
                Grade     = 5
            };

            var student2 = new Student()
            {
                StudentId = 2,
                FirstName = "Minko",
                LastName  = "Markov",
                School    = new School(),
                Grade     = 5
            };

            fakeRepo.Add(student2);
            fakeRepo.Add(student1);

            var server = new InMemoryHttpServer <Student>("http://localhost/", fakeRepo);

            var response = server.CreateGetRequest("api/students/1");

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Content);
        }
Ejemplo n.º 2
0
        public void Update_ShouldUpdateStudent()
        {
            Student studentEnitity = new Student()
            {
                StudentId = 1,
                FirstName = "Minko",
                LastName  = "Markov",
                School    = new School(),
                Grade     = 5
            };

            var fakeRepo = new FakeStudentRepository();

            fakeRepo.Add(studentEnitity);
            fakeRepo.Add(studentEnitity);
            var controller = new StudentsController(fakeRepo);

            studentEnitity.FirstName = "Kiro";

            SetupController(controller);
            controller.PutStudent(studentEnitity.StudentId, studentEnitity);

            var student = controller.Get(studentEnitity.StudentId);

            Assert.IsNotNull(student);
            Assert.AreEqual("Kiro", student.FirstName);
        }
Ejemplo n.º 3
0
        public void DeleteStudent_ShouldDeleteStudent()
        {
            Student studentEnitity = new Student()
            {
                StudentId = 1,
                FirstName = "Minko",
                LastName  = "Markov",
                School    = new School(),
                Grade     = 5
            };

            var fakeRepo = new FakeStudentRepository();

            fakeRepo.Add(studentEnitity);
            fakeRepo.Add(studentEnitity);
            var controller = new StudentsController(fakeRepo);

            studentEnitity.FirstName = "Kiro";

            SetupController(controller);
            controller.PutStudent(studentEnitity.StudentId, studentEnitity);

            controller.DeleteStudent(studentEnitity.StudentId);

            Assert.AreEqual(1, fakeRepo.Entities.Count());
        }
Ejemplo n.º 4
0
        public void Find_ShouldReturnOneStudent()
        {
            Mark markEntity = new Mark()
            {
                Subject = "Math",
                Value   = 5
            };

            var marks = new List <Mark>();

            marks.Add(markEntity);

            Student studentEnitity = new Student()
            {
                FirstName = "Minko",
                LastName  = "Markov",
                School    = new School(),
                Grade     = 5,
                Marks     = marks
            };

            var fakeRepo = new FakeStudentRepository();

            fakeRepo.Add(studentEnitity);
            var controller = new StudentsController(fakeRepo);

            SetupController(controller);
            var students = controller.Find("Math", 5);

            Assert.IsNotNull(students);
            Assert.AreEqual(1, students.Count());
        }
Ejemplo n.º 5
0
        public void GetAll_WhenOneStudent_ShouldReturnStatusCode200AndNotNullContent()
        {
            var fakeRepo = new FakeStudentRepository();

            var student = new Student()
            {
                FirstName = "Minko",
                LastName  = "Markov",
                School    = new School(),
                Grade     = 5
            };

            fakeRepo.Add(student);

            var server = new InMemoryHttpServer <Student>("http://localhost/", fakeRepo);

            var response = server.CreateGetRequest("api/students");

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Content);
        }