1+ using System . Linq ;
2+ using System . Threading . Tasks ;
3+ using AngleSharp . Dom ;
4+ using Blazored . Toast . Services ;
5+ using Bunit ;
6+ using FluentAssertions ;
7+ using LinkDotNet . Blog . TestUtilities ;
8+ using LinkDotNet . Blog . Web . Shared . Skills ;
9+ using LinkDotNet . Domain ;
10+ using LinkDotNet . Infrastructure . Persistence ;
11+ using Microsoft . Extensions . DependencyInjection ;
12+ using Moq ;
13+ using Xunit ;
14+
15+ namespace LinkDotNet . Blog . IntegrationTests . Web . Shared . Skills
16+ {
17+ public class SkillTreeTests : SqlDatabaseTestBase < Skill >
18+ {
19+ [ Fact ]
20+ public async Task ShouldDeleteItem ( )
21+ {
22+ var skill = new SkillBuilder ( ) . WithSkillName ( "C#" ) . Build ( ) ;
23+ using var ctx = new TestContext ( ) ;
24+ await Repository . StoreAsync ( skill ) ;
25+ ctx . Services . AddScoped < IRepository < Skill > > ( _ => Repository ) ;
26+ ctx . Services . AddScoped ( _ => new Mock < IToastService > ( ) . Object ) ;
27+ var cut = ctx . RenderComponent < SkillTable > ( p =>
28+ p . Add ( s => s . IsAuthenticated , true ) ) ;
29+ cut . WaitForState ( ( ) => cut . HasComponent < SkillTag > ( ) ) ;
30+
31+ cut . FindComponent < SkillTag > ( ) . Find ( "button" ) . Click ( ) ;
32+
33+ var items = ( await Repository . GetAllAsync ( ) ) . ToList ( ) ;
34+ items . Should ( ) . HaveCount ( 0 ) ;
35+ cut . FindAll ( "td" ) . Any ( s => s . TextContent == "C#" ) . Should ( ) . BeFalse ( ) ;
36+ }
37+
38+ [ Fact ]
39+ public async Task ShouldAddSkill ( )
40+ {
41+ using var ctx = new TestContext ( ) ;
42+ ctx . Services . AddScoped < IRepository < Skill > > ( _ => Repository ) ;
43+ ctx . Services . AddScoped ( _ => new Mock < IToastService > ( ) . Object ) ;
44+ var cut = ctx . RenderComponent < SkillTable > ( p =>
45+ p . Add ( s => s . IsAuthenticated , true ) ) ;
46+ cut . Find ( "button" ) . Click ( ) ;
47+ var dialog = cut . FindComponent < AddSkillDialog > ( ) ;
48+ dialog . Find ( "#title" ) . Change ( "C#" ) ;
49+ dialog . Find ( "#image" ) . Change ( "Url" ) ;
50+ dialog . Find ( "#capability" ) . Change ( "capability" ) ;
51+ dialog . Find ( "#proficiency" ) . Change ( ProficiencyLevel . Expert . Key ) ;
52+
53+ dialog . Find ( "form" ) . Submit ( ) ;
54+
55+ cut . WaitForState ( ( ) => cut . HasComponent < SkillTag > ( ) ) ;
56+ var skillTag = cut . FindComponent < SkillTag > ( ) ;
57+ skillTag . Find ( "span" ) . Text ( ) . Should ( ) . Contain ( "C#" ) ;
58+ var fromRepo = ( await Repository . GetAllAsync ( ) ) [ 0 ] ;
59+ fromRepo . Name . Should ( ) . Be ( "C#" ) ;
60+ fromRepo . IconUrl . Should ( ) . Be ( "Url" ) ;
61+ fromRepo . Capability . Should ( ) . Be ( "capability" ) ;
62+ fromRepo . ProficiencyLevel . Should ( ) . Be ( ProficiencyLevel . Expert ) ;
63+ }
64+ }
65+ }
0 commit comments