public void TestReadAggregatorWithOneMaster() { ActODataService(args => { var author = new Автор { Имя = "TestAuthor" }; var magazine = new Журнал { Название = "TestMagazine", Номер = 30, Автор2 = author }; var book = new Книга { Название = "TestBook", Автор1 = author }; var library = new Библиотека { Адрес = "TestStreet" }; var dMagazines = new DetailArrayOfЖурнал(library); dMagazines.Add(magazine); var dBooks = new DetailArrayOfКнига(library); dBooks.Add(book); library.Книга = dBooks; library.Журнал = dMagazines; var objs = new DataObject[] { library, author, magazine, book }; args.DataService.UpdateObjects(ref objs); var view = Библиотека.Views.Eview; string viewUrl = ViewExtensions.ToODataQuery(view); string requestUrl = string.Format("http://localhost/odata/{0}?{1}", args.Token.Model.GetEdmEntitySet(typeof(Библиотека)).Name, viewUrl); using (HttpResponseMessage response = args.HttpClient.GetAsync(requestUrl).Result) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); string receivedStr = response.Content.ReadAsStringAsync().Result.Beautify(); Dictionary <string, object> receivedDict = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(receivedStr); Assert.Equal(1, ((ArrayList)receivedDict["value"]).Count); var value = ((ArrayList)receivedDict["value"])[0]; var журнал = ((ArrayList)((Dictionary <string, object>)value)["Журнал"])[0]; var авторЖурнала = ((Dictionary <string, object>)журнал)["Автор2"]; var авторЖурналаPK = (string)((Dictionary <string, object>)авторЖурнала)["__PrimaryKey"]; var книга = ((ArrayList)((Dictionary <string, object>)value)["Книга"])[0]; var авторКниги = ((Dictionary <string, object>)книга)["Автор1"]; var авторКнигиPK = (string)((Dictionary <string, object>)авторКниги)["__PrimaryKey"]; Assert.Equal(авторЖурналаPK, авторКнигиPK); } }); }
public void TestUsingUtfRequests() { ActODataService(args => { var author = new Автор { Имя = "TestAuthor" }; var magazine = new Журнал { Название = "TestMagazine", Номер = 30, Автор2 = author }; var book = new Книга { Название = "TestBook", Автор1 = author }; var library = new Библиотека { Адрес = "TestStreet" }; var dMagazines = new DetailArrayOfЖурнал(library); dMagazines.Add(magazine); var dBooks = new DetailArrayOfКнига(library); dBooks.Add(book); library.Книга = dBooks; library.Журнал = dMagazines; var objs = new DataObject[] { library, author, magazine, book }; args.DataService.UpdateObjects(ref objs); var view = Библиотека.Views.Eview; string viewUrl = ViewExtensions.ToODataQuery(view); var partUrlArr = new[] { new { Model = args.Token.Model.GetEdmEntitySet(typeof(Библиотека)).Name, Query = viewUrl }, new { Model = args.Token.Model.GetEdmEntitySet(typeof(Библиотека)).Name.Unicodify(), Query = string.Join("&", viewUrl.Split('&') .Select(i => string.Join("=", i.Split('=').Select(m => m.Unicodify()))) .ToArray()) } }; foreach (var item in partUrlArr) { string requestUrl = string.Format("http://localhost/odata/{0}?{1}", item.Model, item.Query); using (HttpResponseMessage response = args.HttpClient.GetAsync(requestUrl).Result) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); string receivedStr = response.Content.ReadAsStringAsync().Result.Beautify(); Dictionary <string, object> receivedDict = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(receivedStr); Assert.Equal(1, ((ArrayList)receivedDict["value"]).Count); } } }); }