コード例 #1
0
        public static TheoryData <string> InvalidCookieNames()
        {
            var invalidNames = new TheoryData <string>
            {
                "foo=",
                "foo;",
                "foo\0",
                "foo👍",
                "foo\\",
                "foo(",
                "foo)",
                "foo<",
                "foo>",
                "foo@foo",
                "foo,bar",
                "foo:bar",
                "foo\"bar",
                "bar/foo",
                "foo[bar",
                "foo]bar",
                "foo?bar",
                "{foo",
                "}foo",
            };

            foreach (var value in Constant.WhitespaceValues)
            {
                invalidNames.Add(value);
            }

            return(invalidNames);
        }
コード例 #2
0
        public static TheoryData <string, string, string, string> TestData()
        {
            var testsString = EmbeddedResourceUtils.LoadResourceFile(typeof(JsonPatchFactoryTests).Assembly,
                                                                     "JsonPatchGenerator.Tests.Resources.tests.json");

            var tests  = (JArray)JToken.Parse(testsString);
            var result = new TheoryData <string, string, string, string>();

            foreach (var test in tests.Cast <JObject>())
            {
                if (test.Property("error") != null)
                {
                    continue;
                }
                if (test.Property("disabled") != null)
                {
                    continue;
                }

                var doc      = test.Property("doc") !.Value;
                var expected = test.Property("expected") !.Value;
                var patch    = test.Property("patch") !.Value;
                var comment  = test.Property("comment")?.Value.Value <string>() ?? string.Empty;

                result.Add(doc.ToString(Formatting.None), expected.ToString(Formatting.None),
                           patch.ToString(Formatting.None), comment);
            }

            return(result);
        }
コード例 #3
0
ファイル: TestDataLoader.cs プロジェクト: xsustek/corert
        private static TheoryData <TestCase> GetTestMethodsFromDll(Func <string[], MethodDefinitionHandle, TestCase> methodSelector)
        {
            var retVal = new TheoryData <TestCase>();

            foreach (var testDllName in GetAllTestDlls())
            {
                var testModule = GetModuleForTestAssembly(testDllName);

                foreach (var methodHandle in testModule.MetadataReader.MethodDefinitions)
                {
                    var method     = (EcmaMethod)testModule.GetMethod(methodHandle);
                    var methodName = method.Name;

                    if (!String.IsNullOrEmpty(methodName) && methodName.Contains("_"))
                    {
                        var mparams             = methodName.Split('_');
                        var specialMethodHandle = HandleSpecialTests(mparams, method);
                        var newItem             = methodSelector(mparams, specialMethodHandle);

                        if (newItem != null)
                        {
                            newItem.TestName   = mparams[0];
                            newItem.MethodName = methodName;
                            newItem.ModuleName = testDllName;

                            retVal.Add(newItem);
                        }
                    }
                }
            }
            return(retVal);
        }
コード例 #4
0
ファイル: CommonTestHelper.cs プロジェクト: juergs/winforms
 // helper method to generate theory data from all values of an enum type
 internal static TheoryData<T> GetEnumTheoryData<T>() where T : Enum
 {
     var data = new TheoryData<T>();
     foreach (T item in Enum.GetValues(typeof(T)))
         data.Add(item);
     return data;
 }
コード例 #5
0
        public static TheoryData <DistributedCacheEntryOptions> PresetOptions()
        {
            var theoryData = new TheoryData <DistributedCacheEntryOptions>();

            theoryData.Add(new DistributedCacheEntryOptions {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30)
            });
            theoryData.Add(new DistributedCacheEntryOptions {
                SlidingExpiration = TimeSpan.FromMinutes(30)
            });
            theoryData.Add(new DistributedCacheEntryOptions {
                AbsoluteExpiration = DateTimeOffset.Now.AddDays(1)
            });

            return(theoryData);
        }
コード例 #6
0
        private static TheoryData <string, int, int> GenerateImageResizeData()
        {
            var result = new TheoryData <string, int, int>();

            string[] resamplerNames = typeof(KnownResamplers).GetProperties(BindingFlags.Public | BindingFlags.Static)
                                      .Select(p => p.Name)
                                      .Where(name => name != nameof(KnownResamplers.NearestNeighbor))
                                      .ToArray();

            int[] dimensionVals =
            {
                // Arbitrary, small dimensions:
                9,      10,   11,   13,   49,   50,   53,  99,  100,  199,  200,  201,  299,  300,  301,

                // Typical image sizes:
                640,   480,  800,  600, 1024,  768, 1280, 960, 1536, 1180, 1600, 1200, 2048, 1536, 2240, 1680, 2560,
                1920, 3032, 2008, 3072, 2304, 3264, 2448
            };

            IOrderedEnumerable <(int s, int d)> source2Dest = dimensionVals
                                                              .SelectMany(s => dimensionVals.Select(d => (s, d)))
                                                              .OrderBy(x => x.s + x.d);

            foreach (string resampler in resamplerNames)
            {
                foreach ((int s, int d)x in source2Dest)
                {
                    result.Add(resampler, x.s, x.d);
                }
            }

            return(result);
        }
