コード例 #1
0
 void VerifyIsBinary(List <ConstraintError> messages, IAdditionalFile file)
 {
     if (file.IsBinary != IsBinary)
     {
         messages.Add(new MismatchConstraintError <bool>(
                          "IsBinary does not match.",
                          IsBinary,
                          file.IsBinary));
     }
 }
コード例 #2
0
        static IResultToken WriteText(IAdditionalFile file)
        {
            using (var writer = new StringWriter())
            {
                file.GenerateFileContent(writer);
                writer.Flush();

                return(new CodeResultToken(writer.ToString(), file.Suffix));
            }
        }
コード例 #3
0
 void VerifySuffix(List <ConstraintError> messages, IAdditionalFile file)
 {
     if (file.Suffix != Suffix)
     {
         messages.Add(new MismatchConstraintError <string>(
                          "Suffix'es do not match.",
                          Suffix,
                          file.Suffix));
     }
 }
コード例 #4
0
        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));
                }
        }
コード例 #5
0
        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()));
                }
            }
        }
コード例 #6
0
        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()));
                }
            }
        }
コード例 #7
0
ファイル: Generator.cs プロジェクト: brian-reichle/Buffalo
        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);
        }
コード例 #8
0
 protected abstract void VerifyFileContent(List <ConstraintError> messages, IAdditionalFile file);