public void Add_WhenStudenDontHaveName_ShouldThrowException()
        {
            Student student = new Student()
            {
                Grade = 6,
                Age = 18
            };

            var createdStudent = this.studentsRepository.Add(student);
        }
        public void Add_WhenStudentPropertiesAreValid_ShouldReturnNotZeroId()
        {
            Student student = new Student()
            {
                FirstName = "Peter",
                LastName = "Petrov",
                Grade = 5,
                Age = 18
            };

            var createdStudent = this.studentsRepository.Add(student);
            Assert.IsTrue(createdStudent.StudentId != 0);
        }
        public void Add_WhenStudentPropertiesAreValid_ShouldAddStudentToDatabase()
        {
            Student student = new Student()
            {
                FirstName = "Peter",
                LastName = "Petrov",
                Grade = 5,
                Age = 18
            };

            var createdStudent = this.studentsRepository.Add(student);
            var foundStudent = this.dbContext.Set<Student>().Find(createdStudent.StudentId);
            Assert.IsNotNull(foundStudent);
            Assert.AreEqual(student.FirstName, foundStudent.FirstName);
        }
        public void Post_StudentWithouthName_ShouldReturnInternalErrorMsg()
        {
           
            var mockRepository = Mock.Create<DbStudentsRepository>();

            var student = new Student()
                {
                    Grade = 5,
                    Age = 18
                };

            Mock.Arrange(() => mockRepository.Add(Arg.IsAny<Student>()))
                .Throws<ArgumentNullException>();

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

            var responce = server.CreatePostRequest("api/students", JsonConvert.SerializeObject(student));

            Assert.AreEqual(responce.StatusCode, HttpStatusCode.InternalServerError);
        }
        public void Post_StudentWithValidContent_ShouldReturnStatusCode200AndStudentWithId()
        {
            
            var mockRepository = Mock.Create<DbStudentsRepository>();
            bool added = false;

            var student = new Student()
                {
                    FirstName = "Peter",
                    LastName = "Petrov",
                    Grade = 5,
                    Age = 18,
                };
            var studentEntity = new Student()
            {
                StudentId =1,
                FirstName = "Peter",
                LastName = "Petrov",
                Grade = 5,
                Age = 18,
            };

            Mock.Arrange(() => mockRepository.Add(Arg.IsAny<Student>()))
                .DoInstead(() => added = true)
                .Returns(studentEntity);

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

            var response = server.CreatePostRequest("api/students", student);
           
            var content = JsonConvert.DeserializeObject<Student>((response.Content.ReadAsStringAsync().Result));
            Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);
            Assert.IsTrue(added);
            Assert.IsTrue(content.StudentId == 1);
        }
        public void Add_WhenStudenDontHaveGrade_ShouldThrowException()
        {
            Student student = new Student()
            {
                FirstName = "Peter",
                LastName = "Petrov",
                Age = 18
            };

            var createdStudent = this.studentsRepository.Add(student);
        }
        public void Delete_WhenIdIsValid_ShouldRemoveStudentFromDb()
        {
            Student student = new Student()
            {
                FirstName = "Peter",
                LastName = "Petrov",
                Grade = 5,
                Age = 18
            };

            var actualStudent = dbContext.Set<Student>().Add(student);
            dbContext.SaveChanges();

            studentsRepository.Delete(actualStudent.StudentId);
            var expectedStudent = studentsRepository.Get(actualStudent.StudentId);

            Assert.IsNull(expectedStudent);
        }
        public void Get_WhenIdIsValid_ShouldReturnStudent()
        {
            Student student = new Student()
            {
                FirstName = "Peter",
                LastName = "Petrov",
                Grade = 5,
                Age = 18
            };

            var actualStudent = dbContext.Set<Student>().Add(student);
            dbContext.SaveChanges();

            var expectedStudent = studentsRepository.Get(actualStudent.StudentId);

            Assert.IsNotNull(expectedStudent);
            Assert.AreEqual(student.LastName, expectedStudent.LastName);
        }
        public void All_WhenDbNotEmpty_ShouldReturnAllStudents()
        {
            Student student1 = new Student()
            {
                FirstName = "Peter",
                LastName = "Petrov",
                Grade = 5,
                Age = 18
            };
            Student student2 = new Student()
            {
                FirstName = "Peter2",
                LastName = "Petrov2",
                Grade = 6,
                Age = 19
            };

            dbContext.Set<Student>().Add(student1);
            dbContext.Set<Student>().Add(student2);
            dbContext.SaveChanges();

            var students = this.studentsRepository.All().ToList();
            Assert.AreEqual(students.Count, 2);
            Assert.IsNotNull(students.Where(s => s.FirstName == student1.FirstName));
            Assert.IsNotNull(students.Where(s => s.FirstName == student2.FirstName));


        }