コード例 #7
0
ファイル: PathTestData.cs プロジェクト: Aniel/Arilon
        public static TheoryData <INode[], IEdge[], IPath[]> SelfReferingNodes()
        {
            var data = new TheoryData <INode[], IEdge[], IPath[]>();

            var nStart = new Node("nStart", new List <string> {
                "e1"
            }, new List <string> {
                "e1", "e2"
            });
            var n1 = new Node("n1", new List <string> {
                "e2", "e3"
            }, new List <string> {
                "e3", "e4"
            });
            var nEnd = new Node("nEnd", new List <string> {
                "e4"
            });
            var e1 = new Edge("e1", "nStart", "nStart");
            var e2 = new Edge("e2", "nStart", "n1");
            var e3 = new Edge("e3", "n1", "n1");
            var e4 = new Edge("e4", "n1", "nEnd");

            data.Add(
                new INode[] { nStart, n1, nEnd },
                new IEdge[] { e1, e2, e3, e4 },
                new IPath[] { new Path(new IGraphObject[] { nStart, e2, n1, e4, nEnd }) }
                );

            return(data);
        }
コード例 #8
0
        public static TheoryData <ScanCompareType, float, float, byte[], ScanResult, bool, ScanResult> GetTestCompareWithPreviousData()
        {
            var data = new TheoryData <ScanCompareType, float, float, byte[], ScanResult, bool, ScanResult>
            {
                { ScanCompareType.Changed, 0.0f, 0.0f, BitConverter.GetBytes(0.0f), new FloatScanResult(1.0f), true, new FloatScanResult(0.0f) },
                { ScanCompareType.Changed, 0.0f, 0.0f, BitConverter.GetBytes(1.0f), new FloatScanResult(1.0f), false, null },
                { ScanCompareType.NotChanged, 0.0f, 0.0f, BitConverter.GetBytes(1.0f), new FloatScanResult(1.0f), true, new FloatScanResult(1.0f) },
                { ScanCompareType.NotChanged, 0.0f, 0.0f, BitConverter.GetBytes(0.0f), new FloatScanResult(1.0f), false, null },
                { ScanCompareType.Increased, 0.0f, 0.0f, BitConverter.GetBytes(2.0f), new FloatScanResult(1.0f), true, new FloatScanResult(2.0f) },
                { ScanCompareType.Increased, 0.0f, 0.0f, BitConverter.GetBytes(1.0f), new FloatScanResult(1.0f), false, null },
                { ScanCompareType.Increased, 0.0f, 0.0f, BitConverter.GetBytes(0.0f), new FloatScanResult(1.0f), false, null },
                { ScanCompareType.IncreasedOrEqual, 0.0f, 0.0f, BitConverter.GetBytes(2.0f), new FloatScanResult(1.0f), true, new FloatScanResult(2.0f) },
                { ScanCompareType.IncreasedOrEqual, 0.0f, 0.0f, BitConverter.GetBytes(1.0f), new FloatScanResult(1.0f), true, new FloatScanResult(1.0f) },
                { ScanCompareType.IncreasedOrEqual, 0.0f, 0.0f, BitConverter.GetBytes(0.0f), new FloatScanResult(1.0f), false, null },
                { ScanCompareType.Decreased, 0.0f, 0.0f, BitConverter.GetBytes(0.0f), new FloatScanResult(1.0f), true, new FloatScanResult(0.0f) },
                { ScanCompareType.Decreased, 0.0f, 0.0f, BitConverter.GetBytes(1.0f), new FloatScanResult(1.0f), false, null },
                { ScanCompareType.Decreased, 0.0f, 0.0f, BitConverter.GetBytes(2.0f), new FloatScanResult(1.0f), false, null },
                { ScanCompareType.DecreasedOrEqual, 0.0f, 0.0f, BitConverter.GetBytes(0.0f), new FloatScanResult(1.0f), true, new FloatScanResult(0.0f) },
                { ScanCompareType.DecreasedOrEqual, 0.0f, 0.0f, BitConverter.GetBytes(1.0f), new FloatScanResult(1.0f), true, new FloatScanResult(1.0f) },
                { ScanCompareType.DecreasedOrEqual, 0.0f, 0.0f, BitConverter.GetBytes(2.0f), new FloatScanResult(1.0f), false, null }
            };

            var basicData = GetTestCompareBasicData();

            foreach (var x in basicData)
            {
                data.Add((ScanCompareType)x[0], (float)x[1], (float)x[2], (byte[])x[3], new FloatScanResult(1.0f), (bool)x[4], (ScanResult)x[5]);
            }

            return(data);
        }
コード例 #9
0
        public static TheoryData <Enum> GetEnumTypeTheoryDataInvalidMasked(Type enumType)
        {
            var data = new TheoryData <Enum>();
            IEnumerable <Enum> values = Enum.GetValues(enumType).Cast <Enum>().OrderBy(p => p);

            long allMasked = 0;

            foreach (Enum value in values)
            {
                allMasked |= Convert.ToInt64(value);
            }

            data.Add((Enum)Enum.ToObject(enumType, int.MaxValue));
            data.Add((Enum)Enum.ToObject(enumType, allMasked + 1));
            return(data);
        }
