22using Foundatio . CommandQuery . MongoDB . Tests . Domain . Models ;
33using Foundatio . CommandQuery . MongoDB . Tests . Fixtures ;
44using Foundatio . CommandQuery . MongoDB . Tests . Mocks ;
5+ using Foundatio . CommandQuery . Queries ;
56
67using MediatR . CommandQuery . MongoDB . Tests ;
78
@@ -17,7 +18,7 @@ public PriorityTests(ITestOutputHelper output, DatabaseFixture databaseFixture)
1718 }
1819
1920 [ Fact ]
20- public async Task CreateEntity ( )
21+ public async Task FullTest ( )
2122 {
2223 var mediator = Services . GetService < IMediator > ( ) ;
2324 mediator . Should ( ) . NotBeNull ( ) ;
@@ -46,5 +47,64 @@ public async Task CreateEntity()
4647 created . Description . Should ( ) . Be ( createModel . Description ) ;
4748 created . DisplayOrder . Should ( ) . Be ( createModel . DisplayOrder ) ;
4849
50+ // get entity
51+ var getCommand = new GetEntity < string , PriorityReadModel > ( MockPrincipal . Default , created . Id ) ;
52+ var getResult = await mediator . InvokeAsync < Result < PriorityReadModel > > ( getCommand ) ;
53+ getResult . Should ( ) . NotBeNull ( ) ;
54+
55+ getResult . IsSuccess . Should ( ) . BeTrue ( ) ;
56+ getResult . Value . Should ( ) . NotBeNull ( ) ;
57+
58+ var readModel = ( PriorityReadModel ) getResult ;
59+ readModel . Should ( ) . NotBeNull ( ) ;
60+ readModel . Id . Should ( ) . Be ( created . Id ) ;
61+ readModel . Name . Should ( ) . Be ( createModel . Name ) ;
62+ readModel . Description . Should ( ) . Be ( createModel . Description ) ;
63+
64+ // query entity
65+ var queryDefinition = new QueryDefinition
66+ {
67+ Page = 1 ,
68+ PageSize = 10 ,
69+ Sorts = [ new ( ) { Name = nameof ( PriorityReadModel . Name ) } ]
70+ } ;
71+
72+ var queryCommand = new QueryEntities < PriorityReadModel > ( MockPrincipal . Default , queryDefinition ) ;
73+
74+ var queryResult = await mediator . InvokeAsync < Result < QueryResult < PriorityReadModel > > > ( queryCommand ) ;
75+ queryResult . Should ( ) . NotBeNull ( ) ;
76+
77+ var queryModel = ( QueryResult < PriorityReadModel > ) queryResult ;
78+ queryModel . Should ( ) . NotBeNull ( ) ;
79+ queryModel . Data . Should ( ) . NotBeNull ( ) ;
80+ queryModel . Total . Should ( ) . BeGreaterThan ( 0 ) ;
81+
82+ // update entity
83+ PriorityUpdateModel updateRequest = new ( )
84+ {
85+ Name = createModel . Name + " Updated" ,
86+ Description = createModel . Description + " Updated" ,
87+ DisplayOrder = createModel . DisplayOrder + 1 ,
88+ IsActive = ! createModel . IsActive
89+ } ;
90+ var updateCommand = new UpdateEntity < string , PriorityUpdateModel , PriorityReadModel > ( MockPrincipal . Default , created . Id , updateRequest ) ;
91+
92+ var updateResult = await mediator . InvokeAsync < Result < PriorityReadModel > > ( updateCommand ) ;
93+ updateResult . Should ( ) . NotBeNull ( ) ;
94+
95+ updateResult . IsSuccess . Should ( ) . BeTrue ( ) ;
96+ updateResult . Value . Should ( ) . NotBeNull ( ) ;
97+
98+ var updatedModel = ( PriorityReadModel ) updateResult ;
99+ updatedModel . Should ( ) . NotBeNull ( ) ;
100+ updatedModel . Id . Should ( ) . Be ( created . Id ) ;
101+ updatedModel . Name . Should ( ) . Be ( updateRequest . Name ) ;
102+ updatedModel . Description . Should ( ) . Be ( updateRequest . Description ) ;
103+
104+ // delete entity
105+ var deleteCommand = new DeleteEntity < string , PriorityReadModel > ( MockPrincipal . Default , created . Id ) ;
106+ var deleteResult = await mediator . InvokeAsync < Result < PriorityReadModel > > ( deleteCommand ) ;
107+ deleteResult . Should ( ) . NotBeNull ( ) ;
108+ deleteResult . IsSuccess . Should ( ) . BeTrue ( ) ;
49109 }
50110}
0 commit comments