Galen.CI.Azure.Sql.Sharding.App.Arguments.AddRangeMapShardArgs.Validate C# (CSharp) Method

Validate() public method

public Validate ( ) : void
return void
        public void Validate()
        {
            if (string.IsNullOrWhiteSpace(ConnectionString))
            {
                throw new ValidationArgException("Connection string is required for adding a range map shard.");
            }

            if (string.IsNullOrWhiteSpace(MapName))
            {
                throw new ValidationArgException("Map name is required for adding a range map shard.");
            }

            if (ShardKeyRange == null)
            {
                throw new ValidationArgException("Shard key range was not provided, is invalid, or is in an incorrect format.");
            }

            if (ShardKeyRange.KeyType == null)
            {
                throw new ValidationArgException("Shard key range type was not provided, is invalid, or could not be parsed.");
            }

            if (ShardKeyRange.LowValue == null)
            {
                throw new ValidationArgException("Shard key range low value was not provided, is invalid, or could not be parsed.");
            }

            if (ShardKeyRange.HighValue == null)
            {
                throw new ValidationArgException("Shard key range high value was not provided, is invalid, or could not be parsed.");
            }

            if (string.IsNullOrWhiteSpace(ShardServerName))
            {
                throw new ValidationArgException("Shard server name is required for adding a range map shard.");
            }

            if (string.IsNullOrWhiteSpace(ShardDatabaseName))
            {
                throw new ValidationArgException("Shard database name is required for adding a range map shard.");
            }

            var highValueComparable = (IComparable)ShardKeyRange.HighValue;
            var isHighValueLargerThanLowValue = (highValueComparable.CompareTo(ShardKeyRange.LowValue) > 0);
            if (!isHighValueLargerThanLowValue)
            {
                throw new ValidationArgException($"Shard key range low value {ShardKeyRange.LowValue} is greater than high value {ShardKeyRange.HighValue}.");
            }
        }
    }

Usage Example

        public void CorrectlyAcceptsValidArguments()
        {
            var sut = new AddRangeMapShardArgs
            {
                ConnectionString = @"Server = (localdb)\mssqllocaldb; Initial Catalog = SomeTestDb; Integrated Security = true; Application Name = Galen.CI.Azure.Sql.Sharding.App.Tests; ",
                MapName = "MyTestListMapName",
                ShardServerName = "TestShard001",
                ShardDatabaseName = "MyShardedDatabase",
                ShardKeyRange = new ShardKeyRange(typeof (int), lowValue: 2000, highValue: 3000)
            };

            sut.Validate();     // should not throw exception
        }
All Usage Examples Of Galen.CI.Azure.Sql.Sharding.App.Arguments.AddRangeMapShardArgs::Validate
AddRangeMapShardArgs