コード例 #10
0
        public static TheoryData <string, IReadOnlyList <SubtitleTrackEvent> > Parse_MultipleDialogues_TestData()
        {
            var data = new TheoryData <string, IReadOnlyList <SubtitleTrackEvent> >();

            data.Add(
                @"[Events]
                Format: Layer, Start, End, Text
                Dialogue: ,0:00:01.18,0:00:01.85,dialogue1
                Dialogue: ,0:00:02.18,0:00:02.85,dialogue2
                Dialogue: ,0:00:03.18,0:00:03.85,dialogue3
                ",
                new List <SubtitleTrackEvent>
            {
                new SubtitleTrackEvent("1", "dialogue1")
                {
                    StartPositionTicks = 11800000,
                    EndPositionTicks   = 18500000
                },
                new SubtitleTrackEvent("2", "dialogue2")
                {
                    StartPositionTicks = 21800000,
                    EndPositionTicks   = 28500000
                },
                new SubtitleTrackEvent("3", "dialogue3")
                {
                    StartPositionTicks = 31800000,
                    EndPositionTicks   = 38500000
                }
            });

            return(data);
        }
コード例 #11
0
        private static TheoryData <TestCase> GetTestTypeFromDll(Func <string[], TypeDefinitionHandle, TestCase> typeSelector)
        {
            var retVal = new TheoryData <TestCase>();

            foreach (var testDllName in GetAllTestDlls())
            {
                EcmaModule     testModule     = GetModuleForTestAssembly(testDllName);
                MetadataReader metadataReader = testModule.PEReader.GetMetadataReader();
                foreach (TypeDefinitionHandle typeHandle in metadataReader.TypeDefinitions)
                {
                    var typeDef  = metadataReader.GetTypeDefinition(typeHandle);
                    var typeName = metadataReader.GetString(typeDef.Name);
                    if (!string.IsNullOrEmpty(typeName) && typeName.Contains("_"))
                    {
                        var      mparams = typeName.Split('_');
                        TestCase newItem = typeSelector(mparams, typeHandle);
                        if (newItem != null)
                        {
                            newItem.TestName   = mparams[0];
                            newItem.TypeName   = typeName;
                            newItem.ModuleName = testDllName;
                            retVal.Add(newItem);
                        }
                    }
                }
            }
            return(retVal);
        }
コード例 #12
0
ファイル: PathTestData.cs プロジェクト: Aniel/Arilon
        public static TheoryData <INode[], IEdge[], IPath[]> ShorterPath()
        {
            var data   = new TheoryData <INode[], IEdge[], IPath[]>();
            var nStart = new Node("nStart", null, new List <string> {
                "e1", "e3"
            });
            var n2 = new Node("n2", new List <string> {
                "e1"
            }, new List <string> {
                "e2"
            });
            var nEnd = new Node("nEnd", new List <string> {
                "e2", "e3"
            });

            var e1 = new Edge("e1", "nStart", "n2");
            var e2 = new Edge("e2", "n2", "nEnd");
            var e3 = new Edge("e3", "nStart", "nEnd");

            data.Add(
                new INode[] { nStart, n2, nEnd },
                new IEdge[] { e1, e2, e3 },
                new IPath[] { new Path(new IGraphObject[] { nStart, e3, nEnd }) });
            return(data);
        }
コード例 #13
0
        // helper method to generate theory data for some values of a int
        internal static TheoryData <float> GetFloatTheoryData()
        {
            var data = new TheoryData <float>();

            data.Add(float.MaxValue);
            data.Add(float.MinValue);
            data.Add(float.Epsilon);
            data.Add(float.Epsilon * -1);
            data.Add(float.NegativeInfinity); // not sure about these two
            data.Add(float.PositiveInfinity); // 2
            data.Add(0);
            data.Add(-1);
            data.Add(1);
            data.Add(float.MaxValue / 2);
            return(data);
        }
