Ejemplo n.º 1
0
        /// <summary>
        /// Creates client.
        /// </summary>
        void CreateClient()
        {
            Data.DeviceEnvironment info = Controllers.ContextController.GetDeviceEnvironment();

            EndpointController controller = new EndpointController(new EndpointAddress(_serviceAddress));

            CredentialsProvider credentialsProvider = new CredentialsProvider();

            credentialsProvider.Username = info.Credentials.UserName;
            credentialsProvider.Password = info.Credentials.Password;

            Binding binding = new HttpBinding(new IChannelController[] { this, controller, credentialsProvider });

            _client = CreateClient(binding, new EndpointAddress(_serviceAddress));
            System.Net.ServicePointManager.Expect100Continue = false;

            SecurityBehavior securityBehavior = new SecurityBehavior();

            securityBehavior.UserName        = info.Credentials.UserName;
            securityBehavior.Password        = info.Credentials.Password;
            securityBehavior.UseUTCTimestamp = info.Credentials.UseUTCTimeStamp;
            _client.Endpoint.Behaviors.Add(securityBehavior);

            _client.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 0, 0, _messageTimeout);
        }
Ejemplo n.º 2
0
        protected BaseOnvifTest(TestLaunchParam param)
            : base(param)
        {
            _features = param.Features;

            _cameraAddress       = param.ServiceAddress;
            _cameraIp            = param.CameraIp;
            _cameraId            = param.CameraUUID;
            _nic                 = param.NIC;
            _username            = param.UserName;
            _password            = param.Password;
            _useUTCTimestamp     = param.UseUTCTimestamp;
            _operator            = param.Operator;
            _videoForm           = param.VideoForm;
            _environmentSettings = param.EnvironmentSettings;

            _messageTimeout = param.MessageTimeout;

            _operationDelay = param.OperationDelay;
            _recoveryDelay  = param.RecoveryDelay;

            _rebootTimeout = param.RebootTimeout;

            _trafficListener                   = new TrafficListener();
            _trafficListener.RequestSent      += LogRequest;
            _trafficListener.ResponseReceived += LogResponse;

            _endpointController = new EndpointController(new EndpointAddress(_cameraAddress));

            _credentialsProvider          = new CredentialsProvider();
            _credentialsProvider.Username = param.UserName;
            _credentialsProvider.Password = param.Password;
            _credentialsProvider.Security = param.Security;
        }
Ejemplo n.º 3
0
        public void ShouldBeAbleToRetrieveEndpointInformation()
        {
            // Arrange
            var controller = new EndpointController(new EndpointInfo
            {
                KeyName   = "qwerty",
                AccessKey = "qwerty",
                Resource  = "qwerty",
                Ttl       = TimeSpan.FromMinutes(10),
            });

            // Act
            var result = controller.Get();

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(result);
            var model    = okResult.Value as AnalyticsEndpointInfoResponseModel;

            Assert.NotNull(model);

            //TODO: Add additional asserts as soon as we can handle configurations witin unit tests
            Assert.Equal("POST", model.HttpVerb);
            Assert.NotEmpty(model.Url);
            Assert.Equal("application/json", model.ContentType);
            Assert.NotEmpty(model.Authorization);
        }
