示例#1
0
        public void LoadData_CallsValidateStudentRecord_ForNTimes(int n)
        {
            //Arange
            string path            = "path";
            var    student         = new StudentModel();
            var    studentsList    = new List <StudentModel>();
            var    rowStudentsList = new List <StudentRawModel> {
                new StudentRawModel()
            };

            for (int i = 0; i < n; i++)
            {
                studentsList.Add(student);
            }

            var fileReader = Substitute.For <IFileReader>();

            fileReader.ImportData(path).Returns(rowStudentsList);

            var mapper = Substitute.For <ICustomMapper>();

            mapper.MapToStudent(rowStudentsList).Returns(studentsList);

            var validator = Substitute.For <IValidator>();

            var sut = new StudentDataProcessorBuilder().WithFileReader(fileReader).WithMapper(mapper).WithValidator(validator).Build();

            // Act
            sut.LoadData(path);

            // Assert
            validator.Received(n).ValidateStudentRecord(student);
        }
示例#2
0
        public void LoadData_CallsImportData_OneTimeWithPath()
        {
            string path       = "path";
            var    fileReader = Substitute.For <IFileReader>();
            var    sut        = new StudentDataProcessorBuilder().WithFileReader(fileReader).Build();

            sut.LoadData(path);
            fileReader.Received(1).ImportData(path);
        }
        public void LoadData_CallLoadaData_OneTime()
        {
            string path       = "path";
            var    fileReader = new Mock <IFileReader>();

            var sut = new StudentDataProcessorBuilder().WithFileReader(fileReader).Build();

            sut.LoadData(path);
            fileReader.Verify(f => f.ImportData(path), Times.Once());
        }
        public void LoadData_CallValidator_WithStudentsFromMapper_AtLeastOnce()
        {
            string path           = "path";
            var    mappedStudents = new List <StudentModel> {
                new StudentModel()
            };
            var mapper = new Mock <ICustomMapper>();

            mapper.Setup(m => m.MapToStudent(It.IsAny <IEnumerable <StudentRawModel> >())).Returns(mappedStudents);
            var validator = new Mock <IValidator>();
            var sut       = new StudentDataProcessorBuilder().WithMapper(mapper).WithValidator(validator).Build();

            sut.LoadData(path);
            validator.Verify(v => v.ValidateStudentRecord(It.IsAny <StudentModel>()), Times.AtLeastOnce());
        }
        public void LoadData_CallMapper_WithStudents()
        {
            string path       = "path";
            var    fileReader = new Mock <IFileReader>();
            var    students   = new List <StudentRawModel> {
                new StudentRawModel()
            };

            fileReader.Setup(a => a.ImportData(path)).Returns(students);
            var mapper = new Mock <ICustomMapper>();
            var sut    = new StudentDataProcessorBuilder().WithFileReader(fileReader).WithMapper(mapper).Build();

            sut.LoadData(path);
            mapper.Verify(m => m.MapToStudent(students), Times.Once());
        }
示例#6
0
        public void LoadData_CallsMapToStudent_WithStudentsFromImportData()
        {
            string path     = "path";
            var    students = new List <StudentRawModel>()
            {
                new StudentRawModel()
            };
            var fileReader = Substitute.For <IFileReader>();

            fileReader.ImportData(path).Returns(students);

            var mapper = Substitute.For <ICustomMapper>();
            var sut    = new StudentDataProcessorBuilder().WithFileReader(fileReader).WithMapper(mapper).Build();

            sut.LoadData(path);
            mapper.Received(1).MapToStudent(students);
        }
        public void LoadData_CallCreateDiplomas_WithStudentFromMapper_ExactlyTimes()
        {
            string path           = "path";
            var    mappedStudents = new List <StudentModel> {
                new StudentModel(), new StudentModel(), new StudentModel()
            };
            var mapper = new Mock <ICustomMapper>();

            mapper.Setup(m => m.MapToStudent(It.IsAny <IEnumerable <StudentRawModel> >())).Returns(mappedStudents);
            var validator = new Mock <IValidator>();

            validator.Setup(v => v.ValidateStudentRecord(It.IsAny <StudentModel>())).Returns(true);
            validator.Setup(v => v.ValidateStudentRecord(It.IsAny <StudentModel>())).Returns(true);
            validator.Setup(v => v.ValidateStudentRecord(It.IsAny <StudentModel>())).Returns(true);
            var fileWritter = new Mock <IFileWriter>();
            var sut         = new StudentDataProcessorBuilder().WithMapper(mapper).WithFileWriter(fileWritter).WithValidator(validator).Build();

            sut.LoadData(path);
            fileWritter.Verify(f => f.CreateDiplomas(It.IsAny <StudentModel>()), Times.Exactly(3));
        }
        public void LoadData_SaveDiploma_WithStudentDiploma_AtLeastOnce()
        {
            string        path            = "path";
            DocumentModel studentDiplomas = null;
            var           mappedStudents  = new List <StudentModel> {
                new StudentModel()
            };
            var mapper = new Mock <ICustomMapper>();

            mapper.Setup(m => m.MapToStudent(It.IsAny <IEnumerable <StudentRawModel> >())).Returns(mappedStudents);
            var validator   = new Mock <IValidator>();
            var fileWritter = new Mock <IFileWriter>();

            validator.Setup(v => v.ValidateStudentRecord(It.IsAny <StudentModel>())).Returns(true);
            var sut = new StudentDataProcessorBuilder().WithMapper(mapper).WithValidator(validator).WithFileWriter(fileWritter).Build();

            sut.LoadData(path);

            fileWritter.Verify(f => f.SaveDiploma(studentDiplomas, It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce);
        }
示例#9
0
        public void LoadData_CallsCreateDiplomasAndSaveDiploma_OneTime_IfValidatorPassed_Else_NoCalls(bool validation)
        {
            // Arange
            string path   = "path";
            int    nTimes = validation ? 1 : 0;

            var student      = new StudentModel();
            var studentsList = new List <StudentModel>()
            {
                student
            };
            var rowStudentsList = new List <StudentRawModel> {
                new StudentRawModel()
            };

            var fileReader = Substitute.For <IFileReader>();

            fileReader.ImportData(path).Returns(rowStudentsList);

            var mapper = Substitute.For <ICustomMapper>();

            mapper.MapToStudent(rowStudentsList).Returns(studentsList);

            var validator = Substitute.For <IValidator>();

            validator.ValidateStudentRecord(student).Returns(validation);

            var fileWritter = Substitute.For <IFileWriter>();

            var sdp = new StudentDataProcessorBuilder().WithMapper(mapper).WithFileWritter(fileWritter).WithFileReader(fileReader).WithValidator(validator).Build();

            // Act
            sdp.LoadData(path);

            // Assert
            fileWritter.Received(nTimes).CreateDiplomas(student);
            fileWritter.Received(nTimes).SaveDiploma(fileWritter.CreateDiplomas(student), student.FirstName, student.LastName);
        }