using System;
using System.Collections.Generic;
using DotNetty.Common;
namespace NucuCar.Domain.Services
{
///
/// ConnectionStringParser is an utility service to parse and validate connection strings.
///
public static class ConnectionStringParser
{
///
/// Parse parses and validates a provided connection string.
///
/// The connection string to parse
/// A dictionary object containing the values of the connection string.
///
public static Dictionary Parse(string connectionString)
{
// TODO: Write tests for this.
var items = connectionString.Split(";");
var parsedConnectionString = new Dictionary();
foreach (var item in items)
{
var keyValue = item.Split("=");
if (keyValue.Length != 2)
{
throw new ArgumentException(
$"Invalid argument for connection string, expected KEY=VALUE got {item}");
}
parsedConnectionString[keyValue[0]] = parsedConnectionString[keyValue[1]];
}
return parsedConnectionString;
}
}
}