Exemplo n.º 1
0
        public void EntityValidator_should_raise_validation_exception_if_endpoint_entity_token_is_short()
        {
            var endpoint = new EndpointRegistration
            {
                Address = "address", Group = "group", MonitorType = "http", Name = "name", Password = "******"
            };

            Assert.Throws <ValidationException>(() => endpoint.ValidateModel());
        }
 public IHttpActionResult PostRegisterEndpoint([FromBody] EndpointRegistration endpoint)
 {
     endpoint.ValidateModel();
     try
     {
         var id = _endpointRegistry.RegisterOrUpdate(endpoint.MonitorType, endpoint.Address, endpoint.Group, endpoint.Name, endpoint.Tags);
         return(Created(new Uri(Request.RequestUri, $"/api/endpoints/{id}"), id));
     }
     catch (UnsupportedMonitorException e)
     {
         return(BadRequest(e.Message));
     }
 }
        public IHttpActionResult PostRegisterEndpoint([FromBody] EndpointRegistration endpoint)
        {
            endpoint.ValidateModel();

            try
            {
                var existed = _endpointRegistry.GetByNaturalKey(endpoint.MonitorType, endpoint.Address);
                RequestContext.AuthorizeRegistration(endpoint, existed, SecurityRole.Admin);

                var id = _endpointRegistry.RegisterOrUpdate(endpoint.MonitorType, endpoint.Address, endpoint.Group, endpoint.Name, endpoint.Tags, endpoint.Password);
                return(Created(new Uri(Request.RequestUri, $"/api/endpoints/{id}"), id));
            }
            catch (UnsupportedMonitorException e)
            {
                return(BadRequest(e.Message));
            }
        }