Skip to content

Commit

Permalink
fix: fix the "Non-nullable" warnings for QaseExporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel.butuzov committed Jan 10, 2025
1 parent b8467ab commit 5bc0713
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 77 deletions.
12 changes: 6 additions & 6 deletions Migrators/QaseExporter/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task<QaseProject> GetProject()
}

var content = await response.Content.ReadAsStringAsync();
var projectData = JsonSerializer.Deserialize<QaseProjectData>(content);
var projectData = JsonSerializer.Deserialize<QaseProjectData>(content)!;

_logger.LogDebug("Found project {@Project}", projectData.Project);

Expand Down Expand Up @@ -85,7 +85,7 @@ public async Task<List<QaseSuite>> GetSuites()
}

var content = await response.Content.ReadAsStringAsync();
var suitesData = JsonSerializer.Deserialize<QaseSuitesData>(content);
var suitesData = JsonSerializer.Deserialize<QaseSuitesData>(content)!;

if (suitesData.SuitesData.Count > 0)
{
Expand Down Expand Up @@ -130,7 +130,7 @@ public async Task<List<QaseTestCase>> GetTestCasesBySuiteId(int suiteId)
}

var content = await response.Content.ReadAsStringAsync();
var qaseCasesData = JsonSerializer.Deserialize<QaseCasesData>(content);
var qaseCasesData = JsonSerializer.Deserialize<QaseCasesData>(content)!;

if (qaseCasesData.CasesData.Count > 0)
{
Expand Down Expand Up @@ -175,7 +175,7 @@ public async Task<List<QaseSharedStep>> GetSharedSteps()
}

var content = await response.Content.ReadAsStringAsync();
var sharedStepData = JsonSerializer.Deserialize<SharedStepData>(content);
var sharedStepData = JsonSerializer.Deserialize<SharedStepData>(content)!;

if (sharedStepData.SharedStepsData.Count > 0)
{
Expand Down Expand Up @@ -220,7 +220,7 @@ public async Task<List<QaseCustomField>> GetCustomFields()
}

var content = await response.Content.ReadAsStringAsync();
var fieldsData = JsonSerializer.Deserialize<QaseFieldsData>(content);
var fieldsData = JsonSerializer.Deserialize<QaseFieldsData>(content)!;

if (fieldsData.FieldsData.Count > 0)
{
Expand Down Expand Up @@ -257,7 +257,7 @@ public async Task<List<QaseSystemField>> GetSystemFields()
}

var content = await response.Content.ReadAsStringAsync();
var systemFieldsData = JsonSerializer.Deserialize<QaseSysFieldsData>(content);
var systemFieldsData = JsonSerializer.Deserialize<QaseSysFieldsData>(content)!;

_logger.LogDebug("Got system fields: {@Fields}", systemFieldsData.Fields);

Expand Down
8 changes: 4 additions & 4 deletions Migrators/QaseExporter/Models/AttributeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace QaseExporter.Models;

public class AttributeData
{
public List<Attribute> Attributes { get; set; }
public List<Attribute> Attributes { get; set; } = new();

public Dictionary<QaseCustomField, Guid> CustomAttributeMap { get; set; }
public Dictionary<QaseCustomField, Guid> CustomAttributeMap { get; set; } = new();

public Dictionary<QaseSystemField, Guid> SystemAttributeMap { get; set; }
public Dictionary<QaseSystemField, Guid> SystemAttributeMap { get; set; } = new();

public Dictionary<string, Attribute> AttributeMap { get; set; }
public Dictionary<string, Attribute> AttributeMap { get; set; } = new();
}
10 changes: 5 additions & 5 deletions Migrators/QaseExporter/Models/QaseAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ public class QaseAttachment
public int Size { get; set; }

[JsonPropertyName("mime")]
public string Type { get; set; }
public string Type { get; set; } = null!;

[JsonPropertyName("filename")]
public string Name { get; set; }
public string Name { get; set; } = null!;

[JsonPropertyName("url")]
public string Url { get; set; }
public string Url { get; set; } = null!;
}

public class QaseDescriptionData
{
public string Description { get; set; }
public List<QaseAttachment> Attachments { get; set; }
public string? Description { get; set; }
public List<QaseAttachment> Attachments { get; set; } = new();
}
6 changes: 3 additions & 3 deletions Migrators/QaseExporter/Models/QaseBaseField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace QaseExporter.Models;
public class QaseBaseField
{
[JsonPropertyName("title")]
public string Title { get; set; }
public string Title { get; set; } = null!;

[JsonPropertyName("is_required")]
public bool Required { get; set; }

[JsonPropertyName("options")]
public List<QaseOption>? Options { get; set; }
public List<QaseOption> Options { get; set; } = new();
}

public class QaseOption
Expand All @@ -20,5 +20,5 @@ public class QaseOption
public int Id { get; set; }

