public void Validate_ConfigurationIsNull_ThrowsException()
 {
     ExceptionAssert.ThrowsArgumentNullException("configuration", () =>
     {
         KassaConfigurationValidator.Validate(null);
     });
 }
        public void Validate_IsValid_NoException()
        {
            KassaConfiguration configuration = new KassaConfiguration()
            {
                KeyVersion = 1,
                MerchantId = "123456789012345",
                SecretKey  = "secret",
                Url        = new Uri("https://www.github.com")
            };

            KassaConfigurationValidator.Validate(configuration);
        }
        public void Validate_MerchantIdIsWhitespace_ThrowsException()
        {
            KassaConfiguration configuration = new KassaConfiguration()
            {
                KeyVersion = 1,
                MerchantId = "   ",
                SecretKey  = "secret",
                Url        = new Uri("https://www.github.com")
            };

            ExceptionAssert.ThrowsWhitespaceValidationException(nameof(configuration.MerchantId), () =>
            {
                KassaConfigurationValidator.Validate(configuration);
            });
        }
        public void Validate_KeyVersionLessThan1_ThrowsException()
        {
            KassaConfiguration configuration = new KassaConfiguration()
            {
                KeyVersion = 0,
                MerchantId = "merchant",
                SecretKey  = "secret",
                Url        = new Uri("https://www.github.com")
            };

            ExceptionAssert.ThrowsHigherThanValidationException(nameof(configuration.KeyVersion), 0, () =>
            {
                KassaConfigurationValidator.Validate(configuration);
            });
        }
        public void Validate_UrlContainsSeparator_ThrowsException()
        {
            KassaConfiguration configuration = new KassaConfiguration()
            {
                KeyVersion = 1,
                MerchantId = "merchant",
                SecretKey  = "secret",
                Url        = new Uri("https://github.com/?a=|")
            };

            ExceptionAssert.ThrowsSeparatorValidationException(nameof(configuration.Url), () =>
            {
                KassaConfigurationValidator.Validate(configuration);
            });
        }
        public void Validate_UrlIsNull_ThrowsException()
        {
            KassaConfiguration configuration = new KassaConfiguration()
            {
                KeyVersion = 1,
                MerchantId = "merchant",
                SecretKey  = "secret",
                Url        = null
            };

            ExceptionAssert.ThrowsNullValidationException(nameof(configuration.Url), () =>
            {
                KassaConfigurationValidator.Validate(configuration);
            });
        }
        public void Validate_SecretKeyIsEmpty_ThrowsException()
        {
            KassaConfiguration configuration = new KassaConfiguration()
            {
                KeyVersion = 1,
                MerchantId = "merchant",
                SecretKey  = string.Empty,
                Url        = new Uri("https://www.github.com")
            };

            ExceptionAssert.ThrowsEmptyValidationException(nameof(configuration.SecretKey), () =>
            {
                KassaConfigurationValidator.Validate(configuration);
            });
        }
        public void Validate_MerchantIdHasNonAlphanumericCharacter_ThrowsException()
        {
            KassaConfiguration configuration = new KassaConfiguration()
            {
                KeyVersion = 1,
                MerchantId = "%",
                SecretKey  = "secret",
                Url        = new Uri("https://www.github.com")
            };

            ExceptionAssert.ThrowsAlphanumericValidationException(nameof(configuration.MerchantId), () =>
            {
                KassaConfigurationValidator.Validate(configuration);
            });
        }
        public void Validate_MerchantIdIsLongerThanMaxLength_ThrowsException()
        {
            KassaConfiguration configuration = new KassaConfiguration()
            {
                KeyVersion = 1,
                MerchantId = "1234567890123456",
                SecretKey  = "secret",
                Url        = new Uri("https://www.github.com")
            };

            ExceptionAssert.ThrowsLengthValidationException(nameof(configuration.MerchantId), 15, () =>
            {
                KassaConfigurationValidator.Validate(configuration);
            });
        }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Kassa"/> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public Kassa(IKassaConfiguration configuration)
        {
            KassaConfigurationValidator.Validate(configuration);

            Configuration = configuration;
        }