public void ReadClass_WithValidCsv_ReturnsStudent()
        {
            // Arrange
            string className         = _fixture.Create <string>();
            string expectedFirstName = _fixture.Create <string>();
            string expectedInfix     = _fixture.Create <string>();
            string expectedLastName  = _fixture.Create <string>();

            Application.Models.ValueTypes.Path filePath = _fixture.Create <Application.Models.ValueTypes.Path>();
            var validCsv = "Stamnummer,Klas,Roepnaam,Tussenvoegsel,Achternaam,Studie,Email,Telefoonnummer\n" +
                           $"{_fixture.Create<int>()}," +
                           $"\"{className}\",\"{expectedFirstName}\",\"{expectedInfix}\",\"{expectedLastName}\"," +
                           $"\"{_fixture.Create<string>()}\",\"{_fixture.Create<string>()}\",{_fixture.Create<int>()}";
            var stream          = new MemoryStream(Encoding.UTF8.GetBytes(validCsv));
            var fileInfoWrapper = new Mock <IFileInfoWrapper>();

            fileInfoWrapper.Setup(x => x.OpenRead())
            .Returns(stream);
            _fileInfoWrapperFactoryMock.Setup(x => x.Create(filePath))
            .Returns(fileInfoWrapper.Object);

            // Act
            Application.Models.Class.Magister.MagisterClass result = _sut.ReadClass(filePath);

            // Assert
            result.Should().NotBeNull();
            result.Students.Should().ContainSingle();

            var actualStudent = result.Students.Single();

            actualStudent.FirstName.Should().Be(expectedFirstName);
            actualStudent.Infix.Should().Be(expectedInfix);
            actualStudent.LastName.Should().Be(expectedLastName);
        }
Esempio n. 2
0
        private MemoryStream SetupNonExistingFile(Application.Models.ValueTypes.Path classRepositoryPath)
        {
            var memoryStream = new MemoryStream();
            var file         = new Mock <IFileInfoWrapper>();

            file.SetupGet(x => x.Exists)
            .Returns(false);
            file.Setup(x => x.OpenWrite())
            .Returns(memoryStream);
            _fileInfoWrapperFactory.Setup(x => x.Create(classRepositoryPath))
            .Returns(file.Object);
            return(memoryStream);
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public MagisterClass ReadClass(Application.Models.ValueTypes.Path fileLocation)
        {
            IFileInfoWrapper fileInfo = _fileInfoWrapperFactory.Create(fileLocation);

            using (var reader = new StreamReader(fileInfo.OpenRead()))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    var magisterRecords = csv
                                          .GetRecords <MagisterRecord>()
                                          .ToList();
                    var students = magisterRecords.MapToMagisterStudents();

                    return(new MagisterClass
                    {
                        Name = magisterRecords.First().Klas,
                        Students = students,
                    });
                }
        }
Esempio n. 4
0
 public DirectoryInfoWrapper(Application.Models.ValueTypes.Path directoryPath,
                             IFileInfoWrapperFactory fileInfoWrapperFactory)
 {
     _directoryPath          = directoryPath;
     _fileInfoWrapperFactory = fileInfoWrapperFactory;
 }
Esempio n. 5
0
 public TestFileRepository(IFileLocationProvider fileLocationProvider,
                           IFileInfoWrapperFactory fileInfoWrapperFactory)
 {
     _testRepositoryLocation = fileLocationProvider.GetTestRepositoryPath();
     _fileInfoWrapperFactory = fileInfoWrapperFactory;
 }