[JsonPropertyName("title")]
public string Title { get; set; }
public string Title { get; set; } = null!;
}
8 changes: 4 additions & 4 deletions Migrators/QaseExporter/Models/QaseCustomField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public class QaseCustomField : QaseBaseField
public int Id { get; set; }

[JsonPropertyName("type")]
public string Type { get; set; }
public string Type { get; set; } = null!;

[JsonPropertyName("value")]
public string Value { get; set; }
public string Value { get; set; } = null!;
}

public class QaseFields
Expand All @@ -26,11 +26,11 @@ public class QaseFields
public int Filtered { get; set; }

[JsonPropertyName("entities")]
public List<QaseCustomField> Fields { get; set; }
public List<QaseCustomField> Fields { get; set; } = new();
}

public class QaseFieldsData
{
[JsonPropertyName("result")]
public QaseFields FieldsData { get; set; }
public QaseFields FieldsData { get; set; } = null!;
}
6 changes: 3 additions & 3 deletions Migrators/QaseExporter/Models/QaseProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace QaseExporter.Models;
public class QaseProject
{
[JsonPropertyName("code")]
public string Key { get; set; }
public string Key { get; set; } = null!;

[JsonPropertyName("title")]
public string Name { get; set; }
public string Name { get; set; } = null!;
}

public class QaseProjectData
{
[JsonPropertyName("result")]
public QaseProject Project { get; set; }
public QaseProject Project { get; set; } = null!;
}
10 changes: 5 additions & 5 deletions Migrators/QaseExporter/Models/QaseSharedStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace QaseExporter.Models;
public class QaseSharedStep
{
[JsonPropertyName("hash")]
public string Hash { get; set; }
public string Hash { get; set; } = null!;

[JsonPropertyName("title")]
public string Name { get; set; }
public string Name { get; set; } = null!;

[JsonPropertyName("steps")]
public List<QaseStep> Steps { get; set; }
public List<QaseStep> Steps { get; set; } = new();
}

public class QaseSharedSteps
Expand All @@ -26,11 +26,11 @@ public class QaseSharedSteps
public int Filtered { get; set; }

[JsonPropertyName("entities")]
public List<QaseSharedStep> SharedSteps { get; set; }
public List<QaseSharedStep> SharedSteps { get; set; } = new();
}

public class SharedStepData
{
[JsonPropertyName("result")]
public QaseSharedSteps SharedStepsData { get; set; }
public QaseSharedSteps SharedStepsData { get; set; } = null!;
}
4 changes: 2 additions & 2 deletions Migrators/QaseExporter/Models/QaseStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace QaseExporter.Models;
public class QaseStep
{
[JsonPropertyName("action")]
public string Action { get; set; }
public string Action { get; set; } = null!;

[JsonPropertyName("expected_result")]
public string? ExpectedResult { get; set; }
Expand All @@ -26,5 +26,5 @@ public class QaseStep
public string? SharedStepNestedHash { get; set; }

[JsonPropertyName("attachments")]
public List<QaseAttachment> Attachments { get; set; }
public List<QaseAttachment> Attachments { get; set; } = new();
}
10 changes: 5 additions & 5 deletions Migrators/QaseExporter/Models/QaseSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public class QaseSuite
public int Id { get; set; }

[JsonPropertyName("title")]
public string Name { get; set; }
public string Name { get; set; } = null!;

[JsonPropertyName("description")]
public string Description { get; set; }
public string Description { get; set; } = null!;

[JsonPropertyName("preconditions")]
public string Preconditions { get; set; }
public string Preconditions { get; set; } = null!;

[JsonPropertyName("cases_count")]
public int CasesCount { get; set; }
Expand All @@ -35,11 +35,11 @@ public class QaseSuites
public int Filtered { get; set; }

[JsonPropertyName("entities")]
public List<QaseSuite> Suites { get; set; }
public List<QaseSuite> Suites { get; set; } = new();
}

