Skip to content

Commit b2fa9f0

Browse files
committed
Improvements and unit tests for coverage
1 parent a128e1b commit b2fa9f0

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/Dataverse.ConfigurationMigrationTool/Console.Tests/Features/Import/Commands/ImportCommandsTest.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using Dataverse.ConfigurationMigrationTool.Console.Features.Import.Commands;
33
using Dataverse.ConfigurationMigrationTool.Console.Features.Import.Model;
44
using Dataverse.ConfigurationMigrationTool.Console.Features.Shared;
5+
using Dataverse.ConfigurationMigrationTool.Console.Tests.Extensions;
56
using Microsoft.Extensions.Logging;
67
using NSubstitute;
8+
using Shouldly;
79

810
namespace Dataverse.ConfigurationMigrationTool.Console.Tests.Features.Import.Commands;
911
public class ImportCommandsTest
@@ -69,5 +71,48 @@ public async Task GivenDataToImportWithSchema_WhenTheCommandExecutes_ThenItShoul
6971
});
7072

7173
}
74+
[Fact]
75+
public async Task GivenAnInvalidSchema_WhenTheCommandExecutes_ThenItShouldFailAndLogIssues()
76+
{
77+
//Arrange
78+
var importSchema = new ImportSchema
79+
{
80+
Entity = new()
81+
{
82+
FakeSchemas.Account,
83+
FakeSchemas.Contact,
84+
FakeSchemas.Opportunity
7285

86+
}
87+
};
88+
var datasets = new Entities
89+
{
90+
Entity = new()
91+
{
92+
FakeDatasets.AccountSets,
93+
FakeDatasets.ContactSets,
94+
FakeDatasets.OpportunitiesSet
95+
}
96+
};
97+
_importDataService.Execute(Arg.Any<ImportDataTask>(), Arg.Any<Entities>())
98+
.Returns(TaskResult.Completed);
99+
_importDataProvider.ReadFromFile(DataFilePath).Returns(datasets);
100+
_importDataProvider.ReadSchemaFromFile(SchemaFilePath).Returns(importSchema);
101+
_schemaValidator.Validate(importSchema).Returns(new ValidationResult()
102+
{
103+
Failures = new List<ValidationFailure>
104+
{
105+
new ("Entity", "Entity is not valid")
106+
}
107+
});
108+
//Act
109+
Func<Task> act = () => _importCommands.Import(SchemaFilePath, DataFilePath);
110+
111+
//Assert
112+
var ex = await act.ShouldThrowAsync<Exception>();
113+
ex.Message.ShouldBe("Provided Schema was not valid.");
114+
_logger.ShouldHaveLogged(LogLevel.Error, "Schema failed validation process with 1 failure(s).");
115+
116+
117+
}
73118
}

0 commit comments

Comments
 (0)