Example #1
0
        private Mock <Device> CreateDeviceMock()
        {
            var capabilities = new Capabilities {
                Events = new EventCapabilities {
                    XAddr = "http://127.0.0.1", WSPullPointSupport = true
                }
            };

            var deviceMock = new Mock <Device>();

            deviceMock.Setup(x => x.GetCapabilitiesAsync(It.IsNotNull <GetCapabilitiesRequest>())).
            Returns(Task.FromResult(new GetCapabilitiesResponse(capabilities)));
            deviceMock.Setup(x => x.GetSystemDateAndTimeAsync()).
            Returns(Task.FromResult(new SystemDateTime()));

            return(deviceMock);
        }
        public async Task ConnectAsync(CancellationToken cancellationToken)
        {
            DateTime deviceTime = await GetDeviceTimeAsync();

            if (!_connectionParameters.Credentials.IsEmpty())
            {
                byte[] nonceBytes = new byte[20];
                var    random     = new Random();
                random.NextBytes(nonceBytes);

                var token = new SecurityToken(deviceTime, nonceBytes);

                _onvifClientFactory.SetSecurityToken(token);
            }

            cancellationToken.ThrowIfCancellationRequested();

            _deviceCapabilities = await GetDeviceCapabilitiesAsync();

            if (!_deviceCapabilities.Events.WSPullPointSupport)
            {
                throw new DeviceEventReceiverException("Device doesn't support pull point subscription");
            }
        }