public class QaseSuitesData
{
[JsonPropertyName("result")]
public QaseSuites SuitesData { get; set; }
public QaseSuites SuitesData { get; set; } = null!;
}
2 changes: 1 addition & 1 deletion Migrators/QaseExporter/Models/QaseSystemField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public class QaseSystemField : QaseBaseField
public class QaseSysFieldsData
{
[JsonPropertyName("result")]
public List<QaseSystemField> Fields { get; set; }
public List<QaseSystemField> Fields { get; set; } = new();
}
2 changes: 1 addition & 1 deletion Migrators/QaseExporter/Models/QaseTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace QaseExporter.Models;
public class QaseTag
{
[JsonPropertyName("title")]
public string Title { get; set; }
public string Title { get; set; } = null!;

[JsonPropertyName("internal_id")]
public int InternalId { get; set; }
Expand Down
26 changes: 13 additions & 13 deletions Migrators/QaseExporter/Models/QaseTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ public class QaseTestCase
public int Id { get; set; }

[JsonPropertyName("title")]
public string Name { get; set; }
public string Name { get; set; } = null!;

[JsonPropertyName("description")]
public string Description { get; set; }
public string Description { get; set; } = null!;

[JsonPropertyName("preconditions")]
public string Preconditions { get; set; }
public string Preconditions { get; set; } = null!;

[JsonPropertyName("postconditions")]
public string Postconditions { get; set; }
public string Postconditions { get; set; } = null!;

[JsonPropertyName("status")]
public int Status { get; set; }
Expand All @@ -36,22 +36,22 @@ public class QaseTestCase
//public List<QaseLink> Links { get; set; }

[JsonPropertyName("steps")]
public List<QaseStep> Steps { get; set; }
public List<QaseStep> Steps { get; set; } = new();

[JsonPropertyName("custom_fields")]
public List<QaseCustomFieldValues> CustomFields { get; set; }
public List<QaseCustomFieldValues> CustomFields { get; set; } = new();

[JsonPropertyName("params")]
public object Parameters { get; set; }
public object Parameters { get; set; } = null!;

[JsonPropertyName("steps_type")]
public string StepsType { get; set; }
public string StepsType { get; set; } = null!;

[JsonPropertyName("attachments")]
public List<QaseAttachment> Attachments { get; set; }
public List<QaseAttachment> Attachments { get; set; } = new();

[JsonPropertyName("tags")]
public List<QaseTag> Tags { get; set; }
public List<QaseTag> Tags { get; set; } = new();

[JsonPropertyName("type")]
public int Type { get; set; }
Expand All @@ -78,7 +78,7 @@ public class QaseCustomFieldValues
public int FieldId { get; set; }

[JsonPropertyName("value")]
public string Value { get; set; }
public string Value { get; set; } = null!;
}

public class QaseCases
Expand All @@ -93,11 +93,11 @@ public class QaseCases
public int Filtered { get; set; }

[JsonPropertyName("entities")]
public List<QaseTestCase> Cases { get; set; }
public List<QaseTestCase> Cases { get; set; } = new();
}

public class QaseCasesData
{
[JsonPropertyName("result")]
public QaseCases CasesData { get; set; }
public QaseCases CasesData { get; set; } = null!;
}
4 changes: 2 additions & 2 deletions Migrators/QaseExporter/Models/SectionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace QaseExporter.Models;

public class SectionData
{
public Section MainSection { get; set; }
public Dictionary<int, Guid> SectionMap { get; set; }
public Section MainSection { get; set; } = null!;
public Dictionary<int, Guid> SectionMap { get; set; } = new();
}
4 changes: 2 additions & 2 deletions Migrators/QaseExporter/Models/StepsData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace QaseExporter.Models;

public class StepsData
{
public List<Step> Steps { get; set; }
public List<Iteration> Iterations { get; set; }
public List<Step> Steps { get; set; } = new();
public List<Iteration> Iterations { get; set; } = new();
}
4 changes: 2 additions & 2 deletions Migrators/QaseExporter/Models/TestCaseData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace QaseExporter.Models;

public class TestCaseData
{
public List<TestCase> TestCases { get; set; }
public List<Attribute> Attributes { get; set; }
public List<TestCase> TestCases { get; set; } = new();
public List<Attribute> Attributes { get; set; } = new();
}
4 changes: 2 additions & 2 deletions Migrators/QaseExporter/Services/AttributeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public async Task<AttributeData> ConvertAttributes()

if (attribute.Type == AttributeType.Options || attribute.Type == AttributeType.MultipleOptions)
{
customField.Options = JsonSerializer.Deserialize<List<QaseOption>>(customField.Value);
customField.Options = JsonSerializer.Deserialize<List<QaseOption>>(customField.Value)!;

if (customField.Options == null)
if (customField.Options.Count == 0)
{
_logger.LogError("Problems converting the value {Value} to options for the custom field {Name}", customField.Value, customField.Title);

Expand Down
1 change: 1 addition & 0 deletions Migrators/QaseExporter/Services/SectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public SectionService(ILogger<SectionService> logger, IClient client)
_logger = logger;
_client = client;
_sectionMap = new Dictionary<int, Guid>();
_allSuites = new List<QaseSuite>();
}

public async Task<SectionData> ConvertSections()
Expand Down
7 changes: 6 additions & 1 deletion Migrators/QaseExporter/Services/StepService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ private async Task<Step> ConvertStep(QaseStep step, Guid testCaseId)
return newStep;
}

private static string ConvertingStepDescription(string description)
private static string ConvertingStepDescription(string? description)
{
if (string.IsNullOrEmpty(description))
{
return string.Empty;
}

return
Utils.RemoveBackslashCharacters(
Utils.ConvertingAngleBracketsStr(
Expand Down
Loading

0 comments on commit 5bc0713

Please sign in to comment.