public void ConfigurationRequirement_SecureString_Succeeds()
        {
            const string name        = "ConfigurationRequirementName";
            const string description = "Configuration requirement description.";
            const long   badInput    = 8675309L;
            SecureString goodInput   = "Hello world".ToSecureString();

            AssertUtil.Compare(
                name,
                description,
                ConfigurationRequirementType.SecureString,
                () => ConfigurationRequirement.SecureString(name, description),
                badInput,
                goodInput);
        }
Esempio n. 2
0
        static DemoFactory()
        {
            // [~2]. Create the requirements. For the demo, these are just examples.
            DemoFactory.Website = ConfigurationRequirement.Uri(
                "Website",
                "The website to use for the demo.");
            DemoFactory.Username = ConfigurationRequirement.String(
                "Username",
                "The username to use for the demo.");
            DemoFactory.Password = ConfigurationRequirement.SecureString(
                "Password",
                "The password to use for the demo.",
                dependsOn: new IConfigurationRequirement[]
            {
                DemoFactory.Website,
                DemoFactory.Username
            },
                additionalValidation: (x, y, z) =>
            {
                if (!z.TryGetOrDefault(DemoFactory.Website, () => null, out Uri website))
                {
                    return(new InvalidOperationException("Missing website."));
                }

                if (!z.TryGetOrDefault(DemoFactory.Username, () => null, out string username))
                {
                    return(new InvalidOperationException("Missing username."));
                }

                Console.WriteLine();
                Console.WriteLine("Additional validation callback for password.");
                Console.WriteLine("Press enter to continue. Non-empty inputs will intentionally fail validation.");
                string input = Console.ReadLine();
                if (input.Length != 0)
                {
                    return(new InvalidOperationException(input));
                }

                return(null);
            });

            DemoFactory.BackingRequirements = new IConfigurationRequirement[]
            {
                DemoFactory.Website,
                DemoFactory.Username,
                DemoFactory.Password
            };
        }
        public void ConfigurationRequirement_SecureString_PropagatesInfo()
        {
            const string name        = "ConfigurationRequirementName";
            const string description = "Configuration requirement description.";
            const bool   isOptional  = true;
            const long   badInput    = 8675309L;

            SecureString[] goodInput =
                new SecureString[]
            {
                "Hello world".ToSecureString()
            };
            CollectionInfo collectionInfo = new CollectionInfo(1, 4);

            IEnumerable <IConfigurationRequirement> dependsOn =
                TestUtil.CreateIConfigurationRequirementCollection(3);
            IEnumerable <IConfigurationRequirement> exclusiveWith =
                TestUtil.CreateIConfigurationRequirementCollection(3);

            AssertUtil.Compare(
                name,
                description,
                ConfigurationRequirementType.SecureString,
                isOptional,
                collectionInfo,
                dependsOn,
                exclusiveWith,
                () => ConfigurationRequirement.SecureString(
                    name,
                    description,
                    isOptional,
                    collectionInfo,
                    dependsOn,
                    exclusiveWith),
                badInput,
                goodInput);
        }