コード例 #14
0
        public static IEnumerable <object[]> Serialize_should_throw_when_effectiveGuidRepresentation_is_Unspecified_MemberData()
        {
            var data = new TheoryData <GuidRepresentationMode, GuidRepresentation, GuidRepresentation, GuidRepresentation?>();

            foreach (var defaultGuidRepresentationMode in EnumHelper.GetValues <GuidRepresentationMode>())
            {
                foreach (var defaultGuidRepresentation in EnumHelper.GetValues <GuidRepresentation>())
                {
                    if (defaultGuidRepresentationMode == GuidRepresentationMode.V3 && defaultGuidRepresentation != GuidRepresentation.Unspecified)
                    {
                        continue;
                    }

                    foreach (var serializerGuidRepresentation in EnumHelper.GetValues <GuidRepresentation>())
                    {
                        foreach (var writerGuidRepresentation in EnumHelper.GetValuesAndNull <GuidRepresentation>())
                        {
                            var effectiveGuidRepresentation = serializerGuidRepresentation;
                            if (defaultGuidRepresentationMode == GuidRepresentationMode.V2 && serializerGuidRepresentation == GuidRepresentation.Unspecified)
                            {
                                effectiveGuidRepresentation = writerGuidRepresentation ?? defaultGuidRepresentation;
                            }
                            if (effectiveGuidRepresentation != GuidRepresentation.Unspecified)
                            {
                                continue;
                            }

                            data.Add(defaultGuidRepresentationMode, defaultGuidRepresentation, serializerGuidRepresentation, writerGuidRepresentation);
                        }
                    }
                }
            }

            return(data);
        }
        private static void AddDecryptMismatchTheoryData(
            string testId,
            SymmetricSecurityKey decryptKey,
            SymmetricSecurityKey encryptkey,
            string decryptAlgorithm,
            string encryptAlgorithm,
            ExpectedException ee,
            TheoryData <AuthenticatedEncryptionTestParams> theoryData)
        {
            var authenticatedData = Guid.NewGuid().ToByteArray();
            var plainText         = Guid.NewGuid().ToByteArray();
            var provider          = new AuthenticatedEncryptionProvider(encryptkey, encryptAlgorithm);
            var results           = provider.Encrypt(plainText, authenticatedData);

            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                AuthenticatedData = authenticatedData,
                DecryptAlgorithm  = decryptAlgorithm,
                DecryptKey        = decryptKey,
                EE = ee,
                EncryptionResults = results,
                Provider          = new AuthenticatedEncryptionProvider(decryptKey, decryptAlgorithm),
                TestId            = testId
            });
        }
コード例 #16
0
        public static TheoryData <ScanCompareType, byte, byte, byte[], ScanResult, bool, ScanResult> GetTestCompareWithPreviousData()
        {
            var data = new TheoryData <ScanCompareType, byte, byte, byte[], ScanResult, bool, ScanResult>
            {
                { ScanCompareType.Changed, 0, 0, new byte[] { 0 }, new ByteScanResult(1), true, new ByteScanResult(0) },
                { ScanCompareType.Changed, 0, 0, new byte[] { 1 }, new ByteScanResult(1), false, null },
                { ScanCompareType.NotChanged, 0, 0, new byte[] { 1 }, new ByteScanResult(1), true, new ByteScanResult(1) },
                { ScanCompareType.NotChanged, 0, 0, new byte[] { 0 }, new ByteScanResult(1), false, null },
                { ScanCompareType.Increased, 0, 0, new byte[] { 2 }, new ByteScanResult(1), true, new ByteScanResult(2) },
                { ScanCompareType.Increased, 0, 0, new byte[] { 1 }, new ByteScanResult(1), false, null },
                { ScanCompareType.Increased, 0, 0, new byte[] { 0 }, new ByteScanResult(1), false, null },
                { ScanCompareType.IncreasedOrEqual, 0, 0, new byte[] { 2 }, new ByteScanResult(1), true, new ByteScanResult(2) },
                { ScanCompareType.IncreasedOrEqual, 0, 0, new byte[] { 1 }, new ByteScanResult(1), true, new ByteScanResult(1) },
                { ScanCompareType.IncreasedOrEqual, 0, 0, new byte[] { 0 }, new ByteScanResult(1), false, null },
                { ScanCompareType.Decreased, 0, 0, new byte[] { 0 }, new ByteScanResult(1), true, new ByteScanResult(0) },
                { ScanCompareType.Decreased, 0, 0, new byte[] { 1 }, new ByteScanResult(1), false, null },
                { ScanCompareType.Decreased, 0, 0, new byte[] { 2 }, new ByteScanResult(1), false, null },
                { ScanCompareType.DecreasedOrEqual, 0, 0, new byte[] { 0 }, new ByteScanResult(1), true, new ByteScanResult(0) },
                { ScanCompareType.DecreasedOrEqual, 0, 0, new byte[] { 1 }, new ByteScanResult(1), true, new ByteScanResult(1) },
                { ScanCompareType.DecreasedOrEqual, 0, 0, new byte[] { 2 }, new ByteScanResult(1), false, null }
            };

            var basicData = GetTestCompareBasicData();

            foreach (var x in basicData)
            {
                data.Add((ScanCompareType)x[0], (byte)x[1], (byte)x[2], (byte[])x[3], new ByteScanResult(1), (bool)x[4], (ScanResult)x[5]);
            }

            return(data);
        }
コード例 #17
0
        private static TheoryData <string, int, int> GenerateImageResizeData()
        {
            var result = new TheoryData <string, int, int>();

            string[] resamplerNames = TestUtils.GetAllResamplerNames(false);

            int[] dimensionVals =
            {
                // Arbitrary, small dimensions:
                9,      10,   11,   13,   49,   50,   53,  99,  100,  199,  200,  201,  299,  300,  301,

                // Typical image sizes:
                640,   480,  800,  600, 1024,  768, 1280, 960, 1536, 1180, 1600, 1200, 2048, 1536, 2240, 1680, 2560,
                1920, 3032, 2008, 3072, 2304, 3264, 2448
            };

            IOrderedEnumerable <(int s, int d)> source2Dest = dimensionVals
                                                              .SelectMany(s => dimensionVals.Select(d => (s, d)))
                                                              .OrderBy(x => x.s + x.d);

            foreach (string resampler in resamplerNames)
            {
                foreach ((int s, int d)x in source2Dest)
                {
                    result.Add(resampler, x.s, x.d);
                }
            }

            return(result);
        }
