From 35249775d1c91b99849f5e2782e184c627bb13cf Mon Sep 17 00:00:00 2001 From: Geo Perez <1775792+geoperez@users.noreply.github.com> Date: Thu, 6 Feb 2020 10:28:08 -0600 Subject: [PATCH] Review and remove coveralls for now --- appveyor.yml | 8 +-- .../Collections/IComponentCollection`1.cs | 1 + src/Swan.Lite/Extensions.ByteArrays.cs | 67 ++++++++++--------- ...ependencyContainerRegistrationException.cs | 6 +- test/Swan.Test/CsvWriterTest.cs | 19 +++--- 5 files changed, 49 insertions(+), 52 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 81ad853de..cc128af4a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -35,16 +35,10 @@ before_build: - ps: $NTP = Start-Process node ntp.js -PassThru - dotnet restore -v Minimal - cmd: mkdir tools -- cmd: nuget install coveralls.net -Version 0.7.0 -OutputDirectory tools build_script: - msbuild /p:Configuration=Release /verbosity:quiet test_script: -- dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude=[NUnit3.TestAdapter]* test/Swan.Test/Swan.Test.csproj -c Release -- ps: | - if(-Not $env:APPVEYOR_PULL_REQUEST_TITLE -And $isWindows) - { - tools\coveralls.net.0.7.0\tools\csmacnz.Coveralls.exe --opencover -i test\Swan.Test\coverage.opencover.xml --serviceName appveyor --jobId $Env:APPVEYOR_BUILD_NUMBER - } +- dotnet test test/Swan.Test/Swan.Test.csproj -c Release after_build: - ps: | if(-Not $env:APPVEYOR_PULL_REQUEST_TITLE -And $isWindows -And $env:APPVEYOR_REPO_BRANCH -eq "master") diff --git a/src/Swan.Lite/Collections/IComponentCollection`1.cs b/src/Swan.Lite/Collections/IComponentCollection`1.cs index a18c7340f..7edfdc2bd 100644 --- a/src/Swan.Lite/Collections/IComponentCollection`1.cs +++ b/src/Swan.Lite/Collections/IComponentCollection`1.cs @@ -8,6 +8,7 @@ namespace Swan.Collections /// Each component in the collection may be given a unique name for later retrieval. /// /// The type of components in the collection. + [Obsolete("This interface will be removed in the next major version")] public interface IComponentCollection : IReadOnlyList { /// diff --git a/src/Swan.Lite/Extensions.ByteArrays.cs b/src/Swan.Lite/Extensions.ByteArrays.cs index 3888912c4..bd025ce38 100644 --- a/src/Swan.Lite/Extensions.ByteArrays.cs +++ b/src/Swan.Lite/Extensions.ByteArrays.cs @@ -125,7 +125,7 @@ public static byte SetBitValueAt(this byte @this, byte offset, byte length, byte /// /// A byte array containing the results the specified sequence of bytes. /// - /// + /// /// buffer /// or /// sequence. @@ -172,7 +172,7 @@ public static List Split(this byte[] @this, int offset, params byte[] se /// /// A byte array containing the results of encoding the specified set of characters. /// - /// this + /// this public static byte[] DeepClone(this byte[] @this) { if (@this == null) @@ -398,14 +398,17 @@ public static MemoryStream Append(this MemoryStream stream, IEnumerable /// /// The buffer. /// The encoding. - /// A that contains the results of decoding the specified sequence of bytes. - public static string ToText(this IEnumerable buffer, Encoding encoding) => encoding.GetString(buffer.ToArray()); + /// A that contains the results of decoding the specified sequence of bytes. + public static string ToText(this IEnumerable buffer, Encoding encoding) => + encoding == null + ? throw new ArgumentNullException(nameof(encoding)) + : encoding.GetString(buffer.ToArray()); /// /// Converts an array of bytes into text with UTF8 encoding. /// /// The buffer. - /// A that contains the results of decoding the specified sequence of bytes. + /// A that contains the results of decoding the specified sequence of bytes. public static string ToText(this IEnumerable buffer) => buffer.ToText(Encoding.UTF8); /// @@ -424,31 +427,32 @@ public static async Task ReadBytesAsync(this Stream stream, long length, if (stream == null) throw new ArgumentNullException(nameof(stream)); - using (var dest = new MemoryStream()) + using var dest = new MemoryStream(); + + try { - try - { - var buff = new byte[bufferLength]; - while (length > 0) - { - if (length < bufferLength) - bufferLength = (int)length; - - var nread = await stream.ReadAsync(buff, 0, bufferLength, cancellationToken).ConfigureAwait(false); - if (nread == 0) - break; - - dest.Write(buff, 0, nread); - length -= nread; - } - } - catch + var buff = new byte[bufferLength]; + while (length > 0) { - // ignored - } + if (length < bufferLength) + bufferLength = (int)length; + + var read = await stream.ReadAsync(buff, 0, bufferLength, cancellationToken).ConfigureAwait(false); + if (read == 0) + break; - return dest.ToArray(); + dest.Write(buff, 0, read); + length -= read; + } + } +#pragma warning disable CA1031 // Do not catch general exception types + catch +#pragma warning restore CA1031 // Do not catch general exception types + { + // ignored } + + return dest.ToArray(); } /// @@ -468,19 +472,22 @@ public static async Task ReadBytesAsync(this Stream stream, int length, var buff = new byte[length]; var offset = 0; + try { while (length > 0) { - var nread = await stream.ReadAsync(buff, offset, length, cancellationToken).ConfigureAwait(false); - if (nread == 0) + var read = await stream.ReadAsync(buff, offset, length, cancellationToken).ConfigureAwait(false); + if (read == 0) break; - offset += nread; - length -= nread; + offset += read; + length -= read; } } +#pragma warning disable CA1031 // Do not catch general exception types catch +#pragma warning restore CA1031 // Do not catch general exception types { // ignored } diff --git a/src/Swan/DependencyInjection/DependencyContainerRegistrationException.cs b/src/Swan/DependencyInjection/DependencyContainerRegistrationException.cs index 389074493..bed99f2da 100644 --- a/src/Swan/DependencyInjection/DependencyContainerRegistrationException.cs +++ b/src/Swan/DependencyInjection/DependencyContainerRegistrationException.cs @@ -8,6 +8,7 @@ /// Generic Constraint Registration Exception. /// /// + [Serializable] public class DependencyContainerRegistrationException : Exception { private const string ConvertErrorText = "Cannot convert current registration of {0} to {1}"; @@ -38,9 +39,6 @@ public DependencyContainerRegistrationException(Type type, string method, bool i { } - private static string GetTypesString(IEnumerable types) - { - return string.Join(",", types.Select(type => type.FullName)); - } + private static string GetTypesString(IEnumerable types) => string.Join(",", types.Select(type => type.FullName)); } } \ No newline at end of file diff --git a/test/Swan.Test/CsvWriterTest.cs b/test/Swan.Test/CsvWriterTest.cs index 178b528ca..61bf9f768 100644 --- a/test/Swan.Test/CsvWriterTest.cs +++ b/test/Swan.Test/CsvWriterTest.cs @@ -79,11 +79,9 @@ public void TempFileFilled_SetStreamLengthToZero() using (var stream = File.OpenWrite(tempFile)) { - using (var writer = new CsvWriter(stream)) - { - writer.WriteHeadings(data); - writer.WriteObjects(new List { data.Select(k => k.Key) }); - } + using var writer = new CsvWriter(stream); + writer.WriteHeadings(data); + writer.WriteObjects(new List { data.Select(k => k.Key) }); } var valuesInFile = CsvReader.LoadRecords(tempFile); @@ -145,7 +143,7 @@ public void Strings_ReturnsAreEqual() using var writer = new CsvWriter(stream); writer.WriteObjects(strings); - Assert.AreEqual((int) writer.Count, strings.Count); + Assert.AreEqual((int)writer.Count, strings.Count); } [Test] @@ -159,7 +157,7 @@ public void DynamicObject_ReturnsAreEqual() writer.WriteObject(dynObject); Assert.IsNotNull(writer); - Assert.AreEqual(1, (int) writer.Count); + Assert.AreEqual(1, (int)writer.Count); } } @@ -181,7 +179,7 @@ public void NullDictionary_ThrowsArgumentNullException() using var stream = new MemoryStream(); using var writer = new CsvWriter(stream); - Assert.Throws(() => + Assert.Throws(() => writer.WriteHeadings(null as Dictionary)); } @@ -245,7 +243,7 @@ public void WritingHeadersFromSampleClass_WritesHeaders() } [Test] - public void WriteHeadingNull () + public void WriteHeadingNull() { using var stream = new MemoryStream(); using var writer = new CsvWriter(stream); @@ -295,9 +293,8 @@ public void ChangeSeparator() var objHeaders = new SampleCsvRecord(); using var stream = new MemoryStream(); - using var writer = new CsvWriter(stream); + using var writer = new CsvWriter(stream) {SeparatorCharacter = '#'}; - writer.SeparatorCharacter = '#'; writer.WriteHeadings(objHeaders); stream.Position = 0;