void VerifyIsBinary(List <ConstraintError> messages, IAdditionalFile file) { if (file.IsBinary != IsBinary) { messages.Add(new MismatchConstraintError <bool>( "IsBinary does not match.", IsBinary, file.IsBinary)); } }
static IResultToken WriteText(IAdditionalFile file) { using (var writer = new StringWriter()) { file.GenerateFileContent(writer); writer.Flush(); return(new CodeResultToken(writer.ToString(), file.Suffix)); } }
void VerifySuffix(List <ConstraintError> messages, IAdditionalFile file) { if (file.Suffix != Suffix) { messages.Add(new MismatchConstraintError <string>( "Suffix'es do not match.", Suffix, file.Suffix)); } }
static IResultToken WriteBinary(IAdditionalFile file) { using (var writer = new StringWriter()) using (var stream = new HexStream(writer)) { file.GenerateFileContent(stream); stream.Flush(); return(new CodeResultToken(writer.ToString(), file.Suffix)); } }
protected override void VerifyFileContent(List <ConstraintError> messages, IAdditionalFile file) { byte[] actualBytes; using (var actualStream = new MemoryStream()) { file.GenerateFileContent(actualStream); actualBytes = actualStream.ToArray(); } byte[] expectedBytes; using (var expectedStream = Resource.CreateStream()) { expectedBytes = new byte[expectedStream.Length]; expectedStream.Read(expectedBytes, 0, expectedBytes.Length); } if (actualBytes.Length != expectedBytes.Length) { messages.Add(new MismatchConstraintError <int>( "Resource lengths do not match.", actualBytes.Length, expectedBytes.Length)); } else { var firstErrorOrNull = IndexOfFirstError(expectedBytes, actualBytes); if (firstErrorOrNull.HasValue) { var builder = new StringBuilder(); var firstError = firstErrorOrNull.Value; builder.Append("Resource differs at position "); builder.Append(firstError); builder.AppendLine(); builder.AppendLine(); builder.Append("Expected: "); AppendBufferSegment(builder, expectedBytes, firstError); builder.AppendLine(); builder.Append("Actual: "); AppendBufferSegment(builder, actualBytes, firstError); messages.Add(new SimpleConstraintError(builder.ToString())); } } }
protected override void VerifyFileContent(List <ConstraintError> messages, IAdditionalFile file) { string actualValue; using (var actualStream = new MemoryStream()) using (var actualWriter = new StreamWriter(actualStream)) { file.GenerateFileContent(actualWriter); actualWriter.Flush(); actualValue = actualWriter.Encoding.GetString(actualStream.ToArray()); } var expectedValue = Resource.ReadString(); if (actualValue.Length != expectedValue.Length) { messages.Add(new MismatchConstraintError <int>( "Resource lengths do not match.", actualValue.Length, expectedValue.Length)); } else { var firstErrorOrNull = IndexOfFirstError(expectedValue, actualValue); if (firstErrorOrNull.HasValue) { var builder = new StringBuilder(); var firstError = firstErrorOrNull.Value; builder.Append("Resource differs at position "); builder.Append(firstError); builder.AppendLine(); builder.AppendLine(); builder.Append("Expected: "); AppendBufferSegment(builder, expectedValue, firstError); builder.AppendLine(); builder.Append("Actual: "); AppendBufferSegment(builder, actualValue, firstError); messages.Add(new SimpleConstraintError(builder.ToString())); } } }
static BuildAction GetBuildAction(IAdditionalFile file) { BuildAction action; switch (file.Type) { case AdditionalFileType.Code: action = BuildAction.Compile; break; case AdditionalFileType.EmbeddedResource: action = BuildAction.EmbeddedResource; break; default: action = BuildAction.None; break; } return(action); }
protected abstract void VerifyFileContent(List <ConstraintError> messages, IAdditionalFile file);