Ejemplo n.º 4
0
        public void CreateEndpointWithValidInput()
        {
            Endpoint endpoint = new Endpoint()
            {
                serialNumber         = "1",
                meterModelId         = 16,
                meterNumber          = 1,
                meterFirmwareVersion = "1",
                switchState          = 0
            };
            Mock <IBaseDao <Endpoint> > mock = new Mock <IBaseDao <Endpoint> >();

            mock.Setup(dao => dao.Create(endpoint)).Returns(endpoint);
            EndpointController endpointController = new EndpointController();
            EndpointVO         endpointVo         = new EndpointVO()
            {
                serialNumber         = "1",
                meterModelId         = "nsx1p2w",
                meterNumber          = "1",
                switchState          = "Disconnected",
                meterFirmwareVersion = "1",
            };
            var resultExpect = mock.Object.Create(endpoint);
            var result       = endpointController.Create(endpointVo);

            Assert.AreEqual(resultExpect, result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor. Performs initialization.
        /// </summary>
        /// <param name="param"></param>
        protected BaseTest(TestLaunchParam param)
        {
            _cameraAddress        = param.ServiceAddress;
            _cameraIp             = param.CameraIp;
            _cameraId             = param.CameraUUID;
            _nic                  = param.NIC;
            _username             = param.UserName;
            _password             = param.Password;
            _useUTCTimestamp      = param.UseUTCTimestamp;
            _operator             = param.Operator;
            _videoForm            = param.VideoForm;
            _environmentSettings  = param.EnvironmentSettings;
            _ptzNodeToken         = param.PTZNodeToken;
            _useEmbeddedPassword  = param.UseEmbeddedPassword;
            _password1            = param.Password1;
            _password2            = param.Password2;
            _operationDelay       = param.OperationDelay;
            _recoveryDelay        = param.RecoveryDelay;
            _relayOutputDelayTime = param.RelayOutputDelayTime;

            _rebootTimeout = param.RebootTimeout;

            _semaphore = new TestSemaphore();

            _trafficListener                   = new TrafficListener();
            _trafficListener.RequestSent      += LogRequest;
            _trafficListener.ResponseReceived += LogResponse;

            _endpointController = new EndpointController(new EndpointAddress(_cameraAddress));

            _credentialsProvider          = new CredentialsProvider();
            _credentialsProvider.Username = param.UserName;
            _credentialsProvider.Password = param.Password;
        }
Ejemplo n.º 6
0
        protected Binding CreateEventServiceBinding(string address)
        {
            IChannelController[] controllers;
            // add mandatory controllers.
            // _trafficListener is used to monitor data sent and received via Client.
            // _semaphore is used to stop waiting for the answer.

            EndpointController controller = new EndpointController(new EndpointAddress(address));

            WsaController wsaController = new WsaController();

            controllers = new IChannelController[]
            {
                _trafficListener,
                _semaphore,
                _credentialsProvider,
                controller,
                wsaController,
                new SoapValidator(EventsSchemasSet.GetInstance())
            };

            Binding binding = CreateBinding(controllers);

            return(binding);
        }
Ejemplo n.º 7
0
        public override EventPortTypeClient CreateClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress address)
        {
            EndpointController controller = new EndpointController(new EndpointAddress(_serviceAddress));

            controller.WsaEnabled = true;
            Binding binding1 = new HttpBinding(new IChannelController[] { this, controller, _credentialsProvider });

            return(new EventPortTypeClient(binding1, address));
        }
Ejemplo n.º 8
0
        public override EventPortTypeClient CreateClient(Binding binding, EndpointAddress address)
        {
            EndpointController controller = new EndpointController(new EndpointAddress(_serviceAddress));

            WsaController wsaController = new WsaController();
            Binding       eventBinding  = new HttpBinding(new IChannelController[] { this, controller, wsaController, _credentialsProvider });

            return(new EventPortTypeClient(eventBinding, address));
        }
Ejemplo n.º 9
0
 public void CreateEndpointWithEmptySerialNumber()
 {
     EndpointController endpointController = new EndpointController();
     EndpointVO         endpointVo         = new EndpointVO()
     {
         meterModelId         = "nsx1p2w",
         meterNumber          = "1",
         switchState          = "Disconnected",
         meterFirmwareVersion = "1",
     };
     var result = endpointController.Create(endpointVo);
 }
Ejemplo n.º 10
0
 public void CreateEndpointWithInvalidSwitchState()
 {
     EndpointController endpointController = new EndpointController();
     EndpointVO         endpointVo         = new EndpointVO()
     {
         serialNumber         = "1",
         meterModelId         = "nsx1p2w",
         meterNumber          = "1",
         switchState          = "5",
         meterFirmwareVersion = "1",
     };
     var result = endpointController.Create(endpointVo);
 }
Ejemplo n.º 11
0
        protected BaseOnvifTest(TestLaunchParam param) : base(param)
        {
            _features.Mode = param.FeatureDefinitionMode;
            if (param.FeatureDefinitionMode == FeatureDefinitionMode.Default)
            {
                _features.AddRange(param.Features);
            }

            _cameraAddress   = param.ServiceAddress;
            _cameraIp        = param.CameraIp;
            _cameraId        = param.CameraUUID;
            _nic             = param.NIC;
            _username        = param.UserName;
            _password        = param.Password;
            _useUTCTimestamp = param.UseUTCTimestamp;
            Operator         = param.Operator;

            if (param.VideoForm != null)
            {
                _videoForm = param.VideoForm;
                // reinitialize video window
                _videoForm.Reset();
                _videoForm.NICIndex  = param.NIC.Index;
                _videoForm.StopEvent = _semaphore.StopEvent;
            }

            _declaredScopes.AddRange(param.DeclaredScopes);

            _environmentSettings = param.EnvironmentSettings;

            _messageTimeout = param.MessageTimeout;

            _operationDelay = param.OperationDelay;
            _recoveryDelay  = param.RecoveryDelay;

            _rebootTimeout = param.RebootTimeout;

            // should be done in BaseTest.Initialize();
            //_trafficListener = new TrafficListener();
            //_trafficListener.RequestSent += LogRequest;
            //_trafficListener.ResponseReceived += LogResponse;

            _endpointController = new EndpointController(new EndpointAddress(_cameraAddress));

            _credentialsProvider          = new CredentialsProvider();
            _credentialsProvider.Username = param.UserName;
            _credentialsProvider.Password = param.Password;
            _credentialsProvider.Security = param.Security;
        }
Ejemplo n.º 12
0
        private HttpBinding CreateEventServiceBinding(string address)
        {
            IChannelController[] controllers;
            // add mandatory controllers.
            // _trafficListener is used to monitor data sent and received via Client.
            // _semaphore is used to stop waiting for the answer.

            EndpointController controller = new EndpointController(new EndpointAddress(address));

            controller.WsaEnabled = true;
            controllers           = new IChannelController[] { _trafficListener, _semaphore, controller, new SoapValidator(EventsSchemasSet.GetInstance()) };

            HttpBinding binding = new HttpBinding(controllers);

            return(binding);
        }
        void InitServiceClient(ServiceHolder serviceHolder, IEnumerable <IChannelController> controllers)
        {
            bool found = false;

            if (!serviceHolder.HasAddress)
            {
                RunStep(() =>
                {
                    serviceHolder.Retrieve(Features);
                    if (!serviceHolder.HasAddress)
                    {
                        throw new AssertException(string.Format("{0} service not found", serviceHolder.ServiceName));
                    }
                    else
                    {
                        found = true;
                        LogStepEvent(serviceHolder.Address);
                    }
                }, string.Format("Get {0} service address", serviceHolder.ServiceName),
                        OnvifFaults.NoSuchService, true, true);
                DoRequestDelay();
            }

            Assert(found,
                   string.Format("{0} service address not found", serviceHolder.ServiceName),
                   string.Format("Check that the DUT returned {0} service address", serviceHolder.ServiceName));

            if (found)
            {
                EndpointController controller = new EndpointController(new EndpointAddress(serviceHolder.Address));

                List <IChannelController> ctrls = new List <IChannelController>();
                ctrls.Add(controller);
                ctrls.AddRange(controllers);

                Binding binding = CreateBinding(
                    false,
                    ctrls);

                serviceHolder.CreateClient(binding, AttachSecurity, SetupChannel);
            }
        }
Ejemplo n.º 14
0
        public static void InitServiceClient <ServicePortClient, ServicePort>(this ServiceHolder <ServicePortClient, ServicePort> s, IEnumerable <IChannelController> controllers, BaseOnvifTest test, bool includeAddressController = false)
            where ServicePort : class
            where ServicePortClient : ClientBase <ServicePort>, ServicePort
        {
            bool found = false;

            if (!s.HasAddress)
            {
                s.Retrieve(test.Features);
                test.RunStep(() =>
                {
                    if (!s.HasAddress)
                    {
                        throw new AssertException(string.Format("{0} service not found", s.ServiceName));
                    }
                    else
                    {
                        found = true;
                        test.LogStepEvent(s.Address);
                    }
                },
                             string.Format("Get {0} service address", s.ServiceName), OnvifFaults.NoSuchService, true, true);
                test.DoRequestDelay();
            }

            test.Assert(found,
                        string.Format("{0} service address not found", s.ServiceName),
                        string.Format("Check that the DUT returned {0} service address", s.ServiceName));

            if (found)
            {
                var controller = new EndpointController(new EndpointAddress(s.Address));

                var ctrls = new List <IChannelController>();
                ctrls.Add(controller);
                ctrls.AddRange(controllers);

                Binding binding = test.CreateBinding(includeAddressController, ctrls);

                s.CreateClient(binding, test.AttachSecurity, test.SetupChannel);
            }
        }
Ejemplo n.º 15
0
        public void GetEndpoints()
        {
            //Arrange
            List <Endpoint> endpoints = Endpoints.EndpointList;

            var projectService = new Mock <IProjectService>();

            projectService.Setup(service => service.GetEndpoints())
            .Returns(endpoints);
            var controller = new EndpointController(projectService.Object);

            // Act
            var values = controller.GetEndpoints();
            var result = values.Result as OkObjectResult;


            //Assert
            Assert.Equal(200, result.StatusCode);
            Assert.Equal(endpoints, result.Value);
        }
Ejemplo n.º 16
0
        public void InitServiceClient(IEnumerable <IChannelController> controllers, bool includeAddressController = false)
        {
            bool found = false;

            if (string.IsNullOrEmpty(ServiceAddress))
            {
                ServiceAddress = ServiceAddressRetrievalAction(Test.Features);
                Test.RunStep(() =>
                {
                    //Failed to retrive service's address
                    if (string.IsNullOrEmpty(ServiceAddress))
                    {
                        throw new AssertException(string.Format("{0} service not found", ServiceName));
                    }
                    else
                    {
                        found = true;
                        Test.LogStepEvent(ServiceAddress);
                    }
                },
                             string.Format("Get {0} service address", ServiceName), OnvifFaults.NoSuchService, true, true);
                Test.DoRequestDelay();
            }

            Test.Assert(found,
                        string.Format("{0} service address not found", ServiceName),
                        string.Format("Check that the DUT returned {0} service address", ServiceName));

            if (found)
            {
                var controller = new EndpointController(new EndpointAddress(ServiceAddress));

                var ctrls = new List <IChannelController>();
                ctrls.Add(controller);
                ctrls.AddRange(controllers);

                Binding binding = Test.CreateBinding(includeAddressController, ctrls);

                CreateClient(binding, Test.AttachSecurity, Test.SetupChannel);
            }
        }
Ejemplo n.º 17
0
        private void ConfigureControllers(Application application)
        {
            Type localClass = application.GetType();

            deviceController = new DeviceController();

            Debug.WriteLine("## AppName: " + deviceController.AppName);
            Debug.WriteLine("## Version: " + deviceController.Version);

            foreach (object attribute in localClass.GetCustomAttributes(true))
            {
                if (attribute is MposConfig)
                {
                    MposConfig appConfig = (MposConfig)attribute;
                    Debug.WriteLine(appConfig);

                    if (appConfig.DeviceDetails)
                    {
                        deviceController.CollectDeviceConfig();
                    }
                    if (appConfig.LocationCollect)
                    {
                        deviceController.CollectLocation();
                    }

                    if (appConfig.EndpointSecondary == null && !appConfig.DiscoveryCloudlet)
                    {
                        throw new NetworkException("You must define an internet server IP or allow the service discovery!");
                    }

                    profileController  = new ProfileController(appConfig.Profile);
                    endpointController = new EndpointController(appConfig.EndpointSecondary, appConfig.DecisionMakerActive, appConfig.DiscoveryCloudlet);

                    break;
                }
            }
        }
Ejemplo n.º 18
0
        public void CreateEndpointWithDuplicatedSerialNumber()
        {
            Endpoint endpoint = new Endpoint()
            {
                serialNumber         = "1",
                meterModelId         = 16,
                meterNumber          = 1,
                meterFirmwareVersion = "1",
                switchState          = 0
            };
            Mock <IBaseDao <Endpoint> > mock = new Mock <IBaseDao <Endpoint> >();

            mock.Setup(dao => dao.FindOne(endpoint.serialNumber)).Returns(endpoint);
            EndpointController endpointController = new EndpointController();
            EndpointVO         endpointVo         = new EndpointVO()
            {
                serialNumber         = "1",
                meterModelId         = "nsx1p2w",
                meterNumber          = "1",
                switchState          = "Disconnected",
                meterFirmwareVersion = "1",
            };
            var result = endpointController.Create(endpointVo);
        }
Ejemplo n.º 19
0
 public void CreateEndpointWithEmptyEndpoint()
 {
     EndpointController endpointController = new EndpointController();
     EndpointVO         endpointVo         = new EndpointVO();
     var result = endpointController.Create(endpointVo);
 }
Ejemplo n.º 20
0
        protected BaseOnvifTest(TestLaunchParam param) : base(param)
        {
            _features.Mode = param.FeatureDefinitionMode;
            if (param.FeatureDefinitionMode == FeatureDefinitionMode.Default)
            {
                _features.AddRange(param.Features);
            }

            //_cameraAddress = param.ServiceAddress;
            FirmwareFilePath = param.FirmwareFilePath;

            CredentialIdentifierValueFirst  = param.CredentialIdentifierValueFirst;
            CredentialIdentifierValueSecond = param.CredentialIdentifierValueSecond;
            CredentialIdentifierValueThird  = param.CredentialIdentifierValueThird;

            _cameraIp = param.CameraIp;
            _cameraId = param.CameraUUID;
            _nic      = param.NIC;
            TestTool.HttpTransport.RequestNetworkStream.EndpointFrom = new IPEndPoint(_nic.IP, 0);
            _username        = param.UserName;
            _password        = param.Password;
            _useUTCTimestamp = param.UseUTCTimestamp;
            Operator         = param.Operator;

            if (param.VideoForm != null)
            {
                _videoForm = param.VideoForm;
                // reinitialize video window
                _videoForm.Reset();
                _videoForm.NICIndex  = param.NIC.Index;
                _videoForm.StopEvent = _semaphore.StopEvent;
            }

            _declaredScopes.AddRange(param.DeclaredScopes);

            _environmentSettings = param.EnvironmentSettings;

            _messageTimeout = param.MessageTimeout;

            _operationDelay = param.OperationDelay;
            _recoveryDelay  = param.RecoveryDelay;

            _rebootTimeout = param.RebootTimeout;

            // should be done in BaseTest.Initialize();
            //_trafficListener = new TrafficListener();
            //_trafficListener.RequestSent += LogRequest;
            //_trafficListener.ResponseReceived += LogResponse;

            _endpointController = new EndpointController(new EndpointAddress(param.ServiceAddress));

            _credentialsProvider = new CredentialsProvider
            {
                Username = param.UserName,
                Password = param.Password,
                Security = param.Security
            };

            NetworkSettingsChangedEvent += address =>
            {
                var uri = new EndpointAddress(address);

                var       addresses = Dns.GetHostAddresses(uri.Uri.Host);
                IPAddress newAddr   = null;
                switch (uri.Uri.HostNameType)
                {
                case UriHostNameType.IPv4:
                    newAddr = addresses.FirstOrDefault(u => u.AddressFamily == AddressFamily.InterNetwork);
                    break;

                case UriHostNameType.IPv6:
                    newAddr = addresses.FirstOrDefault(u => u.AddressFamily == AddressFamily.InterNetworkV6);
                    break;

                case UriHostNameType.Dns:
                    newAddr = addresses.FirstOrDefault(u => u.AddressFamily == AddressFamily.InterNetwork);
                    if (null == _cameraIp)
                    {
                        newAddr = addresses.FirstOrDefault(u => u.AddressFamily == AddressFamily.InterNetworkV6);
                    }
                    break;
                }

                if (null != newAddr)
                {
                    _endpointController.UpdateAddress(uri);
                    _cameraIp = newAddr;
                }
            };
        }