diff --git a/Source/Code/UtilPack/UtilPack.csproj b/Source/Code/UtilPack/UtilPack.csproj index 4055283..3266c4c 100644 --- a/Source/Code/UtilPack/UtilPack.csproj +++ b/Source/Code/UtilPack/UtilPack.csproj @@ -30,7 +30,7 @@ - 1.7.0 + 1.7.1 UtilPack.Common Library containing useful and generic methods, which are missing from one or more BCL. @@ -41,7 +41,7 @@ $(AssemblyName) $(VersionPrefix) $(PackageVersion)-$(VersionSuffix) - Added .NET Standard 2.0 to targets, in order to reduce build and restore speeds for compatible target frameworks. Also added JoinToString extension methods. + Removed Prepend and Append extension methods for IEnumerable<T> from netstandard2.0 version. bcl utility binary serialization collection extensions Utility Package for CLR diff --git a/Source/Tests/UtilPack.Tests/AsyncEnumeration/ConcurrentTests.cs b/Source/Tests/UtilPack.Tests/AsyncEnumeration/ConcurrentTests.cs deleted file mode 100644 index ef94c20..0000000 --- a/Source/Tests/UtilPack.Tests/AsyncEnumeration/ConcurrentTests.cs +++ /dev/null @@ -1,160 +0,0 @@ -///* -// * Copyright 2017 Stanislav Muhametsin. All rights Reserved. -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// * implied. -// * -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -//using Microsoft.VisualStudio.TestTools.UnitTesting; -//using System; -//using System.Linq; -//using System.Collections.Generic; -//using System.Text; -//using System.Threading; -//using System.Threading.Tasks; -//using UtilPack.AsyncEnumeration; -//using System.Collections.Concurrent; - -//namespace UtilPack.Tests.AsyncEnumeration -//{ -// [TestClass] -// public class ConcurrentTests -// { -// const Int32 MAX_ITEMS = 10; - -// [TestMethod] -// public async Task TestParallelEnumeratorSync() -// { - -// var start = MAX_ITEMS; -// var completionState = new Int32[start]; -// var r = new Random(); -// var enumerator = AsyncEnumerationFactory.CreateConcurrentEnumerable( () => AsyncEnumerationFactory.CreateConcurrentStartInfo( -// () => -// { -// var decremented = Interlocked.Decrement( ref start ); -// return (decremented >= 0, decremented + 1); -// }, -// async ( idx ) => -// { -// await Task.Delay( r.Next( 100, 500 ) ); -// return completionState.Length - idx; -// }, -// null -// ) ); - -// var itemsEncountered = await enumerator.EnumerateConcurrentlyAsync( cur => -// { -// Interlocked.Increment( ref completionState[cur] ); -// } ); - -// Assert.AreEqual( itemsEncountered, completionState.Length ); -// Assert.IsTrue( completionState.All( s => s == 1 ) ); -// } - -// [TestMethod] -// public async Task TestParallelEnumeratorASync() -// { - -// var start = MAX_ITEMS; -// var completionState = new Int32[start]; -// var r = new Random(); -// var enumerator = AsyncEnumerationFactory.CreateConcurrentEnumerable( () => AsyncEnumerationFactory.CreateConcurrentStartInfo( -// () => -// { -// var decremented = Interlocked.Decrement( ref start ); -// return (decremented >= 0, decremented + 1); -// }, -// async ( idx ) => -// { -// await Task.Delay( r.Next( 100, 500 ) ); -// return completionState.Length - idx; -// }, -// null -// ) ); - -// var itemsEncountered = await enumerator.EnumerateConcurrentlyAsync( async cur => -// { -// await Task.Delay( r.Next( 100, 500 ) ); -// Interlocked.Increment( ref completionState[cur] ); -// } ); - -// Assert.AreEqual( itemsEncountered, completionState.Length ); -// Assert.IsTrue( completionState.All( s => s == 1 ) ); -// } - -// [TestMethod] -// public void TestParallelEnumeratorCompletelySync() -// { -// var start = MAX_ITEMS * 100000; -// var completionState = new Int32[start]; -// var r = new Random(); -// var enumerator = AsyncEnumerationFactory.CreateConcurrentEnumerable( () => AsyncEnumerationFactory.CreateConcurrentStartInfo( -// () => -// { -// var decremented = Interlocked.Decrement( ref start ); -// return (decremented >= 0, decremented + 1); -// }, -// ( idx ) => -// { -// return new ValueTask( completionState.Length - idx ); -// }, -// null -// ) ); - -// var itemsEncounteredTask = enumerator.EnumerateConcurrentlyAsync( cur => -// { -// Interlocked.Increment( ref completionState[cur] ); -// } ); - -// Assert.IsTrue( itemsEncounteredTask.IsCompleted ); -// Assert.AreEqual( itemsEncounteredTask.Result, completionState.Length ); -// Assert.IsTrue( completionState.All( s => s == 1 ) ); -// } - -// [TestMethod] -// public async Task TestParallelEnumeratorGetsEndedCalled() -// { -// var start = MAX_ITEMS; -// var completionState = new Int32[start]; -// var r = new Random(); -// var endCalled = false; -// var enumerator = AsyncEnumerationFactory.CreateConcurrentEnumerable( () => AsyncEnumerationFactory.CreateConcurrentStartInfo( -// () => -// { -// var decremented = Interlocked.Decrement( ref start ); -// return (decremented >= 0, decremented + 1); -// }, -// async ( idx ) => -// { -// await Task.Delay( r.Next( 100, 500 ) ); -// return completionState.Length - idx; -// }, -// async () => -// { -// Assert.IsTrue( completionState.All( s => s == 1 ) ); -// await Task.Delay( r.Next( 100, 500 ) ); -// endCalled = true; -// } -// ) ); - -// var itemsEncountered = await enumerator.EnumerateConcurrentlyAsync( cur => -// { -// Interlocked.Increment( ref completionState[cur] ); -// } ); -// Assert.AreEqual( true, endCalled ); -// Assert.AreEqual( itemsEncountered, completionState.Length ); -// } - -// } -//} diff --git a/Source/Tests/UtilPack.Tests/AsyncEnumeration/LINQTests.cs b/Source/Tests/UtilPack.Tests/AsyncEnumeration/LINQTests.cs deleted file mode 100644 index c19d49c..0000000 --- a/Source/Tests/UtilPack.Tests/AsyncEnumeration/LINQTests.cs +++ /dev/null @@ -1,63 +0,0 @@ -///* -// * Copyright 2018 Stanislav Muhametsin. All rights Reserved. -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// * implied. -// * -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -//using AsyncEnumeration.Implementation.Enumerable; -//using AsyncEnumeration.Implementation.Provider; -//using Microsoft.VisualStudio.TestTools.UnitTesting; -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; -//using System.Threading.Tasks; - -//namespace UtilPack.Tests.AsyncEnumeration -//{ -// [TestClass] -// public class LINQTests -// { -// [TestMethod] -// public async Task TestTake() -// { -// var array = await AsyncEnumerable.Repeat( count: 5, item: 1, provider: DefaultAsyncProvider.Instance ).Take( 3 ).ToArrayAsync(); - -// Assert.IsTrue( ArrayEqualityComparer.ArrayEquality( array, Enumerable.Repeat( 1, 3 ).ToArray() ) ); -// } - -// [TestMethod, Timeout( 1000 )] -// public async Task TestTakeNeverEnding() -// { -// var array = await AsyncEnumerable.Neverending( 1, provider: DefaultAsyncProvider.Instance ).Take( 3 ).ToArrayAsync(); -// Assert.IsTrue( ArrayEqualityComparer.ArrayEquality( array, Enumerable.Repeat( 1, 3 ).ToArray() ) ); -// } - -// [TestMethod, Timeout( 1000 )] -// public async Task TestTakeWhile() -// { -// var idx = 0; -// var array = await AsyncEnumerable.Neverending( 1, provider: DefaultAsyncProvider.Instance ).TakeWhile( item => ++idx <= 3 ).ToArrayAsync(); -// Assert.IsTrue( ArrayEqualityComparer.ArrayEquality( array, Enumerable.Repeat( 1, 3 ).ToArray() ) ); -// } - -// [TestMethod] -// public async Task TestTakeWhileAsync() -// { -// var idx = 0; -// var array = await AsyncEnumerable.Neverending( 1, provider: DefaultAsyncProvider.Instance ).TakeWhile( async item => { await Task.Delay( 100 ); return ++idx <= 3; } ).ToArrayAsync(); -// Assert.IsTrue( ArrayEqualityComparer.ArrayEquality( array, Enumerable.Repeat( 1, 3 ).ToArray() ) ); -// } -// } -//} diff --git a/Source/Tests/UtilPack.Tests/AsyncEnumeration/SequentialTests.cs b/Source/Tests/UtilPack.Tests/AsyncEnumeration/SequentialTests.cs deleted file mode 100644 index 8a39f5f..0000000 --- a/Source/Tests/UtilPack.Tests/AsyncEnumeration/SequentialTests.cs +++ /dev/null @@ -1,217 +0,0 @@ -///* -// * Copyright 2017 Stanislav Muhametsin. All rights Reserved. -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// * implied. -// * -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -//using AsyncEnumeration.Implementation.Enumerable; -//using AsyncEnumeration.Implementation.Provider; -//using Microsoft.VisualStudio.TestTools.UnitTesting; -//using System; -//using System.Collections.Concurrent; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; -//using System.Threading; -//using System.Threading.Tasks; - -//namespace UtilPack.Tests.AsyncEnumeration -//{ -// [TestClass] -// public class SequentialTests -// { -// const Int32 MAX_ITEMS = 10; - -// [DataTestMethod] -// public async Task TestSequentialEnumeratorAsync() -// { -// var start = MAX_ITEMS; -// var completionState = new Int32[start]; -// var r = new Random(); -// MoveNextAsyncDelegate moveNext = async () => -// { -// var decremented = Interlocked.Decrement( ref start ); -// await Task.Delay( r.Next( 100, 500 ) ); -// return (decremented >= 0, MAX_ITEMS - decremented - 1); -// }; - -// var enumerable = AsyncEnumerationFactory.CreateSequentialEnumerable( () => AsyncEnumerationFactory.CreateSequentialStartInfo( -// moveNext, -// null -// ), -// DefaultAsyncProvider.Instance ); -// Func callback = async idx => -// { -// await Task.Delay( r.Next( 100, 900 ) ); -// Assert.IsTrue( completionState.Take( idx ).All( s => s == 1 ) ); -// Interlocked.Increment( ref completionState[idx] ); -// }; -// var itemsEncountered = await enumerable.EnumerateAsync( callback ); -// Assert.AreEqual( itemsEncountered, completionState.Length ); -// Assert.IsTrue( completionState.All( s => s == 1 ) ); -// } - -// [DataTestMethod] -// public Task TestSequentialEnumeratorCompletelySync() -// { -// var start = MAX_ITEMS; -// var completionState = new Int32[start]; -// var r = new Random(); -// MoveNextAsyncDelegate moveNext = () => -// { -// var decremented = Interlocked.Decrement( ref start ); -// return new ValueTask<(Boolean, Int32)>( (decremented >= 0, MAX_ITEMS - decremented - 1) ); -// }; - -// var enumerable = AsyncEnumerationFactory.CreateSequentialEnumerable( () => AsyncEnumerationFactory.CreateSequentialStartInfo( -// moveNext, -// null -// ), -// DefaultAsyncProvider.Instance ); -// Action callback = idx => -// { -// Assert.IsTrue( completionState.Take( idx ).All( s => s == 1 ) ); -// Interlocked.Increment( ref completionState[idx] ); -// }; -// var itemsEncounteredTask = enumerable.EnumerateAsync( callback ); - -// TestSequentialEnumeratorCompletelySync_Completion( itemsEncounteredTask.Result, completionState ); -// return Task.CompletedTask; -// } - -// private static void TestSequentialEnumeratorCompletelySync_Completion( -// Int64 itemsEncountered, -// Int32[] completionState -// ) -// { -// Assert.AreEqual( itemsEncountered, completionState.Length ); -// Assert.IsTrue( completionState.All( s => s == 1 ) ); -// } - -// private static async Task TestSequentialEnumeratorCompletelySync_ConcurrentCompletion( -// Task enumerationTask, -// Int32[] completionState -// ) -// { -// TestSequentialEnumeratorCompletelySync_Completion( await enumerationTask, completionState ); -// } - -// //[TestMethod] -// //public async Task TestParallelEnumeratorSync_SequentialEnumeration() -// //{ - -// // var start = MAX_ITEMS; -// // var completionState = new Int32[start]; -// // var r = new Random(); -// // var enumerable = AsyncEnumerationFactory.CreateConcurrentEnumerable( () => AsyncEnumerationFactory.CreateConcurrentStartInfo( -// // () => -// // { -// // var decremented = Interlocked.Decrement( ref start ); -// // return (decremented >= 0, decremented + 1); -// // }, -// // async ( idx ) => -// // { -// // await Task.Delay( r.Next( 100, 500 ) ); -// // return completionState.Length - idx; -// // }, -// // null -// // ) ); - -// // var itemsEncountered = await enumerable.EnumerateSequentiallyAsync( cur => -// // { -// // Interlocked.Increment( ref completionState[cur] ); -// // } ); - -// // Assert.AreEqual( itemsEncountered, completionState.Length ); -// // Assert.IsTrue( completionState.All( s => s == 1 ) ); -// //} - -// //[TestMethod] -// //public async Task TestParallelEnumeratorASync_SequentialEnumeration() -// //{ - -// // var start = MAX_ITEMS; -// // var completionState = new Int32[start]; -// // var r = new Random(); -// // var enumerable = AsyncEnumerationFactory.CreateConcurrentEnumerable( () => AsyncEnumerationFactory.CreateConcurrentStartInfo( -// // () => -// // { -// // var decremented = Interlocked.Decrement( ref start ); -// // return (decremented >= 0, decremented + 1); -// // }, -// // async ( idx ) => -// // { -// // await Task.Delay( r.Next( 100, 500 ) ); -// // return completionState.Length - idx; -// // }, -// // null -// // ) ); - -// // var itemsEncountered = await enumerable.EnumerateSequentiallyAsync( async cur => -// // { -// // await Task.Delay( r.Next( 100, 500 ) ); -// // Interlocked.Increment( ref completionState[cur] ); -// // } ); - -// // Assert.AreEqual( itemsEncountered, completionState.Length ); -// // Assert.IsTrue( completionState.All( s => s == 1 ) ); -// //} - -// //[TestMethod] -// //public void TestParallelEnumeratorCompletelySync_SequentialEnumeration() -// //{ -// // var start = MAX_ITEMS * 100000; -// // var completionState = new Int32[start]; -// // var r = new Random(); -// // var enumerable = AsyncEnumerationFactory.CreateConcurrentEnumerable( () => AsyncEnumerationFactory.CreateConcurrentStartInfo( -// // () => -// // { -// // var decremented = Interlocked.Decrement( ref start ); -// // return (decremented >= 0, decremented + 1); -// // }, -// // ( idx ) => -// // { -// // return new ValueTask( completionState.Length - idx ); -// // }, -// // null -// // ) ); - -// // var itemsEncounteredTask = enumerable.EnumerateSequentiallyAsync( cur => -// // { -// // Interlocked.Increment( ref completionState[cur] ); -// // } ); - -// // Assert.IsTrue( itemsEncounteredTask.IsCompleted ); -// // Assert.AreEqual( itemsEncounteredTask.Result, completionState.Length ); -// // Assert.IsTrue( completionState.All( s => s == 1 ) ); -// //} - -// [TestMethod] -// public async Task TestAsyncLINQ() -// { -// var array = Enumerable.Range( 0, 10 ).ToArray(); -// var enumerable = array.AsAsyncEnumerable( DefaultAsyncProvider.Instance ); -// var array2 = await enumerable.ToArrayAsync(); -// Assert.IsTrue( ArrayEqualityComparer.ArrayEquality( array, array2 ) ); - -// var sequentialList = new List(); -// var itemsEncountered2 = await enumerable.Where( x => x >= 5 ).EnumerateAsync( async cur => -// { -// await Task.Delay( new Random().Next( 300, 500 ) ); -// sequentialList.Add( cur ); -// } ); -// Assert.IsTrue( ArrayEqualityComparer.ArrayEquality( array.Where( x => x >= 5 ).ToArray(), sequentialList.ToArray() ) ); -// } -// } -//} diff --git a/Source/Tests/UtilPack.Tests/Cryptography/Digest/DigestTests.cs b/Source/Tests/UtilPack.Tests/Cryptography/Digest/DigestTests.cs deleted file mode 100644 index 390f74d..0000000 --- a/Source/Tests/UtilPack.Tests/Cryptography/Digest/DigestTests.cs +++ /dev/null @@ -1,270 +0,0 @@ -///* -// * Copyright 2017 Stanislav Muhametsin. All rights Reserved. -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// * implied. -// * -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -//using FluentCryptography.Digest; -//using Microsoft.VisualStudio.TestTools.UnitTesting; -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; - -//namespace UtilPack.Tests.Cryptography.Digest -//{ -// using TNativeAlgorithmFactory = Func; -// using TUtilPackAlgorithmFactory = Func; - -// [TestClass] -// public class DigestTests -// { -// private static readonly TNativeAlgorithmFactory NativeMD5 = ( key ) => System.Security.Cryptography.MD5.Create(); -// private static readonly TNativeAlgorithmFactory NativeSHA128 = ( key ) => System.Security.Cryptography.SHA1.Create(); -// private static readonly TNativeAlgorithmFactory NativeSHA256 = ( key ) => System.Security.Cryptography.SHA256.Create(); -// private static readonly TNativeAlgorithmFactory NativeSHA384 = ( key ) => System.Security.Cryptography.SHA384.Create(); -// private static readonly TNativeAlgorithmFactory NativeSHA512 = ( key ) => System.Security.Cryptography.SHA512.Create(); - -// private static readonly TNativeAlgorithmFactory NativeHMACMD5 = ( key ) => new System.Security.Cryptography.HMACMD5( key ); -// private static readonly TNativeAlgorithmFactory NativeHMACSHA128 = ( key ) => new System.Security.Cryptography.HMACSHA1( key ); -// private static readonly TNativeAlgorithmFactory NativeHMACSHA256 = ( key ) => new System.Security.Cryptography.HMACSHA256( key ); -// private static readonly TNativeAlgorithmFactory NativeHMACSHA384 = ( key ) => new System.Security.Cryptography.HMACSHA384( key ); -// private static readonly TNativeAlgorithmFactory NativeHMACSHA512 = ( key ) => new System.Security.Cryptography.HMACSHA512( key ); - -// private static readonly TUtilPackAlgorithmFactory UtilPackMD5 = ( key ) => new MD5(); -// private static readonly TUtilPackAlgorithmFactory UtilPackSHA128 = ( key ) => new SHA128(); -// private static readonly TUtilPackAlgorithmFactory UtilPackSHA256 = ( key ) => new SHA256(); -// private static readonly TUtilPackAlgorithmFactory UtilPackSHA384 = ( key ) => new SHA384(); -// private static readonly TUtilPackAlgorithmFactory UtilPackSHA512 = ( key ) => new SHA512(); - - -// private static readonly TUtilPackAlgorithmFactory UtilPackHMACMD5 = ( key ) => new MD5().CreateHMAC( key ); -// private static readonly TUtilPackAlgorithmFactory UtilPackHMACSHA128 = ( key ) => new SHA128().CreateHMAC( key ); -// private static readonly TUtilPackAlgorithmFactory UtilPackHMACSHA256 = ( key ) => new SHA256().CreateHMAC( key ); -// private static readonly TUtilPackAlgorithmFactory UtilPackHMACSHA384 = ( key ) => new SHA384().CreateHMAC( key ); -// private static readonly TUtilPackAlgorithmFactory UtilPackHMACSHA512 = ( key ) => new SHA512().CreateHMAC( key ); - -// private static T PickBasedOnKey( T keyless, T keyful, Byte[] key ) -// { -// return key.IsNullOrEmpty() ? keyless : keyful; -// } - -// [DataTestMethod, -// DataRow( null ), -// DataRow( new Byte[] { 1, 2, 3 } ) -// ] -// public void TestMD5( -// Byte[] key -// ) -// { -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeMD5, NativeHMACMD5, key ), -// PickBasedOnKey( UtilPackMD5, UtilPackHMACMD5, key ), -// key, -// 1, 10 -// ); -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeMD5, NativeHMACMD5, key ), -// PickBasedOnKey( UtilPackMD5, UtilPackHMACMD5, key ), -// key, -// 1000, -// 2000 -// ); -// } - -// [DataTestMethod, -// DataRow( null ), -// DataRow( new Byte[] { 1, 2, 3 } )] -// public void TestSHA128( -// Byte[] key -// ) -// { -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeSHA128, NativeHMACSHA128, key ), -// PickBasedOnKey( UtilPackSHA128, UtilPackHMACSHA128, key ), -// key, -// 1, 10 -// ); -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeSHA128, NativeHMACSHA128, key ), -// PickBasedOnKey( UtilPackSHA128, UtilPackHMACSHA128, key ), -// key, -// 1000, -// 2000 -// ); -// } - -// [DataTestMethod, -// DataRow( null ), -// DataRow( new Byte[] { 1, 2, 3 } )] -// public void TestSHA256( -// Byte[] key -// ) -// { -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeSHA256, NativeHMACSHA256, key ), -// PickBasedOnKey( UtilPackSHA256, UtilPackHMACSHA256, key ), -// key, -// 1, 10 -// ); -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeSHA256, NativeHMACSHA256, key ), -// PickBasedOnKey( UtilPackSHA256, UtilPackHMACSHA256, key ), -// key, -// 1000, -// 2000 -// ); -// } - -// [DataTestMethod, -// DataRow( null ), -// DataRow( new Byte[] { 1, 2, 3 } )] -// public void TestSHA384( -// Byte[] key -// ) -// { -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeSHA384, NativeHMACSHA384, key ), -// PickBasedOnKey( UtilPackSHA384, UtilPackHMACSHA384, key ), -// key, -// 1, 10 -// ); -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeSHA384, NativeHMACSHA384, key ), -// PickBasedOnKey( UtilPackSHA384, UtilPackHMACSHA384, key ), -// key, -// 1000, -// 2000 -// ); -// } - -// [DataTestMethod, -// DataRow( null ), -// DataRow( new Byte[] { 1, 2, 3 } )] -// public void TestSHA512( -// Byte[] key -// ) -// { -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeSHA512, NativeHMACSHA512, key ), -// PickBasedOnKey( UtilPackSHA512, UtilPackHMACSHA512, key ), -// key, -// 1, 10 -// ); -// this.VerifyNativeVsUtilPack( -// PickBasedOnKey( NativeSHA512, NativeHMACSHA512, key ), -// PickBasedOnKey( UtilPackSHA512, UtilPackHMACSHA512, key ), -// key, -// 1000, -// 2000 -// ); -// } - -// [TestMethod] -// public void TestMultipleSmallWrites() -// { -// var b1 = new Byte[] { 1, 2, 3 }; -// var b2 = new Byte[] { 4, 5, 6 }; -// Byte[] nativeHash; -// using ( var native = System.Security.Cryptography.SHA512.Create() ) -// { -// nativeHash = native.ComputeHash( b1.Concat( b2 ).ToArray() ); -// } - -// var utilPackHash = new Byte[SHA512.DIGEST_BYTE_COUNT]; -// using ( var utilPack = new SHA512() ) -// { -// utilPack.ProcessBlock( b1.ToArray() ); -// utilPack.ProcessBlock( b2.ToArray() ); -// utilPack.WriteDigest( utilPackHash ); -// } - -// Assert.IsTrue( ArrayEqualityComparer.ArrayEquality( nativeHash, utilPackHash ) ); -// } - -// private void VerifyNativeVsUtilPack( -// TNativeAlgorithmFactory nativeFactory, -// TUtilPackAlgorithmFactory utilPackFactory, -// Byte[] key, -// Int32 minLength, -// Int32 maxLength -// ) -// { -// var r = new Random(); -// var count = minLength + ( Math.Abs( r.NextInt32() ) % ( maxLength - minLength ) ); -// var bytez = r.NextBytes( count ); - -// Byte[] nativeHash; -// using ( var native = nativeFactory( key.CreateArrayCopy() ) ) -// { -// nativeHash = native.ComputeHash( bytez ); -// } - -// Byte[] camHash; -// using ( var cam = utilPackFactory( key.CreateArrayCopy() ) ) -// { -// camHash = cam.ComputeDigest( bytez, 0, bytez.Length ); - -// Assert.IsTrue( -// ArrayEqualityComparer.ArrayEquality( nativeHash, camHash ), -// "The hash differed:\nNative hash: {0}\nUtilPack hash: {1}\ninput: {2}", -// StringConversions.CreateHexString( nativeHash ), -// StringConversions.CreateHexString( camHash ), -// StringConversions.CreateHexString( bytez ) -// ); - -// // Test that resetting works by computing same digest again -// camHash = cam.ComputeDigest( bytez, 0, bytez.Length ); -// Assert.IsTrue( -// ArrayEqualityComparer.ArrayEquality( nativeHash, camHash ), -// "The hash differed:\nNative hash: {0}\nUtilPack hash: {1}\ninput: {2}", -// StringConversions.CreateHexString( nativeHash ), -// StringConversions.CreateHexString( camHash ), -// StringConversions.CreateHexString( bytez ) -// ); -// } - - -// } - -// } - - -//} - -//public static partial class E_UtilPackTests -//{ - -// // From Jon Skeet's answer on http://stackoverflow.com/questions/609501/generating-a-random-decimal-in-c-sharp -// /// -// /// Returns an Int32 with a random value across the entire range of -// /// possible values. -// /// -// public static Int32 NextInt32( this Random rng ) -// { -// unchecked -// { -// var firstBits = rng.Next( 0, 1 << 4 ) << 28; -// var lastBits = rng.Next( 0, 1 << 28 ); -// return firstBits | lastBits; -// } -// } - -// public static Byte[] NextBytes( this Random rng, Int32 byteCount ) -// { -// var bytez = new Byte[byteCount]; -// rng.NextBytes( bytez ); -// return bytez; -// } -//} \ No newline at end of file diff --git a/Source/Tests/UtilPack.Tests/Cryptography/SASL/SCRAM/SCRAMTest.cs b/Source/Tests/UtilPack.Tests/Cryptography/SASL/SCRAM/SCRAMTest.cs deleted file mode 100644 index cfef3f2..0000000 --- a/Source/Tests/UtilPack.Tests/Cryptography/SASL/SCRAM/SCRAMTest.cs +++ /dev/null @@ -1,210 +0,0 @@ -///* -// * Copyright 2017 Stanislav Muhametsin. All rights Reserved. -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// * implied. -// * -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -//using FluentCryptography.Digest; -//using FluentCryptography.SASL; -//using FluentCryptography.SASL.SCRAM; -//using Microsoft.VisualStudio.TestTools.UnitTesting; -//using System; -//using System.Collections.Generic; -//using System.Text; -//using System.Threading; -//using System.Threading.Tasks; - -//namespace UtilPack.Tests.Cryptography.SASL.SCRAM -//{ -// [TestClass] -// public class SCRAMTest -// { -// // This tests with messages defined in RFC-5802 example (section 5) and RFC-7677 (section 3) -// [DataTestMethod, -// DataRow( typeof( SHA128 ), "user", "pencil", "fyko+d2lbbFgONRv9qkxdawL", "QSXCR+Q6sek8bf92", "3rfcNHYJY1ZVvWVs7j", 4096, "v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=", "rmF9pqV8S7suAoZWja4dJRkFsKQ=", "HZbuOlKbWl+eR8AfIposuKbhX30=" ), -// DataRow( typeof( SHA256 ), "user", "pencil", "rOprNGfwEbeRWgbNEkqO", "W22ZaJ0SNY7soEsUEjb6gQ==", "%hvYDpWUa2RaTCAfuxFIlj)hNlF$k0", 4096, "dHzbZapWIk4jUhN+Ute9ytag9zjfMHgsqmmiz7AndVQ=", "6rriTRBi23WpRR/wtup+mMhUZUn/dB5nLTJRsjl95G4=", "xKSVEDI6tPlSysH6mUQZOeeOp01r6B3fcJbodRPcYV0=" ) -// ] -// public void TestSCRAMClient( -// Type algorithmType, -// String username, -// String password, -// String clientNonce, -// String serverSalt, -// String serverNonce, -// Int32 iterationCount, -// String clientProof, -// String serverProof, -// String clientPasswordDigest -// ) -// { - -// var encoding = new UTF8Encoding( false, false ).CreateDefaultEncodingInfo(); -// using ( var client = ( (BlockDigestAlgorithm) Activator.CreateInstance( algorithmType ) ).CreateSASLClientSCRAM( () => encoding.Encoding.GetBytes( clientNonce ) ) ) -// { -// var writeArray = new ResizableArray(); -// var credentials = new SASLCredentialsSCRAMForClient( -// username, -// password -// ); - -// // Phase 1. -// (var bytesWritten, var challengeResult) = client.ChallengeAsync( credentials.CreateChallengeArguments( -// null, // Initial phase does not read anything -// -1, -// -1, -// writeArray, -// 0, -// encoding -// ) ).Result.First; -// Assert.IsTrue( bytesWritten > 0 ); -// Assert.AreEqual( challengeResult, SASLChallengeResult.MoreToCome ); -// Assert.AreEqual( "n,,n=" + username + ",r=" + clientNonce, encoding.Encoding.GetString( writeArray.Array, 0, bytesWritten ) ); - -// // Phase 2. -// var serverBytes = encoding.Encoding.GetBytes( "r=" + clientNonce + serverNonce + ",s=" + serverSalt + ",i=" + iterationCount ); -// (bytesWritten, challengeResult) = client.ChallengeAsync( credentials.CreateChallengeArguments( -// serverBytes, -// 0, -// serverBytes.Length, -// writeArray, -// 0, -// encoding -// ) ).Result.First; -// Assert.IsTrue( bytesWritten > 0 ); -// Assert.AreEqual( challengeResult, SASLChallengeResult.MoreToCome ); -// Assert.AreEqual( "c=biws,r=" + clientNonce + serverNonce + ",p=" + clientProof, encoding.Encoding.GetString( writeArray.Array, 0, bytesWritten ) ); -// Assert.AreEqual( clientPasswordDigest, Convert.ToBase64String( credentials.PasswordDigest ) ); - -// // Phase 3 -// serverBytes = encoding.Encoding.GetBytes( "v=" + serverProof ); -// (bytesWritten, challengeResult) = client.ChallengeAsync( credentials.CreateChallengeArguments( -// serverBytes, -// 0, -// serverBytes.Length, -// writeArray, -// 0, -// encoding -// ) ).Result.First; -// Assert.AreEqual( challengeResult, SASLChallengeResult.Completed ); -// Assert.AreEqual( bytesWritten, 0 ); -// } - -// } - -// [DataTestMethod, -// DataRow( typeof( SHA128 ), "user", "pencil", "6dlGYMOdZcOPutkcNY8U2g7vK9Y=", "D+CSWLOshSulAsxiupA+qs2/fTE=", "QSXCR+Q6sek8bf92", 4096 ), -// DataRow( typeof( SHA256 ), "user", "pencil", "WG5d8oPm3OtcPnkdi4Uo7BkeZkBFzpcXkuLmtbsT4qY=", "wfPLwcE6nTWhTAmQ7tl2KeoiWGPlZqQxSrmfPwDl2dU=", "W22ZaJ0SNY7soEsUEjb6gQ==", 4096 ) -// ] -// public void TestSCRAMClientAndServerInterop( -// Type algorithmType, -// String username, -// String password, -// String clientKeyDigest, // H(key_c) -// String serverKey, // key_s -// String serverSalt, -// Int32 iterationCount -// ) -// { -// var encoding = new UTF8Encoding( false, false ).CreateDefaultEncodingInfo(); -// var serverCallbackCalled = 0; -// using ( var client = ( (BlockDigestAlgorithm) Activator.CreateInstance( algorithmType ) ).CreateSASLClientSCRAM() ) -// using ( var server = ( (BlockDigestAlgorithm) Activator.CreateInstance( algorithmType ) ).CreateSASLServerSCRAM( async serverUsername => -// { -// Assert.AreEqual( username, serverUsername ); - -// // Simulate fetching data from DB (each user should have all these 4 attributes) -// await Task.Delay( 100 ); - -// Interlocked.Exchange( ref serverCallbackCalled, 1 ); -// return new SASLCredentialsSCRAMForServer( -// Convert.FromBase64String( clientKeyDigest ), -// Convert.FromBase64String( serverKey ), -// Convert.FromBase64String( serverSalt ), -// iterationCount -// ); -// } ) ) -// { -// var clientWriteArray = new ResizableArray(); -// var clientCredentials = new SASLCredentialsSCRAMForClient( -// username, -// password -// ); - -// var serverWriteArray = new ResizableArray(); -// var serverCredentials = new SASLCredentialsHolder(); - -// // Client-first -// (var bytesWritten, var challengeResult) = client.ChallengeAsync( clientCredentials.CreateChallengeArguments( -// null, // Initial phase does not read anything -// -1, -// -1, -// clientWriteArray, -// 0, -// encoding -// ) ).Result.First; -// Assert.IsTrue( bytesWritten > 0 ); -// Assert.AreEqual( challengeResult, SASLChallengeResult.MoreToCome ); - -// // Server-first -// (bytesWritten, challengeResult) = server.ChallengeAsync( serverCredentials.CreateServerMechanismArguments( -// clientWriteArray.Array, -// 0, -// bytesWritten, -// serverWriteArray, -// 0, -// encoding -// ) ).Result.First; -// Assert.IsTrue( bytesWritten > 0 ); -// Assert.AreEqual( challengeResult, SASLChallengeResult.MoreToCome ); -// Assert.AreNotEqual( 0, serverCallbackCalled ); - -// // Client-final -// (bytesWritten, challengeResult) = client.ChallengeAsync( clientCredentials.CreateChallengeArguments( -// serverWriteArray.Array, -// 0, -// bytesWritten, -// clientWriteArray, -// 0, -// encoding -// ) ).Result.First; -// Assert.IsTrue( bytesWritten > 0 ); -// Assert.AreEqual( challengeResult, SASLChallengeResult.MoreToCome ); - -// // Server-final -// (bytesWritten, challengeResult) = server.ChallengeAsync( serverCredentials.CreateServerMechanismArguments( -// clientWriteArray.Array, -// 0, -// bytesWritten, -// serverWriteArray, -// 0, -// encoding -// ) ).Result.First; -// Assert.IsTrue( bytesWritten > 0 ); -// Assert.AreEqual( challengeResult, SASLChallengeResult.Completed ); - -// // Client-validate -// (bytesWritten, challengeResult) = client.ChallengeAsync( clientCredentials.CreateChallengeArguments( -// serverWriteArray.Array, -// 0, -// bytesWritten, -// clientWriteArray, -// 0, -// encoding -// ) ).Result.First; -// Assert.AreEqual( bytesWritten, 0 ); -// Assert.AreEqual( challengeResult, SASLChallengeResult.Completed ); -// } -// } -// } -//} diff --git a/Source/Tests/UtilPack.Tests/NuGet/NuGetAssemblyResolveTest.cs b/Source/Tests/UtilPack.Tests/NuGet/NuGetAssemblyResolveTest.cs deleted file mode 100644 index 1767db5..0000000 --- a/Source/Tests/UtilPack.Tests/NuGet/NuGetAssemblyResolveTest.cs +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright 2017 Stanislav Muhametsin. All rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ -//using Microsoft.VisualStudio.TestTools.UnitTesting; -//using NuGet.Commands; -//using NuGet.Common; -//using NuGet.Configuration; -//using NuGet.DependencyResolver; -//using NuGet.Frameworks; -//using NuGet.LibraryModel; -//using NuGet.Packaging; -//using NuGet.ProjectModel; -//using NuGet.Protocol; -//using NuGet.Protocol.Core.Types; -//using NuGet.Repositories; -//using NuGet.Versioning; -//using System; -//using System.Collections.Generic; -//using System.IO; -//using System.Linq; -//using System.Reflection; -//using System.Runtime.Loader; -//using System.Text; -//using System.Threading.Tasks; - -namespace UtilPack.Tests.NuGet -{ - //[TestClass] - public class NuGetAssemblyResolveTest - { - - //[TestMethod] - //public async Task TestThatTypeGetTypeWorks() - //{ - // var nugetSettings = UtilPackNuGetUtility.GetNuGetSettingsWithDefaultRootDirectory( null ); - // var restorer = new BoundRestoreCommandUser( nugetSettings ); - // var assemblyResolver = NuGetAssemblyResolverFactory.NewNuGetAssemblyResolver( - // restorer, - // await restorer.RestoreIfNeeded( "Microsoft.NETCore.App", "1.1.2" ), - // out var loader, - // loadersRegistration: OtherLoadersRegistration.Default - // ); - // var pushAssembly = await assemblyResolver.LoadNuGetAssembly( "UtilPack.NuGet.Push.MSBuild", "1.2.0" ); - // const String PUSH_TASK = "UtilPack.NuGet.Push.MSBuild.PushTask"; - // var taskType = Type.GetType( PUSH_TASK + ", " + pushAssembly.FullName ); - // Assert.IsNotNull( taskType ); - // Assert.IsTrue( ReferenceEquals( taskType, pushAssembly.GetType( PUSH_TASK ) ) ); - // Assert.IsTrue( ReferenceEquals( taskType, Type.GetType( PUSH_TASK + ", " + pushAssembly.GetName().Name ) ) ); - //} - - //[TestMethod] - //public async Task TestThatNoUtilPackAssembliesLoadedByAssemblyResolver() - //{ - // var nugetSettings = Settings.LoadDefaultSettings( - // Path.GetDirectoryName( new Uri( this.GetType().GetTypeInfo().Assembly.CodeBase ).LocalPath ), - // null, - // new XPlatMachineWideSetting() - // ); - // var restorer = new BoundRestoreCommandUser( - // nugetSettings, - // Assembly.GetEntryAssembly().GetNuGetFrameworkFromAssembly(), - // new ConsoleLogger() - // ); - - // var cbam = await restorer.RestoreIfNeeded( "CBAM.SQL.MSBuild", "0.1.0-beta" ); - // var cbamAssembly = restorer.ExtractAssemblyPaths( cbam, ( dir, assemblies ) => assemblies )["CBAM.SQL.MSBuild"].First(); - - // var resolver = NuGetAssemblyResolverFactory.NewNuGetAssemblyResolver( - // restorer, - // await restorer.RestoreIfNeeded( "Microsoft.NETCore.App", "1.1.2" ), - // out var createdLoader - // ); - - // var loadedAssembly = await resolver.LoadNuGetAssembly( "CBAM.SQL.MSBuild", "0.1.0-beta" ); - - // var ctx = AssemblyLoadContext.GetLoadContext( loadedAssembly ); - //} - - - - // [TestMethod] - // public void TestSingleAssemblyResolve() - // { - // var repo = CreateDefaultLocalRepo(); - // var nugetClientPackage = repo.FindPackagesById( "NuGet.Client" ).First(); - // var assemblies = new NuGetPathResolver().GetSingleNuGetPackageAssemblies( nugetClientPackage ); - // Assert.AreEqual( 1, assemblies.Length ); - // } - - // [TestMethod] - // public void TestAssemblyResolveWithDependencies() - // { - // var repo = CreateDefaultLocalRepo(); - // var nugetClientPackage = repo.FindPackagesById( "NuGet.Client" ).First(); - // var assemblies = new NuGetPathResolver().GetNuGetPackageAssembliesAndDependencies( nugetClientPackage, repo ); - // } - - // [TestMethod] - // public void TestNETCoreAppResolve() - // { - // var repo = CreateDefaultLocalRepo(); - // var package = repo.FindPackage( "Microsoft.NETCore.App", NuGetVersion.Parse( "1.1.2" ) ); - // var thisAssembly = Assembly.GetEntryAssembly(); - // var thisFW = NuGetFramework.Parse( ".NETCoreApp1.1" ); // thisAssembly.GetNuGetFrameworkFromAssembly(); the test assembly is actually .NET Core App 1.0, even though the version in .csproj is 1.1. - // (var assemblyInfo, var missingDependencies) = new NuGetPathResolver( r => - // { - // return r.GetLibItems( PackagingConstants.Folders.Ref ).Concat( r.GetLibItems() ); - // } ).GetNuGetPackageAssembliesAndDependencies( package, thisFW, repo.Singleton() ); - - // Assert.AreEqual( 0, missingDependencies.Count ); - - // var resolvedAssemblies = assemblyInfo.Values - // .SelectMany( p => p ) - // .Select( p => Path.GetFileName( p ) ) - // .ToArray(); - - // var allDLLs = Directory.EnumerateFiles( @"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.2" ) - // .Where( fullFilePath => - // { - // var file = Path.GetFileName( fullFilePath ); - // var retVal = file.EndsWith( ".dll", StringComparison.OrdinalIgnoreCase ) - // && !file.EndsWith( ".ni.dll", StringComparison.OrdinalIgnoreCase ) - // && file.IndexOf( "Private", StringComparison.OrdinalIgnoreCase ) == -1 - // && !String.Equals( "mscorlib.dll", file, StringComparison.OrdinalIgnoreCase ) - // && !String.Equals( "SOS.NETCore.dll", file, StringComparison.Ordinal ) - // ; - // if ( retVal ) - // { - // try - // { - // System.Runtime.Loader.AssemblyLoadContext.GetAssemblyName( fullFilePath ); - // } - // catch ( BadImageFormatException ) - // { - // retVal = false; - // } - // } - // return retVal; - // } ) - // .Select( fullFilePath => Path.GetFileName( fullFilePath ) ) - // .ToArray(); - - // Assert.AreEqual( allDLLs.Length, resolvedAssemblies.Length ); - - // var set = new HashSet( allDLLs ); - // set.ExceptWith( resolvedAssemblies ); - // Assert.AreEqual( 0, set.Count ); - // } - - - // private static NuGetv3LocalRepository CreateDefaultLocalRepo() - // { - // return new NuGetv3LocalRepository( Path.Combine( NuGetEnvironment.GetFolderPath( NuGetFolderPath.NuGetHome ), "packages" ) ); - // } - } - - //public sealed class ConsoleLogger : ILogger - //{ - - // public void LogDebug( String data ) - // { - // Console.WriteLine( "[NuGet Debug]: " + data ); - // } - - // public void LogError( String data ) - // { - // Console.WriteLine( "[NuGet Error]: " + data ); - // } - - // public void LogErrorSummary( String data ) - // { - // Console.WriteLine( "[NuGet ErrorSummary]: " + data ); - // } - - // public void LogInformation( String data ) - // { - // Console.WriteLine( "[NuGet Info]: " + data ); - // } - - // public void LogInformationSummary( String data ) - // { - // Console.WriteLine( "[NuGet InfoSummary]: " + data ); - // } - - // public void LogMinimal( String data ) - // { - // Console.WriteLine( "[NuGet Minimal]: " + data ); - // } - - // public void LogVerbose( String data ) - // { - // Console.WriteLine( "[NuGet Verbose]: " + data ); - // } - - // public void LogWarning( String data ) - // { - // Console.WriteLine( "[NuGet Warning]: " + data ); - // } - //} -}