File tree Expand file tree Collapse file tree
IoTHub.Portal.Server/Services
IoTHub.Portal.Tests.Unit/Server/Services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -127,6 +127,12 @@ public async Task DeleteDeviceModel(string deviceModelId)
127127 return ;
128128 }
129129
130+ if ( deviceModelEntity . IsBuiltin )
131+ {
132+ throw new ResourceAlreadyExistsException (
133+ $ "The device model { deviceModelId } is a built-in model and cannot be deleted") ;
134+ }
135+
130136 var devices = await this . externalDeviceService . GetAllDevice ( ) ;
131137
132138 if ( devices . Items . Any ( x => DeviceHelper . RetrieveTagValue ( x , "modelId" ) == deviceModelId ) )
Original file line number Diff line number Diff line change @@ -466,6 +466,28 @@ public async Task DeleteDeviceModelShouldNotDeleteNonExistingDevice()
466466 MockRepository . VerifyAll ( ) ;
467467 }
468468
469+ [ Test ]
470+ public async Task DeleteDeviceModelShouldThrowResourceAlreadyExistsExceptionWhenDeviceModelIsBuiltin ( )
471+ {
472+ // Arrange
473+ var deviceModelDto = Fixture . Create < DeviceModelDto > ( ) ;
474+
475+ _ = this . mockDeviceModelRepository . Setup ( repository => repository . GetByIdAsync ( deviceModelDto . ModelId , d => d . Labels ) )
476+ . ReturnsAsync ( new DeviceModel
477+ {
478+ IsBuiltin = true ,
479+ Labels = new List < Label > ( )
480+ } ) ;
481+
482+ // Act
483+ var act = ( ) => this . deviceModelService . DeleteDeviceModel ( deviceModelDto . ModelId ) ;
484+
485+ // Assert
486+ _ = await act . Should ( ) . ThrowAsync < ResourceAlreadyExistsException > ( )
487+ . WithMessage ( $ "The device model { deviceModelDto . ModelId } is a built-in model and cannot be deleted") ;
488+ MockRepository . VerifyAll ( ) ;
489+ }
490+
469491 [ Test ]
470492 public async Task GetDeviceModelAvatarShouldReturnDeviceModelAvatar ( )
471493 {
You can’t perform that action at this time.
0 commit comments