Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Build project
run: dotnet build
- name: Run unit tests
run: dotnet test --logger "console;verbosity=detailed"
run: dotnet test --logger "console;verbosity=detailed" -graphBuild:True
- name: Code Coverage Report
uses: irongut/[email protected]
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Cosmos.DataTransfer.Core.UnitTests
[TestClass]
public class SettingsCommandTests
{
// TODO: What is the purpose of this test?
// It seems to be a very elaborate method to assert parsing null.
[TestMethod]
public void Invoke_ForTestExtension_ProducesValidSettingsJson()
{
Expand Down Expand Up @@ -65,8 +67,10 @@ public void Invoke_ForTestExtension_ProducesValidSettingsJson()
WriteIndented = true
};
var fullJson = stringBuilder.ToString().Trim();
Assert.AreEqual("null", fullJson);
var parsed = JsonSerializer.Deserialize<List<ExtensionSettingProperty>>(fullJson, options);
var parsedJson = JsonSerializer.Serialize<List<ExtensionSettingProperty>>(parsed, options);
Assert.IsNull(parsed);
var parsedJson = JsonSerializer.Serialize<List<ExtensionSettingProperty>>(parsed!, options);

Assert.AreEqual(fullJson, parsedJson);
}
Expand Down
5 changes: 4 additions & 1 deletion Extensions/PostgreSQL/PostgreDataCol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ public PostgreDataCol(string colname, string postgredatatye)
ColumnType = Convert(PostgreType);
}

public PostgreDataCol()
public PostgreDataCol(string colname, Type coltype, NpgsqlTypes.NpgsqlDbType postgredatatye)
{
ColumnName = colname;
PostgreType = postgredatatye;
ColumnType = coltype;
}

public Dictionary<long, object> SparseColumnData { get; } = new Dictionary<long, object>();
Expand Down
11 changes: 3 additions & 8 deletions Extensions/PostgreSQL/PostgresqlDataSinkExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private async Task<List<PostgreDataCol>> FindPostgreDataTypes(IAsyncEnumerable<I
{
if (current.PostgreType == NpgsqlTypes.NpgsqlDbType.Unknown && coltype?.Name != "Missing")
{
var newcol = new PostgreDataCol(col, coltype);
var newcol = new PostgreDataCol(col, coltype!);
postgreDataCols[row] = newcol;
}
}
Expand All @@ -106,12 +106,7 @@ private List<PostgreDataCol> MapDataTypes(List<PostgreDataCol> dest, List<Postgr
{
if (item.ColumnName.ToLower() == col.ColumnName.ToLower())
{
temp.Add(new PostgreDataCol()
{
ColumnName = col.ColumnName,
ColumnType = item.ColumnType,
PostgreType = item.PostgreType
});
temp.Add(new PostgreDataCol(col.ColumnName, item.ColumnType, item.PostgreType));
found = true;
break;
}
Expand Down Expand Up @@ -169,7 +164,7 @@ private static List<PostgreDataCol> LoadTableSchema(NpgsqlConnection con, string
{
if (row != null)
{
var newcol = new PostgreDataCol(row["column_name"]?.ToString(), row["udt_name"]?.ToString());
var newcol = new PostgreDataCol(row["column_name"]?.ToString()!, row["udt_name"]?.ToString()!);
temp.Add(newcol);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Extensions/PostgreSQL/Settings/PostgreSinkSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace Cosmos.DataTransfer.PostgresqlExtension.Settings
public class PostgreSinkSettings : PostgreBaseSettings
{
[Required]
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
public string TableName { get; set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
public bool? AppendDataToTable { get; set; }
public bool? DropAndCreateTable { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion Extensions/PostgreSQL/Settings/PostgreSourceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class PostgreSourceSettings:PostgreBaseSettings
{
[Required]
[SensitiveValue]
public string? ConnectionString { get; set; }
public new string? ConnectionString { get; set; }

[Required]
public string? QueryText { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Cosmos.DataTransfer.Interfaces;

public static class ValidationExtensions
{
public static IEnumerable<string?> GetValidationErrors<T>(this T? settings)
public static IEnumerable<string> GetValidationErrors<T>(this T? settings)
where T : class, IDataExtensionSettings, new()
{
if (settings == null)
Expand All @@ -18,7 +18,10 @@ public static class ValidationExtensions
Validator.TryValidateObject(settings, context, results, true);
foreach (var validationResult in results)
{
yield return validationResult.ErrorMessage;
if (validationResult.ErrorMessage is not null)
{
yield return validationResult.ErrorMessage;
}
}
}

Expand Down
Loading