Exemplo n.º 1
0
 public TeacherSerivceTests()
 {
     _fakeTeacherRepository = new FakeRepository <Teacher>();
     _fakeTeacherRepository.Add(new Teacher {
         ID       = 123,
         Login    = "******",
         Password = "******"
     });
     _fakeTeacherRepository.Add(new Teacher {
         ID       = 321,
         Login    = "******",
         Password = "******"
     });
 }
        public async Task Create_WhenSubjectWasCreated_NewSubjectIsInRepository()
        {
            // Arrange
            var fakeSubjectRepository = new FakeRepository<Subject>();
            var subjectService = new SubjectService(fakeSubjectRepository);
            var subject = new Subject { Name= "Math" };

            // Act
            var id = await subjectService.Create(subject.Name);
            var allSubjects = await subjectService.GetAll();

            // Assert
            Assert.True(id > 0);
            Assert.Equal(1, allSubjects.Count);
        }
Exemplo n.º 3
0
        public async Task GetByIdAsync_FindStudentInRepository()
        {
            // Arrange
            var expectedStudent = new Student {
                ID = 123, FirstName = "Luke", LastName = "Smith"
            };
            var fakeStudentRepository = new FakeRepository <Student>();
            await fakeStudentRepository.Add(expectedStudent);

            var studentService = new StudentService(fakeStudentRepository);

            // Act
            var student = await studentService.GetByIdAsync(123);

            // Assert
            Assert.Same(student, expectedStudent);
        }
Exemplo n.º 4
0
        public async Task Create_WhenStudnetWasCreated_NewStudnetIsInRepository()
        {
            // Arrange
            var fakeStudentRepository = new FakeRepository <Student>();
            var studentService        = new StudentService(fakeStudentRepository);
            var student = new Student {
                FirstName = "Jan", LastName = "Kowalski"
            };

            // Act
            await studentService.Create(student.FirstName, student.LastName);

            var allStudents = await studentService.GetAll();

            // Assert
            Assert.Equal(1, allStudents.Count);
        }
Exemplo n.º 5
0
        public async Task Create_WhenMarkWasCreated_NewMarkIsInRepository()
        {
            // Arrange
            var fakeMarkRepository = new FakeRepository <Mark>();
            var markService        = new MarkService(fakeMarkRepository);
            var expectedMark       = new Mark {
                SubjectID = 123, StudentID = 1234
            };

            // Act
            await markService.Create(expectedMark.StudentID, expectedMark.SubjectID);

            var allMarks = await markService.GetAll();

            var mark = allMarks.FirstOrDefault();

            // Assert
            Assert.Equal(1, allMarks.Count);
            Assert.Equal(mark.SubjectID, expectedMark.SubjectID);
            Assert.Equal(mark.StudentID, expectedMark.StudentID);
        }
        public async Task Create_WhenThreeSubjectsWereCreated_NewThreeSubjectsAreInRepository()
        {
            // Arrange
            var fakeSubjectRepository = new FakeRepository<Subject>();
            var subjectService = new SubjectService(fakeSubjectRepository);
            List<Subject> subjects = new List<Subject>() {
                new Subject { Name = "Math"},
                new Subject { Name = "Chemistry"},
                new Subject { Name =  "PE"}
            };
            
            // Act
            foreach (var subject in subjects)
            {
                await subjectService.Create(subject.Name);
            }
            var allSubjects = await subjectService.GetAll();

            // Assert
            Assert.Equal(3, allSubjects.Count);
        }
        public async Task GetByIdAsync_FindSubjectInRepository()
        {
            // Arrange
            var fakeSubjectRepository = new FakeRepository<Subject>();
            var subjectService = new SubjectService(fakeSubjectRepository);
            var expectedSubjectName = "Math";
            List<Subject> subjects = new List<Subject>() {
                new Subject { Name = "Math"},
                new Subject { Name = "Chemistry"},
                new Subject { Name =  "PE"}
            };
            
            // Act
            foreach (var subject in subjects)
            {
                await subjectService.Create(subject.Name);
            }
            var result  = await subjectService.GetByNameAsync(expectedSubjectName);

            // Assert
            Assert.True(result.ID > 0);            
            Assert.Equal(expectedSubjectName, result.Name);
        }
Exemplo n.º 8
0
        public async Task Remove_WhenStudentRemoved_OneStudentLessInRepository()
        {
            // Arrange
            var firstStudent = new Student {
                ID = 123, FirstName = "Luke", LastName = "Smith"
            };
            var secondStudent = new Student {
                ID = 321, FirstName = "Pablo", LastName = "Perry"
            };
            var fakeStudentRepository = new FakeRepository <Student>();
            await fakeStudentRepository.Add(firstStudent);

            await fakeStudentRepository.Add(secondStudent);

            var studentService = new StudentService(fakeStudentRepository);

            // Act
            await studentService.Remove(123);

            var allStudents = await studentService.GetAll();

            // Assert
            Assert.Equal(1, allStudents.Count);
        }