public void Convert(string inputFile, EolConversion eolConversion, string expectedOutputFile) { // Arrange byte[] inputBuffer = new byte[BlockSize]; byte[] expectedOutputBuffer = new byte[BlockSize * 2]; byte[] outputBuffer = new byte[BlockSize * 2]; sut = new EolDataConverter(eolConversion); using (var reader = GetTestFileStream(inputFile)) using (var expectedOutputReader = GetTestFileStream(expectedOutputFile)) { int outputLength; int expectedOutputRead; int inputRead = 0; while ((inputRead = reader.Read(inputBuffer, 0, BlockSize)) != 0) { // Act sut.Convert(inputBuffer, inputRead, outputBuffer, out outputLength); // Assert expectedOutputRead = expectedOutputReader.Read(expectedOutputBuffer, 0, outputLength); Assert.Equal(expectedOutputRead, outputLength); Assert.Equal(expectedOutputBuffer, outputBuffer); } // Check expected output does not have more bytes to read, otherwise it will be different from converted input that has ended expectedOutputRead = expectedOutputReader.Read(expectedOutputBuffer, 0, BlockSize); Assert.Equal(0, expectedOutputRead); } }
public void Convert(EncodingType encoding, bool hasBom, byte[] data, EolConversion conversion, byte[] expectedOutput) { // Arrange SetupSut(conversion, encoding, hasBom); // Act sut.Convert(data, data.Length, outputData, out outputLength); // Assert AssertOutput(expectedOutput, expectedOutput.Length, outputData, outputLength); }
private static object[] CreateConversionScenario(string inputFile, EolConversion conversion) { return(new object[3] { inputFile, conversion, $"{inputFile}_{conversion.ToString()}" }); }
public EolConverter(EolConversion eolConversion, IEncodingDetector encodingDetector) { this.eolConversion = eolConversion; this.encodingDetector = encodingDetector; }
private static byte[] GetEolBytes(this EolConversion eolConversion) { var attribute = eolConversion.GetAttribute <EolBytesAttribute>(); return(attribute?.EolBytes ?? new byte[0]); }
/// <summary> /// Returns the end of line units of the conversion, using the specified encoding. /// </summary> /// <param name="eolConversion">The conversion to get end of line units from.</param> /// <param name="encoding">The encoding used to create the units.</param> /// <returns>An array with the end of line units of the conversion.</returns> public static byte[] GetEolUnits(this EolConversion eolConversion, EncodingType encoding) { return(eolConversion .GetEolBytes() .ToUnits(encoding)); }
public void Convert_WhenDataIsEndedByNullBytes(EncodingType encoding, bool hasBom, byte[] data, EolConversion conversion, byte[] expectedOutput) { // Arrange var dataNullBytesEnded = new byte[BufferSize]; data.CopyTo(dataNullBytesEnded, 0); SetupSut(conversion, encoding, hasBom); // Act sut.Convert(data, data.Length, outputData, out outputLength); // Assert AssertOutput(expectedOutput, expectedOutput.Length, outputData, outputLength); }
private void CreateSut(EolConversion eolConversion) { sut = new EolConverter(eolConversion, encodingDetectorMock.Object); }
private void SetupSut(EolConversion eolConversion, EncodingType encoding, bool hasBom) { encodingDetectorMock = IEncodingDetectorMockBuilder.Create() .WithDetectedEncoding(encoding, hasBom); CreateSut(eolConversion); }
public EolDataConverter(EolConversion eolConversion) { eolConverter = new EolConverter(eolConversion, new EncodingDetector()); }