@@ -138,23 +138,6 @@ public void CreateWithInvalidTemplate()
138138 . Wait ( Constants . TEST_TIMEOUT ) ;
139139 }
140140
141- [ Fact , Trait ( Constants . TYPE , Constants . UNIT_TEST ) ]
142- public void CreatingMultipleSimulationsIsNotAllowed ( )
143- {
144- // Arrange
145- this . ThereAreSomeDeviceModels ( ) ;
146- this . ThereIsAnEnabledSimulationInTheStorage ( ) ;
147- var s = new SimulationModel { Id = Guid . NewGuid ( ) . ToString ( ) , Enabled = false } ;
148-
149- // Act + Assert
150- // This fails because only 1 solution can be created
151- Assert . ThrowsAsync < ConflictingResourceException > ( async ( ) => await this . target . InsertAsync ( s ) )
152- . Wait ( Constants . TEST_TIMEOUT ) ;
153- // This fails because only "1" can be used as a simulation ID
154- Assert . ThrowsAsync < InvalidInputException > ( async ( ) => await this . target . UpsertAsync ( s ) )
155- . Wait ( Constants . TEST_TIMEOUT ) ;
156- }
157-
158141 [ Fact , Trait ( Constants . TYPE , Constants . UNIT_TEST ) ]
159142 public void CreatedSimulationsAreStored ( )
160143 {
@@ -201,10 +184,10 @@ public void SimulationsCanBeUpserted()
201184 public void UpsertRequiresIdWhileInsertDoesNot ( )
202185 {
203186 // Arrange
204- var s1 = new SimulationModel ( ) ;
205- var s2 = new SimulationModel ( ) ;
187+ var s1 = new SimulationModel ( ) { Name = "Test Simulation 1" } ;
188+ var s2 = new SimulationModel ( ) { Name = "Test Simulation 2" } ;
206189 this . ThereAreNoSimulationsInTheStorage ( ) ;
207-
190+
208191 // Act - No exception occurs
209192 this . target . InsertAsync ( s1 ) . Wait ( Constants . TEST_TIMEOUT ) ;
210193
@@ -221,7 +204,7 @@ public void UpsertUsesOptimisticConcurrency()
221204 const string ETAG2 = "002" ;
222205
223206 // Initial simulation
224- var simulation1 = new SimulationModel { Id = SIMULATION_ID , ETag = ETAG1 } ;
207+ var simulation1 = new SimulationModel { Id = SIMULATION_ID , Name = "Test Simulation 1" , ETag = ETAG1 } ;
225208 var storageRecord1 = new ValueApiModel
226209 {
227210 Key = SIMULATION_ID ,
@@ -232,7 +215,7 @@ public void UpsertUsesOptimisticConcurrency()
232215 storageList1 . Items . Add ( storageRecord1 ) ;
233216
234217 // Simulation after update
235- var simulation2 = new SimulationModel { Id = SIMULATION_ID , ETag = ETAG2 } ;
218+ var simulation2 = new SimulationModel { Id = SIMULATION_ID , Name = "Test Simulation 2" , ETag = ETAG2 } ;
236219 var storageRecord2 = new ValueApiModel
237220 {
238221 Key = SIMULATION_ID ,
@@ -253,9 +236,11 @@ public void UpsertUsesOptimisticConcurrency()
253236
254237 // Arrange - the ETag won't match
255238 this . storage . Setup ( x => x . GetAllAsync ( STORAGE_COLLECTION ) ) . ReturnsAsync ( storageList2 ) ;
239+ this . storage . Setup ( x => x . GetAsync ( STORAGE_COLLECTION , SIMULATION_ID ) ) . ReturnsAsync ( storageRecord2 ) ;
256240
257241 // Act + Assert
258242 var simulationOutOfDate = new SimulationModel { Id = SIMULATION_ID , ETag = ETAG1 } ;
243+
259244 Assert . ThrowsAsync < ResourceOutOfDateException > (
260245 async ( ) => await this . target . UpsertAsync ( simulationOutOfDate ) )
261246 . Wait ( Constants . TEST_TIMEOUT ) ;
@@ -269,15 +254,17 @@ public void ThereAreNoNullPropertiesInTheDeviceModel()
269254 this . ThereAreNoSimulationsInTheStorage ( ) ;
270255
271256 // Arrange the simulation data returned by the storage adapter
257+ var id = SIMULATION_ID ;
272258 var simulation = new SimulationModel
273259 {
274- Id = SIMULATION_ID ,
260+ Id = id ,
261+ Name = "Test Simulation" ,
275262 ETag = "ETag0" ,
276263 Enabled = true
277264 } ;
278265 var updatedValue = new ValueApiModel
279266 {
280- Key = SIMULATION_ID ,
267+ Key = id ,
281268 Data = JsonConvert . SerializeObject ( simulation ) ,
282269 ETag = simulation . ETag
283270 } ;
@@ -290,26 +277,11 @@ public void ThereAreNoNullPropertiesInTheDeviceModel()
290277 // Assert
291278 this . storage . Verify ( x => x . UpdateAsync (
292279 STORAGE_COLLECTION ,
293- SIMULATION_ID ,
294- It . Is < string > ( s => ! s . Contains ( "null" ) ) ,
280+ id ,
281+ It . IsAny < string > ( ) ,
295282 "ETag0" ) ) ;
296283 }
297284
298- [ Fact , Trait ( Constants . TYPE , Constants . UNIT_TEST ) ]
299- public void CreatingMultipleSimulationsViaUpsertIsNotAllowed ( )
300- {
301- // Arrange
302- this . ThereAreSomeDeviceModels ( ) ;
303- this . ThereIsAnEnabledSimulationInTheStorage ( ) ;
304- var s = new SimulationModel { Id = Guid . NewGuid ( ) . ToString ( ) , Enabled = false } ;
305-
306- // Act + Assert
307- // Note: the exception is 'InvalidInputException' because only id='1' is allowed. This will
308- // change in future when multiple simulation will be allowed.
309- Assert . ThrowsAsync < InvalidInputException > ( async ( ) => await this . target . UpsertAsync ( s ) )
310- . Wait ( Constants . TEST_TIMEOUT ) ;
311- }
312-
313285 private void ThereAreSomeDeviceModels ( )
314286 {
315287 this . deviceModels . Setup ( x => x . GetListAsync ( ) )
@@ -320,7 +292,7 @@ private void ThereAreNoSimulationsInTheStorage()
320292 {
321293 this . storage . Setup ( x => x . GetAllAsync ( STORAGE_COLLECTION ) ) . ReturnsAsync ( new ValueListApiModel ( ) ) ;
322294 // In case the test inserts a record, return a valid storage object
323- this . storage . Setup ( x => x . UpdateAsync ( STORAGE_COLLECTION , SIMULATION_ID , It . IsAny < string > ( ) , "*" ) )
295+ this . storage . Setup ( x => x . UpdateAsync ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < string > ( ) ) )
324296 . ReturnsAsync ( new ValueApiModel { Key = SIMULATION_ID , Data = "{}" , ETag = "someETag" } ) ;
325297 }
326298
0 commit comments