public async Task Post_Is_400_Validation_Property_Required() { var startup = new TestStartup( //This will be invoked before the controller is created so we can modify these mocked services (testServices) => { MockServicesForAuthorizationSuccess(testServices, 456); MediaServiceMocks.SetupMocksForPost(testServices.ServiceContext); var mockPropertyEditor = Mock.Get(PropertyEditorResolver.Current); mockPropertyEditor.Setup(x => x.GetByAlias("testEditor")).Returns(new ModelMocks.SimplePropertyEditor()); }); using (var server = TestServer.Create(builder => startup.UseDefaultTestSetup(builder))) { var request = new HttpRequestMessage() { RequestUri = new Uri(string.Format("http://testserver/umbraco/rest/v1/{0}", RouteConstants.MediaSegment)), Method = HttpMethod.Post, }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/hal+json")); //NOTE: it is missing request.Content = new StringContent(@"{ ""name"": ""test"", ""contentTypeAlias"": ""test"", ""parentId"": 456, ""templateId"": 9, ""properties"": { ""TestProperty1"": """", ""testProperty2"": ""property value2"" } }", Encoding.UTF8, "application/json"); Console.WriteLine(request); var result = await server.HttpClient.SendAsync(request); Console.WriteLine(result); var json = await((StreamContent)result.Content).ReadAsStringAsync(); Console.Write(JsonConvert.SerializeObject(JsonConvert.DeserializeObject(json), Formatting.Indented)); Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); var djson = JsonConvert.DeserializeObject <JObject>(json); Assert.AreEqual(1, djson["totalResults"].Value <int>()); Assert.AreEqual("content.properties.TestProperty1.value", djson["_embedded"]["errors"][0]["logRef"].Value <string>()); } }
public async void Post_Is_400_Validation_Required_Fields() { var startup = new TestStartup( //This will be invoked before the controller is created so we can modify these mocked services (request, umbCtx, typedContent, serviceContext, searchProvider) => { MediaServiceMocks.SetupMocksForPost(serviceContext); }); using (var server = TestServer.Create(builder => startup.Configuration(builder))) { var request = new HttpRequestMessage() { RequestUri = new Uri(string.Format("http://testserver/umbraco/rest/v1/{0}", RouteConstants.MediaSegment)), Method = HttpMethod.Post, }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/hal+json")); //NOTE: it is missing request.Content = new StringContent(@"{ ""contentTypeAlias"": """", ""parentId"": 456, ""templateId"": 9, ""name"": """", ""properties"": { ""TestProperty1"": ""property value1"", ""testProperty2"": ""property value2"" } }", Encoding.UTF8, "application/json"); Console.WriteLine(request); var result = await server.HttpClient.SendAsync(request); Console.WriteLine(result); var json = await((StreamContent)result.Content).ReadAsStringAsync(); Console.Write(JsonConvert.SerializeObject(JsonConvert.DeserializeObject(json), Formatting.Indented)); Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); var djson = JsonConvert.DeserializeObject <JObject>(json); Assert.AreEqual(2, djson["totalResults"].Value <int>()); Assert.AreEqual("content.ContentTypeAlias", djson["_embedded"]["errors"][0]["logRef"].Value <string>()); Assert.AreEqual("content.Name", djson["_embedded"]["errors"][1]["logRef"].Value <string>()); } }
public async Task Put_Is_200_Response() { var startup = new TestStartup( //This will be invoked before the controller is created so we can modify these mocked services (testServices) => { MockServicesForAuthorizationSuccess(testServices, 456); MediaServiceMocks.SetupMocksForPost(testServices.ServiceContext); }); await base.Put_Is_200_Response(startup.UseDefaultTestSetup, RouteConstants.MediaSegment, new StringContent(@"{ ""contentTypeAlias"": ""testType"", ""parentId"": 456, ""templateId"": 9, ""name"": ""Home"", ""properties"": { ""TestProperty1"": ""property value1"", ""testProperty2"": ""property value2"" } }", Encoding.UTF8, "application/json")); }