コード例 #18
0
        public static TheoryData <Test> GetTestSuite(string @case, string[] excludedStrings)
        {
            var testsDirectory = Path.GetRelativePath(Directory.GetCurrentDirectory(), $"SCION.SCXML/tests/{@case}");
            var excluded       = excludedStrings.Select(data =>
            {
                var splitted = data.Split(":", 2).ToArray();
                return(name: splitted[0], reason: splitted[1]);
            }).ToDictionary(e => e.name, e => e.reason);

            if (!Directory.Exists(testsDirectory))
            {
                throw new ArgumentException($"Could not find case: {@case} ({testsDirectory} does not exist)");
            }

            var testConfigurations = Directory.GetFiles(testsDirectory, "*.scxml")
                                     .Select(Path.GetFileName)
                                     .Select(name => name.Replace(".scxml", string.Empty))
                                     .Select(name => (name, path: Path.Join(testsDirectory, name)))
                                     .Select(test =>
                                             new Test(
                                                 test.name,
                                                 $"{test.path}.scxml",
                                                 File.ReadAllText($"{test.path}.json"),
                                                 excluded.ContainsKey(test.name) ? Option.From(excluded[test.name]) : Option.None <string>()));

            var theoryData = new TheoryData <Test>();

            foreach (var test in testConfigurations)
            {
                theoryData.Add(test);
            }

            return(theoryData);
        }
コード例 #19
0
        public static TheoryData <string, SecurityKey, bool> HasPrivateKeyTheoryData()
        {
            var theoryData = new TheoryData <string, SecurityKey, bool>();

#if NET452 || NET461
            theoryData.Add(
                "KeyingMaterial.RsaSecurityKeyWithCspProvider_2048",
                KeyingMaterial.RsaSecurityKeyWithCspProvider_2048,
                true
                );

            theoryData.Add(
                "KeyingMaterial.RsaSecurityKeyWithCspProvider_2048_Public",
                KeyingMaterial.RsaSecurityKeyWithCspProvider_2048_Public,
                false
                );
#endif
#if NET461
            theoryData.Add(
                "KeyingMaterial.RsaSecurityKeyWithCngProvider_2048",
                KeyingMaterial.RsaSecurityKeyWithCngProvider_2048,
                true
                );

            theoryData.Add(
                "KeyingMaterial.RsaSecurityKeyWithCngProvider_2048_Public",
                KeyingMaterial.RsaSecurityKeyWithCngProvider_2048_Public,
                false
                );
#endif

            theoryData.Add(
                "KeyingMaterial.RsaSecurityKey_2048",
                KeyingMaterial.RsaSecurityKey_2048,
                true
                );

            theoryData.Add(
                "KeyingMaterial.RsaSecurityKey_2048_Public",
                KeyingMaterial.RsaSecurityKey_2048_Public,
                false
                );

            theoryData.Add(
                "KeyingMaterial.RsaSecurityKey_2048_FromRsa",
                KeyingMaterial.RsaSecurityKey_2048_FromRsa,
                true
                );

            theoryData.Add(
                "KeyingMaterial.RsaSecurityKey_2048_FromRsa_Public",
                KeyingMaterial.RsaSecurityKey_2048_FromRsa_Public,
                false
                );

            return(theoryData);
        }
コード例 #20
0
        public static TheoryData <IEnumerable <T> > EnumerableData()
        {
            var data = new TheoryData <IEnumerable <T> >();

            IEnumerable <int> counts = CountData().Select(array => array[0]).Cast <int>();

            foreach (int count in counts)
            {
                data.Add(Enumerable.Repeat(default(T), count));

                // Test perf: Capture the items into a List here so we
                // only enumerate the sequence once.
                data.Add(s_generator.GenerateEnumerable(count).ToList());
            }

            return(data);
        }
コード例 #21
0
        public static TheoryData <int> CapacityData()
        {
            var data = new TheoryData <int>();

            for (int i = 0; i < 6; i++)
            {
                int powerOfTwo = 1 << i;

                // Return numbers of the form 2^N - 1, 2^N and 2^N + 1
                // This should cover most of the interesting cases
                data.Add(powerOfTwo - 1);
                data.Add(powerOfTwo);
                data.Add(powerOfTwo + 1);
            }

            return(data);
        }
