Esempio n. 1
0
        public void Test_FieldValidation_Error( )
        {
            // Getting Forbidden? Or ConnectorConfigException?
            // Maybe there's duplicate copies of these objects in the DB.

            ConnectorRequest  request;
            ConnectorResponse response;
            IConnectorService service;
            string            tooLong = new string( 'z', 1000 );

            CreateScenarioImpl(null, () => new [] { Permissions.Create });

            // Define request
            request = new ConnectorRequest
            {
                TenantName  = TenantName,
                QueryString = new Dictionary <string, string> {
                    { "key", ApiKey }
                },
                ApiPath            = new [] { ApiAddress, EndpointAddress },
                Verb               = ConnectorVerb.Post,
                Payload            = JilDynamicObjectReaderTests.GetReader(@"{ ""field1"":""" + tooLong + @""" }"),
                ControllerRootPath = "https://whatever/SpApi/api/"
            };

            // Get service
            service = Factory.ConnectorService;

            // Place request
            response = service.HandleRequest(request);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.That(response.MessageResponse.PlatformMessageCode, Is.EqualTo("E1008"));
        }
Esempio n. 2
0
        public void Test_Resource_PutUpdate_WithEmptyBody_Bug26808(string body)
        {
            // Getting Forbidden? Or ConnectorConfigException?
            // Maybe there's duplicate copies of these objects in the DB.

            ConnectorRequest  request;
            ConnectorResponse response;
            IConnectorService service;
            string            resourceName = "ResourceToUpdate";

            CreateScenarioImpl(resourceName, () => new[] { Permissions.Read, Permissions.Modify });

            // Define request
            request = new ConnectorRequest
            {
                TenantName  = TenantName,
                QueryString = new Dictionary <string, string> {
                    { "key", ApiKey }
                },
                ApiPath = new[] { ApiAddress, EndpointAddress, resourceName },
                Verb    = ConnectorVerb.Put,
                Payload = JilDynamicObjectReaderTests.GetReader(body)
            };

            // Get service
            service = Factory.ConnectorService;

            // Place request
            response = service.HandleRequest(request);

            // Check result
            Assert.That(response, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.That(response.MessageResponse.PlatformMessageCode, Is.EqualTo("E1009"));
        }
Esempio n. 3
0
        public void Test_Resource_PostCreate_WithInvalidLookup_Bug26761()
        {
            ConnectorRequest  request;
            ConnectorResponse response;
            IConnectorService service;

            CreateScenarioImpl(null, () => new[] { Permissions.Create });

            // Define request
            request = new ConnectorRequest
            {
                TenantName  = TenantName,
                QueryString = new Dictionary <string, string> {
                    { "key", ApiKey }
                },
                ApiPath            = new[] { ApiAddress, EndpointAddress },
                Verb               = ConnectorVerb.Post,
                Payload            = JilDynamicObjectReaderTests.GetReader(@"{ ""field1"":""hello"", ""lookup1"":""IDontExist"" }"),
                ControllerRootPath = "https://whatever/SpApi/api/"
            };

            // Get service
            service = Factory.ConnectorService;

            // Place request
            response = service.HandleRequest(request);

            // Check result
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.That(response.MessageResponse.PlatformMessageCode, Is.EqualTo("E1003"));
            Assert.That(response.MessageResponse.Message, Is.EqualTo("No resources were found that matched 'IDontExist'."));
        }
Esempio n. 4
0
        public void Test_Resource_PostCreate_WithEmptyBody_Bug26808(string body)
        {
            ConnectorRequest  request;
            ConnectorResponse response;
            IConnectorService service;

            CreateScenarioImpl(null, () => new[] { Permissions.Create });

            // Define request
            request = new ConnectorRequest
            {
                TenantName  = TenantName,
                QueryString = new Dictionary <string, string> {
                    { "key", ApiKey }
                },
                ApiPath            = new[] { ApiAddress, EndpointAddress },
                Verb               = ConnectorVerb.Post,
                Payload            = JilDynamicObjectReaderTests.GetReader(body),
                ControllerRootPath = "https://whatever/SpApi/api/"
            };

            // Get service
            service = Factory.ConnectorService;

            // Place request
            response = service.HandleRequest(request);

            // Check result
            Assert.That(response, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.That(response.MessageResponse.PlatformMessageCode, Is.EqualTo("E1009"));
        }
Esempio n. 5
0
        public void Test_Resource_PostCreate( )
        {
            // Getting Forbidden? Or ConnectorConfigException?
            // Maybe there's duplicate copies of these objects in the DB.

            ConnectorRequest  request;
            ConnectorResponse response;
            IConnectorService service;
            string            tenantName = "EDC";

            CreateScenarioImpl(null, () => new [] { Permissions.Create });

            // Define request
            request = new ConnectorRequest
            {
                TenantName  = TenantName,
                QueryString = new Dictionary <string, string> {
                    { "key", ApiKey }
                },
                ApiPath            = new[] { ApiAddress, EndpointAddress },
                Verb               = ConnectorVerb.Post,
                Payload            = JilDynamicObjectReaderTests.GetReader(@"{ ""field1"":""hello"", ""lookup1"":""" + foreignName + @""", ""rel1"":[""" + foreignName + @"""] }"),
                ControllerRootPath = "https://whatever/SpApi/api/"
            };

            // Get service
            service = Factory.ConnectorService;

            // Place request
            response = service.HandleRequest(request);

            // Check result
            Assert.That(response, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created));
            Assert.That(response.Headers["Location"], Is.Not.Null);
            string location       = response.Headers ["Location"];
            string expectedPrefix = "https://whatever/SpApi/api/" + tenantName + "/" + ApiAddress + "/" + EndpointAddress + "/";

            Assert.That(location, Is.StringStarting(expectedPrefix));
            string suffix = location.Substring(expectedPrefix.Length);
            Guid   guid;

            Assert.That(Guid.TryParse(suffix, out guid), Is.True);

            // Check instance got created
            using (new TenantAdministratorContext(TenantName))
            {
                var instances = Entity.GetInstancesOfType(type.Id).ToList( );
                Assert.That(instances, Has.Count.EqualTo(1));
                IEntity instance = instances [0];

                string fieldValue = instance.GetField <string>(stringField);
                Assert.That(fieldValue, Is.EqualTo("hello"));

                var relInst = instance.GetRelationships(relationship).First();
                Assert.That(relInst.Id, Is.EqualTo(foreignInstance.Id));
            }
        }
Esempio n. 6
0
        public void Test_Resource_PutUpdate( )
        {
            // Getting Forbidden? Or ConnectorConfigException?
            // Maybe there's duplicate copies of these objects in the DB.

            ConnectorRequest  request;
            ConnectorResponse response;
            IConnectorService service;
            string            resourceName = "ResourceToUpdate";

            CreateScenarioImpl(resourceName, () => new [] { Permissions.Read, Permissions.Modify });

            // Define request
            request = new ConnectorRequest
            {
                TenantName  = TenantName,
                QueryString = new Dictionary <string, string> {
                    { "key", ApiKey }
                },
                ApiPath = new [] { ApiAddress, EndpointAddress, resourceName },
                Verb    = ConnectorVerb.Put,
                Payload = JilDynamicObjectReaderTests.GetReader(@"{ ""field1"":""hello"", ""lookup1"":""" + foreignName + @""", ""rel1"":[""" + foreignName + @"""] }")
            };

            // Get service
            service = Factory.ConnectorService;

            // Place request
            response = service.HandleRequest(request);

            // Check result
            Assert.That(response, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));

            // Check instance got created
            using (new TenantAdministratorContext(TenantName))
            {
                var instances = Entity.GetInstancesOfType(type.Id).ToList( );
                Assert.That(instances, Has.Count.EqualTo(1));
                IEntity instance = instances [0];

                string fieldValue = instance.GetField <string>(stringField);
                Assert.That(fieldValue, Is.EqualTo("hello"));

                var relInst = instance.GetRelationships(relationship).First( );
                Assert.That(relInst.Id, Is.EqualTo(foreignInstance.Id));
            }
        }
Esempio n. 7
0
        public void Test_Resource_PostCreate_WithoutOptionalRels_Bug26778()
        {
            ConnectorRequest  request;
            ConnectorResponse response;
            IConnectorService service;

            CreateScenarioImpl(null, () => new[] { Permissions.Create });

            // Define request
            request = new ConnectorRequest
            {
                TenantName  = TenantName,
                QueryString = new Dictionary <string, string> {
                    { "key", ApiKey }
                },
                ApiPath            = new[] { ApiAddress, EndpointAddress },
                Verb               = ConnectorVerb.Post,
                Payload            = JilDynamicObjectReaderTests.GetReader(@"{ ""field1"":""hello"" }"),
                ControllerRootPath = "https://whatever/SpApi/api/"
            };

            // Get service
            service = Factory.ConnectorService;

            // Place request
            response = service.HandleRequest(request);

            // Check result
            Assert.That(response, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created));

            // Check instance got created
            using (new TenantAdministratorContext(TenantName))
            {
                var instances = Entity.GetInstancesOfType(type.Id).ToList();
                Assert.That(instances, Has.Count.EqualTo(1));
                IEntity instance = instances[0];
            }
        }