Skip to content

Commit e20927a

Browse files
committed
Adding unit tests
1 parent 8096736 commit e20927a

File tree

66 files changed

+618
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+618
-52
lines changed

src/Dataverse.ConfigurationMigrationTool.Console/Dataverse.ConfigurationMigrationTool.Console/Services/Dataverse/DataverseMetadataService.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
14+
<PackageReference Include="FakeXrmEasy.v9" Version="3.6.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
16+
<PackageReference Include="NSubstitute" Version="5.3.0" />
17+
<PackageReference Include="Shouldly" Version="4.3.0" />
18+
<PackageReference Include="xunit" Version="2.5.3" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\Dataverse.ConfigurationMigrationTool.Console\Dataverse.ConfigurationMigrationTool.Console.csproj" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<Using Include="Xunit" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<None Update="assets\schema.xml">
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
</None>
34+
</ItemGroup>
35+
36+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.Extensions.Logging;
2+
using NSubstitute;
3+
4+
namespace Dataverse.ConfigurationMigrationTool.Console.Tests.Extensions;
5+
internal static class ILoggerTestExtensions
6+
{
7+
public static void ShouldHaveLoggedException(this ILogger logger, LogLevel logLevel, Exception exception)
8+
{
9+
logger.Received().Log(logLevel, Arg.Any<EventId>(), Arg.Any<object>(), exception, Arg.Any<Func<object, Exception, string>>());
10+
}
11+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using Dataverse.ConfigurationMigrationTool.Console.Features.Import.Model;
2+
3+
namespace Dataverse.ConfigurationMigrationTool.Console.Tests;
4+
internal static class FakeDatasets
5+
{
6+
public static readonly Guid[] AccountIds = new[]
7+
{
8+
Guid.NewGuid(),
9+
Guid.NewGuid(),
10+
Guid.NewGuid(),
11+
Guid.NewGuid(),
12+
Guid.NewGuid()
13+
};
14+
public static readonly Guid[] ContactIds = new[]
15+
{
16+
Guid.NewGuid(),
17+
Guid.NewGuid(),
18+
Guid.NewGuid(),
19+
Guid.NewGuid(),
20+
Guid.NewGuid()
21+
};
22+
public static readonly Guid[] OpportunityIds = new[]
23+
{
24+
Guid.NewGuid(),
25+
Guid.NewGuid(),
26+
Guid.NewGuid(),
27+
Guid.NewGuid(),
28+
Guid.NewGuid()
29+
};
30+
public static readonly EntityImport AccountSets = new()
31+
{
32+
Displayname = "Account",
33+
Name = "account",
34+
Records = new()
35+
{
36+
Record = new()
37+
{
38+
new(){
39+
Id = AccountIds[0],
40+
Field = new(){
41+
new()
42+
{
43+
Name = "name",
44+
Value = "Account 1"
45+
},
46+
new()
47+
{
48+
Name = "primarycontactid",
49+
Value = ContactIds[0].ToString(),
50+
Lookupentity = "contact",
51+
Lookupentityname = "John Doe"
52+
}
53+
}
54+
}
55+
}
56+
}
57+
};
58+
public static readonly EntityImport OpportunitiesSet = new()
59+
{
60+
Displayname = "Opportunity",
61+
Name = "opportunity",
62+
Records = new()
63+
{
64+
Record = new()
65+
{
66+
new(){
67+
Id = OpportunityIds[0],
68+
Field = new(){
69+
new()
70+
{
71+
Name = "name",
72+
Value = "Opportunity 1"
73+
},
74+
new()
75+
{
76+
Name = "estimatedvalue",
77+
Value = "4576.23"
78+
},
79+
}
80+
}
81+
}
82+
}
83+
};
84+
public static readonly EntityImport ContactSets = new()
85+
{
86+
Displayname = "Contact",
87+
Name = "contact",
88+
M2mrelationships = new M2mrelationships
89+
{
90+
M2mrelationship = new()
91+
{
92+
new()
93+
{
94+
M2mrelationshipname = "contact_opportunities",
95+
Sourceid = ContactIds[0],
96+
Targetentityname = "opportunity",
97+
Targetentitynameidfield = "opportunityid",
98+
Targetids = new(){
99+
Targetid = new() {
100+
OpportunityIds[0],
101+
}
102+
}
103+
}
104+
}
105+
},
106+
Records = new()
107+
{
108+
Record = new()
109+
{
110+
new(){
111+
Id = ContactIds[0],
112+
Field = new(){
113+
new()
114+
{
115+
Name = "firstname",
116+
Value = "John"
117+
},
118+
new()
119+
{
120+
Name = "lastname",
121+
Value = "Doe"
122+
}
123+
124+
}
125+
}
126+
}
127+
}
128+
};
129+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using Dataverse.ConfigurationMigrationTool.Console.Features.Import.Model;
2+
3+
namespace Dataverse.ConfigurationMigrationTool.Console.Tests;
4+
internal static class FakeSchemas
5+
{
6+
public static readonly EntitySchema Account = new EntitySchema()
7+
{
8+
Name = "account",
9+
Primaryidfield = "accountid",
10+
Primarynamefield = "name",
11+
Fields = new FieldsSchema
12+
{
13+
Field = new List<FieldSchema>
14+
{
15+
new FieldSchema
16+
{
17+
Name = "name",
18+
Type = "string"
19+
20+
},
21+
new FieldSchema
22+
{
23+
Name = "primarycontactid",
24+
Type = "entityreference",
25+
Customfield = true,
26+
Displayname = "Primary Contact",
27+
LookupType = "contact",
28+
PrimaryKey = false
29+
}
30+
}
31+
},
32+
};
33+
public static readonly EntitySchema Opportunity = new EntitySchema()
34+
{
35+
Name = "opportunity",
36+
Primaryidfield = "opportunityid",
37+
Primarynamefield = "name",
38+
Displayname = "Opportunity",
39+
Fields = new FieldsSchema
40+
{
41+
Field = new List<FieldSchema>
42+
{
43+
new FieldSchema
44+
{
45+
Name = "name",
46+
Type = "string"
47+
},
48+
new FieldSchema
49+
{
50+
Name = "estimatedvalue",
51+
Type = "money"
52+
}
53+
}
54+
},
55+
};
56+
public static readonly EntitySchema Contact = new EntitySchema()
57+
{
58+
Name = "contact",
59+
Primaryidfield = "contactid",
60+
Primarynamefield = "fullname",
61+
Displayname = "Contact",
62+
Etc = 2,
63+
Disableplugins = false,
64+
Relationships = new RelationshipsSchema
65+
{
66+
Relationship = new List<RelationshipSchema>
67+
{
68+
new RelationshipSchema
69+
{
70+
Name = "contact_opportunities",
71+
Isreflexive = false,
72+
M2mTargetEntity = "opportunity",
73+
M2mTargetEntityPrimaryKey = "opportunityid",
74+
ManyToMany = true,
75+
RelatedEntityName = "contact_opportunities"
76+
}
77+
}
78+
},
79+
Fields = new FieldsSchema
80+
{
81+
Field = new List<FieldSchema>
82+
{
83+
new FieldSchema
84+
{
85+
Name = "firstname",
86+
Type = "string"
87+
88+
},
89+
new FieldSchema
90+
{
91+
Name = "lastname",
92+
Type = "string"
93+
94+
}
95+
}
96+
},
97+
};
98+
99+
}

0 commit comments

Comments
 (0)