1 // Copyright (c) Microsoft. All rights reserved. 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 4 using System; 5 using System.Collections.Generic; 6 using System.Text; 7 using System.IO; 8 9 using Microsoft.Build.Framework; 10 using Xunit; 11 using Microsoft.Build.Logging; 12 13 namespace Microsoft.Build.UnitTests 14 { 15 public class LoggerDescription_Tests 16 { 17 [Fact] LoggerDescriptionCustomSerialization()18 public void LoggerDescriptionCustomSerialization() 19 { 20 string className = "Class"; 21 string loggerAssemblyName = "Class"; 22 string loggerFileAssembly = null; 23 string loggerSwitchParameters = "Class"; 24 LoggerVerbosity verbosity = LoggerVerbosity.Detailed; 25 26 LoggerDescription description = new LoggerDescription(className, loggerAssemblyName, loggerFileAssembly, loggerSwitchParameters, verbosity); 27 MemoryStream stream = new MemoryStream(); 28 BinaryWriter writer = new BinaryWriter(stream); 29 BinaryReader reader = new BinaryReader(stream); 30 try 31 { 32 stream.Position = 0; 33 description.WriteToStream(writer); 34 long streamWriteEndPosition = stream.Position; 35 stream.Position = 0; 36 LoggerDescription description2 = new LoggerDescription(); 37 description2.CreateFromStream(reader); 38 long streamReadEndPosition = stream.Position; 39 Assert.Equal(streamWriteEndPosition, streamReadEndPosition); // "Stream end positions should be equal" 40 41 Assert.Equal(description.Verbosity, description2.Verbosity); // "Expected Verbosity to Match" 42 Assert.Equal(description.LoggerId, description2.LoggerId); // "Expected Verbosity to Match" 43 Assert.Equal(0, string.Compare(description.LoggerSwitchParameters, description2.LoggerSwitchParameters, StringComparison.OrdinalIgnoreCase)); // "Expected LoggerSwitchParameters to Match" 44 Assert.Equal(0, string.Compare(description.Name, description2.Name, StringComparison.OrdinalIgnoreCase)); // "Expected Name to Match" 45 } 46 finally 47 { 48 reader.Dispose(); 49 writer = null; 50 stream = null; 51 } 52 } 53 } 54 } 55