public async Task UserLogin() { SCLM sclm = new SCLM(); StoryToken token = await sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, Settings.Username, Settings.Password); Assert.NotNull(token); Assert.NotNull(token.AccessToken); Assert.NotNull(token.RefreshToken); IEnumerable <object> objects = await sclm.GETAsync <IEnumerable <object> >(new Uri($"{sclm.GetEndpoint("api")}/v1/users/"), CancellationToken.None); Assert.NotNull(objects); await Task.Delay(5000); objects = await sclm.GETAsync <IEnumerable <object> >(new Uri($"{sclm.GetEndpoint("api")}/v1/users/"), CancellationToken.None); Assert.NotNull(objects); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, Settings.Username, null)); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, null, Settings.Password)); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, null, null)); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId, null, Settings.Username, Settings.Password)); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret + "w", Settings.Username, Settings.Password)); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId + "s", Settings.UserSecret, Settings.Username, Settings.Password)); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(null, Settings.UserSecret, Settings.Username, Settings.Password)); }
public async Task RefreshWhile() { SCLM sclm = new SCLM(); StoryToken token = await sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, Settings.Username, Settings.Password); Assert.NotNull(token.RefreshToken); string rToken = token.RefreshToken; for (int i = 0; i < 1000; i++) { var t1 = await sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, rToken); Assert.NotNull(t1.RefreshToken); rToken = t1.RefreshToken; } }
public async void GetTables(int id) { SCLM sclm = SCLM.Instance; await sclm.AuthAsync(clientId, secret); IEnumerable <ApiTable> tables = await sclm.GetTablesAsync(id); ApiTable table = tables.FirstOrDefault(t => t.Name.Contains("Profile")); Assert.True(tables.Count() > 0); Assert.NotNull(table); }
public async Task ServiceLogin() { SCLM sclm = new SCLM(); sclm.SetEndpoint("auth", Settings.AuthEndpoint); StoryToken token = await sclm.AuthAsync(Settings.ServiceClientId, Settings.ServiceSecret); Assert.NotNull(token); Assert.NotNull(token.AccessToken); Assert.Null(token.RefreshToken); IEnumerable <object> objects = await sclm.GETAsync <IEnumerable <object> >(new Uri($"{sclm.GetEndpoint("api")}/v1/users/"), CancellationToken.None); Assert.NotNull(objects); await Task.Delay(5000); objects = await sclm.GETAsync <IEnumerable <object> >(new Uri($"{sclm.GetEndpoint("api")}/v1/users/"), CancellationToken.None); Assert.NotNull(objects); await Assert.ThrowsAsync <Exception>(async() => await sclm.AuthAsync(Settings.ServiceClientId, null)); await Assert.ThrowsAsync <Exception>(async() => await sclm.AuthAsync(null, Settings.ServiceSecret)); await Assert.ThrowsAsync <Exception>(async() => await sclm.AuthAsync(Settings.ServiceClientId + "sdf", Settings.ServiceSecret)); await Assert.ThrowsAsync <Exception>(async() => await sclm.AuthAsync(Settings.ServiceClientId, Settings.ServiceSecret + "sadf")); await Assert.ThrowsAsync <Exception>(async() => await sclm.AuthAsync(Settings.ServiceClientId + "sdf", Settings.ServiceSecret + "we")); }
public async void Insert(int tableId) { SCLM sclm = SCLM.Instance; await sclm.AuthAsync(clientId, secret); Profile profile = await sclm.InsertAsync <Profile>(tableId, Profile.CreateProfile()); Assert.NotNull(profile); List <Profile> profiles = new List <Profile>(await sclm.InsertAsync <Profile>(tableId, Profile.CreateProfiles())); Assert.NotNull(profiles); Assert.True(profiles.Count() == 3); }
public async Task Pipeline() { TestDecorator testDecorator = new TestDecorator(); SCLM sclm = new SCLM(); sclm.AddHttpDecorator(testDecorator); Assert.NotNull(sclm.GetHttpDecorator <TestDecorator>()); await sclm.AuthAsync(Settings.ServiceClientId, Settings.ServiceSecret); IEnumerable <object> objects = await sclm.GETAsync <IEnumerable <object> >(new Uri($"{sclm.GetEndpoint("api")}/v1/users/"), CancellationToken.None); Assert.True(testDecorator.Executed && testDecorator.Executing); }
public async void Count(int tableId) { SCLM sclm = SCLM.Instance; await sclm.AuthAsync(clientId, secret); long count = await sclm.CountAsync(tableId); Assert.True(count > 0); count = await sclm.CountAsync(tableId, "[Gender][eq][false]"); Assert.True(count > 0); count = await sclm.LogCountAsync(tableId); Assert.True(count > 0); count = await sclm.LogCountAsync(tableId, DateTime.Now.AddDays(-5)); Assert.True(count > 0); }
public async Task RetryLinar() { SCLM sclm = new SCLM(); await sclm.AuthAsync(Settings.ServiceClientId, Settings.ServiceSecret); var retryCommand = new RetryCommand(new TimeoutException()) { Uri = new Uri($"{sclm.GetEndpoint("api")}v1/users/"), Method = "GET", }; await sclm.ExecuteHttpCommand(retryCommand, new RetryPolicy() { ExponentialBackoff = false, Interval = TimeSpan.FromMilliseconds(50), RetriesCount = 10 }, CancellationToken.None); Assert.NotNull(retryCommand.Exception); }
public async Task Delete(int tableId) { SCLM sclm = SCLM.Instance; await sclm.AuthAsync(clientId, secret); IEnumerable <Profile> results = await sclm.FindAsync <Profile>(tableId, skip : 0, take : 1000); Assert.True(results.Count() > 0); Profile deleteResult = await sclm.DeleteAsync <Profile>(tableId, results.First()._id); Assert.NotNull(deleteResult); results = await sclm.FindAsync <Profile>(tableId, skip : 0, take : 60); Assert.True(results.Count() > 0); IEnumerable <Profile> deleteResults = await sclm.DeleteAsync <Profile>(tableId, results.Select(t => t._id)); Assert.True(deleteResults.Count() > 0); }
public async void Log(int tableId) { SCLM sclm = SCLM.Instance; await sclm.AuthAsync(clientId, secret); IEnumerable <ApiLog> logs = await sclm.LogAsync(tableId, DateTime.Now.AddDays(-5), 0, 900); Assert.True(logs.Count() > 0); logs = await sclm.LogAsync(tableId, DateTime.Now.AddDays(-5)); Assert.True(logs.Count() > 0); logs = await sclm.LogAsync(tableId, skip : 0, take : 900); Assert.True(logs.Count() > 0); logs = await sclm.LogAsync(tableId); Assert.True(logs.Count() > 0); }
public static async Task <SCLM> GetContextAsync(int uc) { switch (uc) { case 0: // service { SCLM sclm = new SCLM(); await sclm.AuthAsync(Settings.Get().ServiceClientId, Settings.Get().ServiceSecret); return(sclm); } case 1: // application (user) { SCLM sclm = new SCLM(); await sclm.AuthAsync(Settings.Get().UserClientId, Settings.Get().UserSecret, Settings.Get().Username, Settings.Get().Password); return(sclm); } } return(null); }
public async Task Refresh() { SCLM sclm = new SCLM(); StoryToken token = await sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, Settings.Username, Settings.Password); Assert.NotNull(token.RefreshToken); var token1 = await sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, token.RefreshToken); Assert.NotNull(token1.RefreshToken); var token2 = await sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, token1.RefreshToken); Assert.NotNull(token2.RefreshToken); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, token.RefreshToken)); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, null)); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId, Settings.UserSecret, token.RefreshToken + "sdfsdf")); await Assert.ThrowsAsync <Exception>(() => sclm.AuthAsync(Settings.UserClientId, null, token2.RefreshToken)); }
public async void Find(int tableId) { SCLM sclm = SCLM.Instance; await sclm.AuthAsync(clientId, secret); Profile profile = await sclm.InsertAsync <Profile>(tableId, Profile.CreateProfile()); profile = await sclm.InsertAsync <Profile>(tableId, Profile.CreateProfile1()); profile = await sclm.InsertAsync <Profile>(tableId, Profile.CreateProfile2()); profile = await sclm.InsertAsync <Profile>(tableId, Profile.CreateProfile3()); profile = await sclm.InsertAsync <Profile>(tableId, Profile.CreateProfile4()); List <Profile> profiles = new List <Profile>(await sclm.InsertAsync <Profile>(tableId, Profile.CreateProfiles())); //Получить объект по идентификатору profile = await sclm.FindAsync <Profile>(tableId, profile._id); Assert.NotNull(profile); //Получить коллекцию записей по списку идентификаторов IEnumerable <Profile> results = await sclm.FindAsync <Profile>(tableId, profiles.Select(t => t._id).ToArray()); Assert.True(results.Count() > 0); results = await sclm.FindAsync <Profile>(tableId, "[Gender][eq][false]", "age", 1, 0, 100); Assert.True(results.Count() > 0); results = await sclm.FindAsync <Profile>(tableId, sortfield : "age", sort : 1, skip : 0, take : 100); Assert.True(results.Count() > 0); results = await sclm.FindAsync <Profile>(tableId, sortfield : "age", skip : 0, take : 100); Assert.True(results.Count() > 0); results = await sclm.FindAsync <Profile>(tableId, skip : 0, take : 100); Assert.True(results.Count() > 0); results = await sclm.FindAsync <Profile>(tableId); Assert.True(results.Count() > 0); //возраст меньше или равен 30 results = sclm.FindAsync <Profile>(tableId, "[age][lte][30]", "age", 1, 0, 100).Result; Assert.True(results.Count() > 0); //поле "name" начинается с символа "T" results = sclm.FindAsync <Profile>(tableId, "[name][sw][\"T\"]", "age", 1, 0, 100).Result; Assert.True(results.Count() > 0); //поле "name" содержит строку "ad" results = sclm.FindAsync <Profile>(tableId, "[Name][cn][\"ad\"]", "age", 1, 0, 100).Result; Assert.True(results.Count() > 0); //поиск имен из списка results = sclm.FindAsync <Profile>(tableId, "[Name][in][\"Stanislav\",\"Tamerlan\"]", "age", 1, 0, 100).Result; Assert.True(results.Count() > 0); //Выбрать женщин, имя ("name") которых начинается со строки "V" results = sclm.FindAsync <Profile>(tableId, "[gender][eq][false][and][Name][sw][\"V\"]", "age", 1, 0, 100).Result; Assert.True(results.Count() > 0); //Выбрать мужчин младше 30 и женщин старше 30 results = sclm.FindAsync <Profile>(tableId, "[gender][eq][true][and][age][lt][30][or][gender][eq][false][and][age][gt][30]", "age", 1, 0, 100).Result; Assert.True(results.Count() > 0); #region сложные запросы со скобочками //поле "name" начинается с символов "T" или "S" при этом возраст должен быть равен 22 results = sclm.FindAsync <Profile>(tableId, "([name][sw][\"S\"][or][name][sw][\"T\"])[and][age][eq][22]", "age", 1, 0, 100).Result; Assert.True(results.Count() > 0); //Выбрать всех с возрастом НЕ в интервале [25,30] и с именами на "S" и "Т" results = sclm.FindAsync <Profile>(tableId, "([age][lt][22][or][age][gt][30])[and]([name][sw][\"S\"][or][name][sw][\"T\"])", "age", 1, 0, 100).Result; // Assert.True(results.Count() > 0); #endregion }
public async void Aggregation(int tableId) { SCLM sclm = SCLM.Instance; await sclm.AuthAsync(clientId, secret); var boolResult = await sclm.MaxAsync <bool>(tableId, "Gender"); var intResult = await sclm.MaxAsync <int>(tableId, "Age"); var stringResult = await sclm.MaxAsync <string>(tableId, "Name"); var datetimeResult = await sclm.MaxAsync <DateTime>(tableId, "Created"); var doubleResult = await sclm.MaxAsync <double>(tableId, "Rating"); var boolQueryResult = await sclm.MaxAsync <bool>(tableId, "Gender", "[Gender][eq][false]"); var intQueryResult = await sclm.MaxAsync <int>(tableId, "Age", "[Gender][eq][false]"); var stringQueryResult = await sclm.MaxAsync <string>(tableId, "Name", "[Gender][eq][false]"); var datetimeQueryResult = await sclm.MaxAsync <DateTime>(tableId, "Created", "[Gender][eq][false]"); var doubleQueryResult = await sclm.MaxAsync <double>(tableId, "Rating", "[Gender][eq][false]"); var boolMinResult = await sclm.MinAsync <bool>(tableId, "Gender"); var intMinResult = await sclm.MinAsync <int>(tableId, "Age"); var stringMinResult = await sclm.MinAsync <string>(tableId, "Name"); var datetimeMinResult = await sclm.MinAsync <DateTime>(tableId, "Created"); var doubleMinResult = await sclm.MinAsync <double>(tableId, "Rating"); var boolQueryMinResult = await sclm.MinAsync <bool>(tableId, "Gender", "[Gender][eq][true]"); var intQueryMinResult = await sclm.MinAsync <int>(tableId, "Age", "[Gender][eq][true]"); var stringQueryMinResult = await sclm.MinAsync <string>(tableId, "Name", "[Gender][eq][true]"); var datetimeQueryMinResult = await sclm.MinAsync <DateTime>(tableId, "Created", "[Gender][eq][true]"); var doubleQueryMinResult = await sclm.MinAsync <double>(tableId, "Rating", "[Gender][eq][false]"); var boolSumResult = await sclm.SumAsync <bool>(tableId, "Gender"); var intSumResult = await sclm.SumAsync <long>(tableId, "Age"); var doubleSumResult = await sclm.SumAsync <double>(tableId, "Rating"); var boolQuerySumResult = await sclm.SumAsync <bool>(tableId, "Gender", "[Gender][eq][true]"); var intQuerySumResult = await sclm.SumAsync <int>(tableId, "Age", "[Gender][eq][true]"); var doubleQuerySumResult = await sclm.SumAsync <double>(tableId, "Rating", "[Gender][eq][false]"); var intAvgResult = await sclm.AvgAsync(tableId, "Age"); var doubleAvgResult = await sclm.AvgAsync(tableId, "Rating"); var intQueryAvgResult = await sclm.AvgAsync(tableId, "Age", "[Gender][eq][true]"); var doubleQueryAvgResult = await sclm.AvgAsync(tableId, "Rating", "[Gender][eq][false]"); Profile profile = await sclm.FirstAsync <Profile>(tableId, "[Age][eq][33]", "age", 1); Profile profile1 = await sclm.FirstAsync <Profile>(tableId, sortfield : "age", sort : 1); Profile profile2 = await sclm.FirstAsync <Profile>(tableId, sortfield : "age"); Profile profile3 = await sclm.FirstAsync <Profile>(tableId); Profile profile4 = await sclm.LastAsync <Profile>(tableId, "[Age][eq][22]", "age", 1); Profile profile5 = await sclm.LastAsync <Profile>(tableId, sortfield : "age", sort : 1); Profile profile6 = await sclm.LastAsync <Profile>(tableId, sortfield : "age"); Profile profile7 = await sclm.LastAsync <Profile>(tableId); }