public void GetAllStudents_WhenRepositoryIsEmpty_ShouldReturnEmptyCollection()
        {
            // Arrange
            var repository = new FakeStudentsRepository();
            var controller = SetupController(repository, HttpMethod.Get);

            // Act
            var students = controller.GetAllStudents();

            // Assert
            Assert.IsNotNull(students);
            Assert.IsFalse(students.Any());
        }
        public void GetStudentById_WhenIsNotExistStudentWithThisId_ShouldThrowHttpResponseExceptionWithStatusBadRequest()
        {
            // Arrange
            const int Id = 1;
            var repository = new FakeStudentsRepository();
            var controller = SetupController(repository, HttpMethod.Get,
                new KeyValuePair<string, object>("id", Id));

            try
            {
                // Act
                var student = controller.GetStudentById(Id);
            }
            catch (HttpResponseException hre)
            {
                // Assert
                Assert.AreEqual(HttpStatusCode.BadRequest, hre.Response.StatusCode);
                throw;
            }
        }
        public void GetAllStudents_WhenASingleStudentInRepository_ShouldReturnSingleStudent()
        {
            // Arrange
            var repository = new FakeStudentsRepository();
            var student = new Student
            {
                FirstName = "Gosho"
            };
            repository.Students.Add(student);

            var controller = SetupController(repository, HttpMethod.Get);

            // Act
            var students = controller.GetAllStudents();

            // Assert
            Assert.IsNotNull(students);
            Assert.IsTrue(students.Count() == 1);
            Assert.AreEqual(student.FirstName, students.First().FirstName);
        }
        public void GetStudentById_WhenExistStudentWithThisId_ShouldReturnSingleStudentWithThisId()
        {
            // Arrange
            const int Id = 1;
            var repository = new FakeStudentsRepository();
            repository.Students.Add(new Student
            {
                Id = Id,
                FirstName = "Gosho"
            });

            var controller = SetupController(repository, HttpMethod.Get, 
                new KeyValuePair<string, object>("id", Id));

            // Act
            var student = controller.GetStudentById(Id);

            // Assert
            Assert.IsNotNull(student);
            Assert.AreEqual(Id, student.Id);
        }
        public void AddStudent_WhenAddOneValidStudent_ShouldReturAddedStudent()
        {
            // Arrange
            var repository = new FakeStudentsRepository();
            var controller = SetupController(repository, HttpMethod.Post);

            // Act
            var response = controller.AddStudent(new Student
            {
                Id = 6,
                FirstName = "Gosho",
                LastName = "Petkov",
                Age = 12,
                Grade = 6,
                School = new School { Name = "TelerikAcademy", Location = "Sofia" }
            });

            // Assert
            Assert.IsNotNull(response.Content);
            Assert.IsTrue(repository.Students.Count == 1);
            var student = JsonConvert.DeserializeObject<Student>(response.Content.ReadAsStringAsync().Result);
            Assert.AreEqual("Gosho", student.FirstName);
        }
        public void GetAllStudentsBySubjectAndValue_WhenNotMatchAnyStudent_ShouldReturnEmptyCollection()
        {
            // Arrange
            var repository = new FakeStudentsRepository();
            repository.Students.Add(new Student
            {
                Marks = new Collection<Mark>
                {
                    new Mark {Subject = "Math", Value = 5.5m }
                }
            });
            repository.Students.Add(new Student
            {
                Marks = new Collection<Mark>
                {
                    new Mark {Subject = "Biology", Value = 4.0m }
                }
            });
            repository.Students.Add(new Student
            {
                Marks = new Collection<Mark>
                {
                    new Mark {Subject = "Math", Value = 3.0m }
                }
            });

            const string Subject = "Math";
            const decimal Value = 6.00m;
            var controller = SetupController(repository, HttpMethod.Get, 
                new KeyValuePair<string, object>("subject", Subject), new KeyValuePair<string, object>("value", Value));

            // Act
            var students = controller.GetAllStudentsBySubjectAndValue(Subject, Value);

            // Assert
            Assert.IsNotNull(students);
            Assert.IsTrue(!students.Any());
        }
        public void GetAllStudentsBySubjectAndValue_WhenMatchOneStudentFromThree_ShouldReturnSingleStudent()
        {
            // Arrange
            var repository = new FakeStudentsRepository();
            repository.Students.Add(new Student
            {
                Marks = new Collection<Mark>
                {
                    new Mark {Subject = "Math", Value = 5.5m }
                }
            });
            repository.Students.Add(new Student
            {
                Marks = new Collection<Mark>
                {
                    new Mark {Subject = "Biology", Value = 4.0m }
                }
            });
            repository.Students.Add(new Student
            {
                Marks = new Collection<Mark>
                {
                    new Mark {Subject = "Math", Value = 3.0m }
                }
            });

            const string Subject = "Math";
            const decimal Value = 5.00m;
            var controller = SetupController(repository, HttpMethod.Get,
                new KeyValuePair<string, object>("subject", Subject), new KeyValuePair<string, object>("value", Value));

            // Act
            var students = controller.GetAllStudentsBySubjectAndValue(Subject, Value);

            // Assert
            Assert.IsNotNull(students);
            Assert.IsTrue(students.Count() == 1);
            Assert.IsTrue(students.First().Marks.Any(m => m.Subject == Subject && m.Value >= Value));
        }