@@ -27,7 +27,7 @@ public class TransactionDomainServiceTests
2727 [ Fact ]
2828 public async Task TransactionDomainService_ProcessLogonTransaction_TransactionIsProcessed ( )
2929 {
30- var configurationRoot = new ConfigurationBuilder ( ) . AddInMemoryCollection ( TestData . DefaultAppSettings ) . Build ( ) ;
30+ IConfigurationRoot configurationRoot = new ConfigurationBuilder ( ) . AddInMemoryCollection ( TestData . DefaultAppSettings ) . Build ( ) ;
3131 ConfigurationReader . Initialise ( configurationRoot ) ;
3232
3333 Logger . Initialise ( NullLogger . Instance ) ;
@@ -65,5 +65,134 @@ public async Task TransactionDomainService_ProcessLogonTransaction_TransactionIs
6565 response . ResponseCode . ShouldBe ( TestData . ResponseCode ) ;
6666 response . ResponseMessage . ShouldBe ( TestData . ResponseMessage ) ;
6767 }
68+
69+ [ Fact ]
70+ public async Task TransactionDomainService_ProcessLogonTransaction_MerchantWithNullDevices_TransactionIsProcessed ( )
71+ {
72+ IConfigurationRoot configurationRoot = new ConfigurationBuilder ( ) . AddInMemoryCollection ( TestData . DefaultAppSettings ) . Build ( ) ;
73+ ConfigurationReader . Initialise ( configurationRoot ) ;
74+
75+ Logger . Initialise ( NullLogger . Instance ) ;
76+
77+ Mock < IAggregateRepositoryManager > aggregateRepositoryManager = new Mock < IAggregateRepositoryManager > ( ) ;
78+ Mock < IAggregateRepository < TransactionAggregate > > transactionAggregateRepository = new Mock < IAggregateRepository < TransactionAggregate > > ( ) ;
79+
80+ aggregateRepositoryManager . Setup ( x => x . GetAggregateRepository < TransactionAggregate > ( It . IsAny < Guid > ( ) ) ) . Returns ( transactionAggregateRepository . Object ) ;
81+ transactionAggregateRepository . SetupSequence ( t => t . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
82+ . ReturnsAsync ( TestData . GetEmptyTransactionAggregate )
83+ . ReturnsAsync ( TestData . GetStartedTransactionAggregate )
84+ . ReturnsAsync ( TestData . GetLocallyAuthorisedTransactionAggregate )
85+ . ReturnsAsync ( TestData . GetCompletedTransactionAggregate ) ;
86+ transactionAggregateRepository . Setup ( t => t . SaveChanges ( It . IsAny < TransactionAggregate > ( ) , It . IsAny < CancellationToken > ( ) ) ) . Returns ( Task . CompletedTask ) ;
87+
88+ Mock < IEstateClient > estateClient = new Mock < IEstateClient > ( ) ;
89+ Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
90+
91+ securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
92+ estateClient . Setup ( e => e . GetMerchant ( It . IsAny < String > ( ) , It . IsAny < Guid > ( ) , It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
93+ . ReturnsAsync ( TestData . GetMerchantResponseWithNullDevices ) ;
94+
95+ TransactionDomainService transactionDomainService =
96+ new TransactionDomainService ( aggregateRepositoryManager . Object , estateClient . Object , securityServiceClient . Object ) ;
97+
98+ ProcessLogonTransactionResponse response = await transactionDomainService . ProcessLogonTransaction ( TestData . TransactionId ,
99+ TestData . EstateId ,
100+ TestData . MerchantId ,
101+ TestData . TransactionDateTime ,
102+ TestData . TransactionNumber ,
103+ TestData . DeviceIdentifier ,
104+ CancellationToken . None ) ;
105+
106+ response . ShouldNotBeNull ( ) ;
107+ response . ResponseCode . ShouldBe ( TestData . ResponseCode ) ;
108+ response . ResponseMessage . ShouldBe ( TestData . ResponseMessage ) ;
109+ }
110+
111+ [ Fact ]
112+ public async Task TransactionDomainService_ProcessLogonTransaction_MerchantWithNoDevices_TransactionIsProcessed ( )
113+ {
114+ IConfigurationRoot configurationRoot = new ConfigurationBuilder ( ) . AddInMemoryCollection ( TestData . DefaultAppSettings ) . Build ( ) ;
115+ ConfigurationReader . Initialise ( configurationRoot ) ;
116+
117+ Logger . Initialise ( NullLogger . Instance ) ;
118+
119+ Mock < IAggregateRepositoryManager > aggregateRepositoryManager = new Mock < IAggregateRepositoryManager > ( ) ;
120+ Mock < IAggregateRepository < TransactionAggregate > > transactionAggregateRepository = new Mock < IAggregateRepository < TransactionAggregate > > ( ) ;
121+
122+ aggregateRepositoryManager . Setup ( x => x . GetAggregateRepository < TransactionAggregate > ( It . IsAny < Guid > ( ) ) ) . Returns ( transactionAggregateRepository . Object ) ;
123+ transactionAggregateRepository . SetupSequence ( t => t . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
124+ . ReturnsAsync ( TestData . GetEmptyTransactionAggregate )
125+ . ReturnsAsync ( TestData . GetStartedTransactionAggregate )
126+ . ReturnsAsync ( TestData . GetLocallyAuthorisedTransactionAggregate )
127+ . ReturnsAsync ( TestData . GetCompletedTransactionAggregate ) ;
128+ transactionAggregateRepository . Setup ( t => t . SaveChanges ( It . IsAny < TransactionAggregate > ( ) , It . IsAny < CancellationToken > ( ) ) ) . Returns ( Task . CompletedTask ) ;
129+
130+ Mock < IEstateClient > estateClient = new Mock < IEstateClient > ( ) ;
131+ Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
132+
133+ securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
134+ estateClient . Setup ( e => e . GetMerchant ( It . IsAny < String > ( ) , It . IsAny < Guid > ( ) , It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
135+ . ReturnsAsync ( TestData . GetMerchantResponseWithNoDevices ) ;
136+
137+ TransactionDomainService transactionDomainService =
138+ new TransactionDomainService ( aggregateRepositoryManager . Object , estateClient . Object , securityServiceClient . Object ) ;
139+
140+ ProcessLogonTransactionResponse response = await transactionDomainService . ProcessLogonTransaction ( TestData . TransactionId ,
141+ TestData . EstateId ,
142+ TestData . MerchantId ,
143+ TestData . TransactionDateTime ,
144+ TestData . TransactionNumber ,
145+ TestData . DeviceIdentifier ,
146+ CancellationToken . None ) ;
147+
148+ response . ShouldNotBeNull ( ) ;
149+ response . ResponseCode . ShouldBe ( TestData . ResponseCode ) ;
150+ response . ResponseMessage . ShouldBe ( TestData . ResponseMessage ) ;
151+ }
152+
153+ [ Fact ]
154+ public async Task TransactionDomainService_ProcessLogonTransaction_IncorrectDevice_TransactionIsProcessed ( )
155+ {
156+ IConfigurationRoot configurationRoot = new ConfigurationBuilder ( ) . AddInMemoryCollection ( TestData . DefaultAppSettings ) . Build ( ) ;
157+ ConfigurationReader . Initialise ( configurationRoot ) ;
158+
159+ Logger . Initialise ( NullLogger . Instance ) ;
160+
161+ Mock < IAggregateRepositoryManager > aggregateRepositoryManager = new Mock < IAggregateRepositoryManager > ( ) ;
162+ Mock < IAggregateRepository < TransactionAggregate > > transactionAggregateRepository = new Mock < IAggregateRepository < TransactionAggregate > > ( ) ;
163+
164+ aggregateRepositoryManager . Setup ( x => x . GetAggregateRepository < TransactionAggregate > ( It . IsAny < Guid > ( ) ) ) . Returns ( transactionAggregateRepository . Object ) ;
165+ transactionAggregateRepository . SetupSequence ( t => t . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
166+ . ReturnsAsync ( TestData . GetEmptyTransactionAggregate )
167+ . ReturnsAsync ( TestData . GetStartedTransactionAggregate )
168+ . ReturnsAsync ( TestData . GetLocallyAuthorisedTransactionAggregate )
169+ . ReturnsAsync ( TestData . GetCompletedTransactionAggregate ) ;
170+ transactionAggregateRepository . Setup ( t => t . SaveChanges ( It . IsAny < TransactionAggregate > ( ) , It . IsAny < CancellationToken > ( ) ) ) . Returns ( Task . CompletedTask ) ;
171+
172+ Mock < IEstateClient > estateClient = new Mock < IEstateClient > ( ) ;
173+ Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
174+
175+ securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
176+ estateClient . Setup ( e => e . GetMerchant ( It . IsAny < String > ( ) , It . IsAny < Guid > ( ) , It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
177+ . ReturnsAsync ( TestData . GetMerchantResponse ) ;
178+
179+ TransactionDomainService transactionDomainService =
180+ new TransactionDomainService ( aggregateRepositoryManager . Object , estateClient . Object , securityServiceClient . Object ) ;
181+
182+ ProcessLogonTransactionResponse response = await transactionDomainService . ProcessLogonTransaction ( TestData . TransactionId ,
183+ TestData . EstateId ,
184+ TestData . MerchantId ,
185+ TestData . TransactionDateTime ,
186+ TestData . TransactionNumber ,
187+ TestData . DeviceIdentifier1 ,
188+ CancellationToken . None ) ;
189+
190+ response . ShouldNotBeNull ( ) ;
191+ response . ResponseCode . ShouldBe ( TestData . ResponseCode ) ;
192+ response . ResponseMessage . ShouldBe ( TestData . ResponseMessage ) ;
193+ }
194+
195+ // Txn for a Different Device (Causes a Validation Exception)
196+
68197 }
69198}
0 commit comments