public List <PowerPort> Resolve(PowerConnectionDto source, PowerConnection destination, List <PowerPort> destMember, ResolutionContext context)
 {
     return(source.Ports.Select <PowerPortDto, PowerPort>(powerPort =>
     {
         // use the appropriate repository method for the given type of power port
         return powerPort switch
         {
             AssetPowerPortDto _ => _powerRepo.GetAssetPowerPort(powerPort.Id),
             PduPortDto _ => _powerRepo.GetPduPort(powerPort.Id),
             _ => throw new ArgumentException($"Unsupported power port type: {powerPort.GetType()}", nameof(powerPort))
         };
     })
            .ToList());
 }
        public async Task CreateConnection_Success()
        {
            using (var scope = _provider.CreateScope())
            {
                await SetupAssetData(scope);
            }

            var assetPowerPortId = _asset.PowerPorts[0]
                                   .Id;
            var pduPortId = _asset.Rack.Pdus.First()
                            .Ports.First()
                            .Id;

            var connectionDto = new PowerConnectionDto
            {
                Ports = new List <PowerPortDto>
                {
                    new AssetPowerPortDto(assetPowerPortId),
                    new PduPortDto(pduPortId)
                }
            };

            using (var scope = _provider.CreateScope())
            {
                var powerService = scope.ServiceProvider.GetRequiredService <IPowerService>();

                var connectionId = await powerService.CreateConnectionAsync(connectionDto);

                var connection = await powerService.GetConnectionAsync(connectionId);

                connection.Ports.Should()
                .HaveCount(2);
                connection.Ports.Should()
                .Contain(port => port.Id == pduPortId);
                connection.Ports.Should()
                .Contain(port => port.Id == assetPowerPortId);
            }
        }
Example #3
0
        public async Task <Guid> CreateConnectionAsync(PowerConnectionDto connectionDto)
        {
            var connection = _mapper.Map <PowerConnection>(connectionDto);

            return(await _repository.CreateConnectionAsync(connection));
        }