|
2 | 2 | using Dataverse.ConfigurationMigrationTool.Console.Features.Import.Commands;
|
3 | 3 | using Dataverse.ConfigurationMigrationTool.Console.Features.Import.Model;
|
4 | 4 | using Dataverse.ConfigurationMigrationTool.Console.Features.Shared;
|
| 5 | +using Dataverse.ConfigurationMigrationTool.Console.Tests.Extensions; |
5 | 6 | using Microsoft.Extensions.Logging;
|
6 | 7 | using NSubstitute;
|
| 8 | +using Shouldly; |
7 | 9 |
|
8 | 10 | namespace Dataverse.ConfigurationMigrationTool.Console.Tests.Features.Import.Commands;
|
9 | 11 | public class ImportCommandsTest
|
@@ -69,5 +71,48 @@ public async Task GivenDataToImportWithSchema_WhenTheCommandExecutes_ThenItShoul
|
69 | 71 | });
|
70 | 72 |
|
71 | 73 | }
|
| 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 |
72 | 85 |
|
| 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 | + } |
73 | 118 | }
|
0 commit comments