コード例 #22
0
        public static TheoryData <Size> GetSizeTheoryData(TestIncludeType includeType)
        {
            var data = new TheoryData <Size>();

            if (!includeType.HasFlag(TestIncludeType.NoPositives))
            {
                data.Add(new Size());
                data.Add(new Size(new Point(1, 1)));
                data.Add(new Size(1, 2));
            }
            if (!includeType.HasFlag(TestIncludeType.NoNegatives))
            {
                data.Add(new Size(-1, 1));
                data.Add(new Size(1, -1));
            }
            return(data);
        }
        public static TheoryData <AuthenticatedEncryptionTestParams> IsSupportedAlgorithmTheoryData()
        {
            var theoryData = new TheoryData <AuthenticatedEncryptionTestParams>();

            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                DecryptAlgorithm = SecurityAlgorithms.Aes128CbcHmacSha256,
                DecryptKey       = null,
                EE = ExpectedException.NoExceptionExpected,
                IsSupportedAlgorithm = false,
                Provider             = new DerivedAuthenticatedEncryptionProvider(Default.SymmetricEncryptionKey256, SecurityAlgorithms.Aes128CbcHmacSha256),
                TestId = "Test1"
            });

            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                DecryptAlgorithm = SecurityAlgorithms.Aes128CbcHmacSha256,
                DecryptKey       = null,
                EE = ExpectedException.NoExceptionExpected,
                IsSupportedAlgorithm = false,
                Provider             = new DerivedAuthenticatedEncryptionProvider(Default.SymmetricEncryptionKey256, SecurityAlgorithms.Aes128CbcHmacSha256),
                TestId = "Test2"
            });

            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                DecryptAlgorithm = SecurityAlgorithms.Aes128Encryption,
                DecryptKey       = Default.SymmetricEncryptionKey256,
                EE = ExpectedException.NoExceptionExpected,
                IsSupportedAlgorithm = false,
                Provider             = new DerivedAuthenticatedEncryptionProvider(Default.SymmetricEncryptionKey256, SecurityAlgorithms.Aes128CbcHmacSha256),
                TestId = "Test3"
            });

            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                DecryptAlgorithm = SecurityAlgorithms.Aes128CbcHmacSha256,
                DecryptKey       = Default.AsymmetricSigningKey,
                EE = ExpectedException.NoExceptionExpected,
                IsSupportedAlgorithm = false,
                Provider             = new DerivedAuthenticatedEncryptionProvider(Default.SymmetricEncryptionKey256, SecurityAlgorithms.Aes128CbcHmacSha256),
                TestId = "Test4"
            });

            return(theoryData);
        }
コード例 #24
0
        public static TheoryData <Point> GetPointTheoryData(TestIncludeType includeType)
        {
            var data = new TheoryData <Point>();

            if (!includeType.HasFlag(TestIncludeType.NoPositives))
            {
                data.Add(new Point());
                data.Add(new Point(10));
                data.Add(new Point(1, 2));
            }
            if (!includeType.HasFlag(TestIncludeType.NoNegatives))
            {
                data.Add(new Point(int.MaxValue, int.MinValue));
                data.Add(new Point(-1, -2));
            }
            return(data);
        }
コード例 #25
0
ファイル: CommonTestHelper.cs プロジェクト: juergs/winforms
 public static TheoryData GetEnumTypeTheoryData(Type enumType)
 {
     var data = new TheoryData<Enum>();
     foreach (Enum item in Enum.GetValues(enumType))
     {
         data.Add(item);
     }
     return data;
 }
コード例 #26
0
        private static TheoryData <string, Dictionary <string, string> > GetParts_ValidAuthHeader_Success_Data()
        {
            var data = new TheoryData <string, Dictionary <string, string> >();

            data.Add(
                "x=\"123,123\",y=\"123\"",
                new Dictionary <string, string>
            {
                { "x", "123,123" },
                { "y", "123" }
            });

            data.Add(
                "x=\"123,123\",         y=\"123\",z=\"'hi'\"",
                new Dictionary <string, string>
            {
                { "x", "123,123" },
                { "y", "123" },
                { "z", "'hi'" }
            });

            data.Add(
                "x=\"ab\"",
                new Dictionary <string, string>
            {
                { "x", "ab" }
            });

            data.Add(
                "param=Hörbücher",
                new Dictionary <string, string>
            {
                { "param", "Hörbücher" }
            });

            data.Add(
                "param=%22%Hörbücher",
                new Dictionary <string, string>
            {
                { "param", "\"%Hörbücher" }
            });

            return(data);
        }
