static void createViews() { // membership_user var url = new StringBuilder(getBaseUrl()).Append(MembershipCouchDbDatabaseName).Append("/_design/membership_user").ToString(); var http = new HttpClient(); http.Request.Accept = "application/json"; string all_view = "function(doc) { if(doc.type == 'CouchDbMembershipUser') { emit(doc.UserName, doc) ; } }"; string all_by_email = "function(doc) { if(doc.UserName) { emit(doc.Email, doc); }}"; string by_single_role = "function(doc) { if(doc.type == 'CouchDbMembershipUser') { if(doc.Roles.length > 0) { for(var idx in doc.Roles) { emit(doc.Roles[idx], doc); } } } }"; var all_map = new { map = all_view }; var all_by_email_map = new { map = all_by_email }; var by_single_role_map = new { map = by_single_role }; var views_document = new { _id = "_design/membership_user", views = new { all = all_map, all_by_email = all_by_email_map, by_single_role = by_single_role_map } }; http.Put(url, views_document, "application/json"); }
static System.Net.HttpStatusCode createDatabase() { var url = new StringBuilder(getBaseUrl()).Append(MembershipCouchDbDatabaseName).ToString(); var http = new HttpClient(); http.Request.Accept = "application/json"; http.Put(url, String.Empty, "application/json"); return http.Response.StatusCode; }
public void PUT_DidNotExist_NotFound() { var repository = Substitute.For<ITranslationRepository>(); Replacing(repository); repository.Update(Arg.Any<TranslationMdl>()).Returns(false); var client = new HttpClient(); HttpResponse response = client.Put(UrlFor("/translation/DK/es"), new TranslationMsg { Data = "Dinamarca" }, HttpContentTypes.ApplicationJson); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); }
public void PUT_AlreadyExists_Ok() { string code = "DK", language = "es", data = "Dinamarca"; var repository = Substitute.For<ITranslationRepository>(); Replacing(repository); repository.Update( Arg.Is<TranslationMdl>(m => m.Language == language && m.Alpha2 == code && m.Name == data)) .Returns(true); var client = new HttpClient(); client.Request.Accept = HttpContentTypes.ApplicationJson; HttpResponse response = client.Put(UrlFor("/translation/{0}/{1}", code, language), new TranslationMsg { Data = data }, HttpContentTypes.ApplicationJson); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(response.DynamicBody.success, Is.True); var expectedUri = new Uri(BaseUrl, new Uri("/translation/DK/es", UriKind.Relative)); Assert.That(response.DynamicBody.uri, Is.EqualTo(expectedUri.ToString())); }
public void PUT_LanguageNotSupported_BadRequest() { var client = new HttpClient(); HttpResponse response = client.Put(UrlFor("/translation/ES/notSupported"), new TranslationMsg { Data = "something" }, HttpContentTypes.ApplicationJson); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest)); }
public void PUT_WrongUrl_NotFound() { var client = new HttpClient(); HttpResponse response = client.Put(UrlFor("/translation"), new TranslationMsg(), HttpContentTypes.ApplicationJson); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); }