コード例 #27
0
        public static TheoryData <string, SecurityTokenDescriptor, TokenValidationParameters, ExpectedException> RoundTripJWEParams()
        {
            var theoryData = new TheoryData <string, SecurityTokenDescriptor, TokenValidationParameters, ExpectedException>();

            theoryData.Add(
                "Test1",
                Default.SymmetricEncryptSignSecurityTokenDescriptor(),
                Default.SymmetricEncyptSignTokenValidationParameters,
                ExpectedException.NoExceptionExpected
                );

            theoryData.Add(
                "Test2",
                Default.SecurityTokenDescriptor(Default.SymmetricEncryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(Default.SymmetricEncryptionKey256, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            // signing key not found
            theoryData.Add(
                "Test3",
                Default.SymmetricEncryptSignSecurityTokenDescriptor(),
                new TokenValidationParameters
            {
                IssuerSigningKey   = NotDefault.SymmetricSigningKey256,
                TokenDecryptionKey = Default.SymmetricEncryptionKey256,
            },
                ExpectedException.SecurityTokenSignatureKeyNotFoundException("IDX10501:")
                );

            // encryption key not found
            theoryData.Add(
                "Test4",
                Default.SymmetricEncryptSignSecurityTokenDescriptor(),
                new TokenValidationParameters
            {
                IssuerSigningKey   = Default.SymmetricSigningKey256,
                TokenDecryptionKey = NotDefault.SymmetricEncryptionKey,
            },
                ExpectedException.SecurityTokenDecryptionFailedException("IDX10609:")
                );

            return(theoryData);
        }
コード例 #28
0
        private static TheoryData <int, BinaryOperatorKind> Build_RightCount_Diagnostic_TheoryData()
        {
            var theoryData = new TheoryData <int, BinaryOperatorKind>();

            foreach (var fixerData in RightCount_Fixer_TheoryData)
            {
                theoryData.Add((int)fixerData[0], (BinaryOperatorKind)fixerData[1]);
            }
            return(theoryData);
        }
コード例 #29
0
        private static TheoryData <BinaryOperatorKind, int> Build_LeftCount_Diagnostic_TheoryData()
        {
            var theoryData = new TheoryData <BinaryOperatorKind, int>();

            foreach (var fixerData in LeftCount_Fixer_TheoryData)
            {
                theoryData.Add((BinaryOperatorKind)fixerData[0], (int)fixerData[1]);
            }
            return(theoryData);
        }
コード例 #30
0
        public static TheoryData <Type> GetIsNotSimpleTheories()
        {
            var result = new TheoryData <Type>();

            foreach (var type in GetNoneSimpleTypes())
            {
                result.Add(type);
            }
            return(result);
        }
コード例 #31
0
        public static TheoryData<KeyValuePair<string, string[]>> CreditCards()
        {
            var json = File.ReadAllText("Data\\ValidCards.json");
            var creditCards = JsonConvert.DeserializeObject<Dictionary<string, string[]>>(json);

            var data = new TheoryData<KeyValuePair<string, string[]>>();
            foreach (var item in creditCards)
            {
                data.Add(item);
            }

            return data;
        }
コード例 #32
0
        private static TheoryData<string, string[]> GetInvalidNameOrPrefixData(
            Func<string, string, string> onNameError,
            string whitespaceErrorString,
            Func<string, string> onDataError)
        {
            // name, expectedErrorMessages
            var data = new TheoryData<string, string[]>
            {
                { "!", new[] {  onNameError("!", "!") } },
                { "hello!", new[] { onNameError("hello!", "!") } },
                { "!hello", new[] { onNameError("!hello", "!") } },
                { "he!lo", new[] { onNameError("he!lo", "!") } },
                {
                    "!he!lo!",
                    new[]
                    {
                        onNameError("!he!lo!", "!"),
                        onNameError("!he!lo!", "!"),
                        onNameError("!he!lo!", "!"),
                    }
                },
                { "@", new[] { onNameError("@", "@") } },
                { "hello@", new[] { onNameError("hello@", "@") } },
                { "@hello", new[] { onNameError("@hello", "@") } },
                { "he@lo", new[] { onNameError("he@lo", "@") } },
                {
                    "@he@lo@",
                    new[]
                    {
                        onNameError("@he@lo@", "@"),
                        onNameError("@he@lo@", "@"),
                        onNameError("@he@lo@", "@"),
                    }
                },
                { "/", new[] { onNameError("/", "/") } },
                { "hello/", new[] { onNameError("hello/", "/") } },
                { "/hello", new[] { onNameError("/hello", "/") } },
                { "he/lo", new[] { onNameError("he/lo", "/") } },
                {
                    "/he/lo/",
                    new[]
                    {
                        onNameError("/he/lo/", "/"),
                        onNameError("/he/lo/", "/"),
                        onNameError("/he/lo/", "/"),
                    }
                },
                { "<", new[] { onNameError("<", "<") } },
                { "hello<", new[] { onNameError("hello<", "<") } },
                { "<hello", new[] { onNameError("<hello", "<") } },
                { "he<lo", new[] { onNameError("he<lo", "<") } },
                {
                    "<he<lo<",
                    new[]
                    {
                        onNameError("<he<lo<", "<"),
                        onNameError("<he<lo<", "<"),
                        onNameError("<he<lo<", "<"),
                    }
                },
                { "?", new[] { onNameError("?", "?") } },
                { "hello?", new[] { onNameError("hello?", "?") } },
                { "?hello", new[] { onNameError("?hello", "?") } },
                { "he?lo", new[] { onNameError("he?lo", "?") } },
                {
                    "?he?lo?",
                    new[]
                    {
                        onNameError("?he?lo?", "?"),
                        onNameError("?he?lo?", "?"),
                        onNameError("?he?lo?", "?"),
                    }
                },
                { "[", new[] { onNameError("[", "[") } },
                { "hello[", new[] { onNameError("hello[", "[") } },
                { "[hello", new[] { onNameError("[hello", "[") } },
                { "he[lo", new[] { onNameError("he[lo", "[") } },
                {
                    "[he[lo[",
                    new[]
                    {
                        onNameError("[he[lo[", "["),
                        onNameError("[he[lo[", "["),
                        onNameError("[he[lo[", "["),
                    }
                },
                { ">", new[] { onNameError(">", ">") } },
                { "hello>", new[] { onNameError("hello>", ">") } },
                { ">hello", new[] { onNameError(">hello", ">") } },
                { "he>lo", new[] { onNameError("he>lo", ">") } },
                {
                    ">he>lo>",
                    new[]
                    {
                        onNameError(">he>lo>", ">"),
                        onNameError(">he>lo>", ">"),
                        onNameError(">he>lo>", ">"),
                    }
                },
                { "]", new[] { onNameError("]", "]") } },
                { "hello]", new[] { onNameError("hello]", "]") } },
                { "]hello", new[] { onNameError("]hello", "]") } },
                { "he]lo", new[] { onNameError("he]lo", "]") } },
                {
                    "]he]lo]",
                    new[]
                    {
                        onNameError("]he]lo]", "]"),
                        onNameError("]he]lo]", "]"),
                        onNameError("]he]lo]", "]"),
                    }
                },
                { "=", new[] { onNameError("=", "=") } },
                { "hello=", new[] { onNameError("hello=", "=") } },
                { "=hello", new[] { onNameError("=hello", "=") } },
                { "he=lo", new[] { onNameError("he=lo", "=") } },
                {
                    "=he=lo=",
                    new[]
                    {
                        onNameError("=he=lo=", "="),
                        onNameError("=he=lo=", "="),
                        onNameError("=he=lo=", "="),
                    }
                },
                { "\"", new[] { onNameError("\"", "\"") } },
                { "hello\"", new[] { onNameError("hello\"", "\"") } },
                { "\"hello", new[] { onNameError("\"hello", "\"") } },
                { "he\"lo", new[] { onNameError("he\"lo", "\"") } },
                {
                    "\"he\"lo\"",
                    new[]
                    {
                        onNameError("\"he\"lo\"", "\""),
                        onNameError("\"he\"lo\"", "\""),
                        onNameError("\"he\"lo\"", "\""),
                    }
                },
                { "'", new[] { onNameError("'", "'") } },
                { "hello'", new[] { onNameError("hello'", "'") } },
                { "'hello", new[] { onNameError("'hello", "'") } },
                { "he'lo", new[] { onNameError("he'lo", "'") } },
                {
                    "'he'lo'",
                    new[]
                    {
                        onNameError("'he'lo'", "'"),
                        onNameError("'he'lo'", "'"),
                        onNameError("'he'lo'", "'"),
                    }
                },
                { "hello*", new[] { onNameError("hello*", "*") } },
                { "*hello", new[] { onNameError("*hello", "*") } },
                { "he*lo", new[] { onNameError("he*lo", "*") } },
                {
                    "*he*lo*",
                    new[]
                    {
                        onNameError("*he*lo*", "*"),
                        onNameError("*he*lo*", "*"),
                        onNameError("*he*lo*", "*"),
                    }
                },
                { Environment.NewLine, new[] { whitespaceErrorString } },
                { "\t", new[] { whitespaceErrorString } },
                { " \t ", new[] { whitespaceErrorString } },
                { " ", new[] { whitespaceErrorString } },
                { Environment.NewLine + " ", new[] { whitespaceErrorString } },
                {
                    "! \t\r\n@/<>?[]=\"'*",
                    new[]
                    {
                        onNameError("! \t\r\n@/<>?[]=\"'*", "!"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", " "),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "\t"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "\r"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "\n"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "@"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "/"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "<"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", ">"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "?"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "["),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "]"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "="),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "\""),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "'"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "*"),
                    }
                },
                {
                    "! \tv\ra\nl@i/d<>?[]=\"'*",
                    new[]
                    {
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "!"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", " "),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "\t"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "\r"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "\n"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "@"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "/"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "<"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", ">"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "?"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "["),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "]"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "="),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "\""),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "'"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "*"),
                    }
                },
            };

            if (onDataError != null)
            {
                data.Add("data-", new[] { onDataError("data-") });
                data.Add("data-something", new[] { onDataError("data-something") });
                data.Add("Data-Something", new[] { onDataError("Data-Something") });
                data.Add("DATA-SOMETHING", new[] { onDataError("DATA-SOMETHING") });
            }

            return data;
        }
コード例 #33
0
        public static TheoryData<KeyValuePair<string, string[]>> CreditCards(CardIssuer cardIssuer)
        {
            var theoryData = new TheoryData<KeyValuePair<string, string[]>>();
            foreach (var creditCard in CreditCards()
                .SelectMany(item => item.Cast<KeyValuePair<string, string[]>>())
                .Where(x => x.Key.Equals(cardIssuer.ToString(), StringComparison.OrdinalIgnoreCase)))
            {
                theoryData.Add(creditCard);
            }

            return theoryData;
        }