public object CoopCloseStore() { //BearerAccessToken bearerAccessToken = new BearerAccessToken("f0cabde6bb8d4bd78c28270ee203253f"); /* Code #1 */ //BearerAccessToken bearerAccessToken = new BearerAccessToken("d0b9a5266a2749cda99d4468319b6d9f"); /* Code #2 */ BearerAccessToken bearerAccessToken = new BearerAccessToken(_token); // Create link to a store with radius as input string url = linkMaker.GetRadiusLink(10000); // Open the link using the url and token OpenHttp <CoopStoreApi> openHttp = new OpenHttp <CoopStoreApi>(url, bearerAccessToken.GetBearerToken()); // Parse CoopStoreApi stuff = openHttp.ReadAndParseAPISingle(); // Create list for StoreId in the different stores found inside the radius //List<int> storId = new List<int>(); // Fill the StoreId list with Kardex (storeid) for the different stores //foreach (var product in stuff.Data) //{ // storId.Add(product.Kardex); //} //foreach (var store in stuff.Data) //{ // Console.WriteLine(store.RetailGroupName + " - " + store.Kardex + " - " + store.Address + " - " + store.Zipcode); //} return(stuff); }
internal void ResetAccessToken(BearerAccessToken newToken, DateTimeOffset issuedDateTime) { AccessToken = newToken.AccessToken; ExpiresIn = newToken.ExpiresIn; Scope = newToken.Scope; Expires = newToken.Expires ?? issuedDateTime.AddSeconds(ExpiresIn); }
public async Task GetUserAccessToken_TokenExpired_ReturnsNewToken() { // arrange var expiredToken = new BearerAccessToken { AccessToken = "abcd1234", ExpiresIn = 3600, Expires = new DateTime(2018, 7, 28, 9, 18, 0, DateTimeKind.Utc) }; const string json = @"{ ""access_token"": ""NgCXRKc...MzYjw"", ""token_type"": ""bearer"", ""expires_in"": 3600, }"; var mockHttp = new MockHttpClient(); mockHttp.SetupSendAsync(json); var http = mockHttp.HttpClient; var bearerTokenStore = new Mock <IBearerTokenStore>(); bearerTokenStore.Setup(s => s.Get(It.IsAny <string>())).ReturnsAsync(expiredToken); var config = new MockConfiguration().Object; var refreshTokenStore = new MockRefreshTokenStore(UserHash, config).Object; var service = new UserAccountsService(http, config, refreshTokenStore, bearerTokenStore.Object); // act var token = await service.GetUserAccessToken(UserHash); // assert Assert.AreNotEqual(expiredToken, token); }
public async Task GetUserAccessToken_TokenNotExpired_ReturnsCurrentToken() { // arrange var currentToken = new BearerAccessToken { AccessToken = "abcd1234", ExpiresIn = 3600, Expires = DateTime.UtcNow.AddSeconds(3600) }; var http = new MockHttpClient().HttpClient; var bearerTokenStore = new Mock <IBearerTokenStore>(); bearerTokenStore.Setup(s => s.Get(It.IsAny <string>())).ReturnsAsync(currentToken); var config = new MockConfiguration().Object; var refreshTokenStore = new MockRefreshTokenStore(UserHash, config).Object; var service = new UserAccountsService(http, config, refreshTokenStore, bearerTokenStore.Object); // act var token = await service.GetUserAccessToken(UserHash); // assert Assert.AreEqual(currentToken, token); }
public User( ConversationInfo info, string userId = null, string username = null, BearerAccessToken spotifyAccessToken = null) { var now = DateTime.UtcNow; (string id, string pk) = EncodeIds(info, userId ?? info.FromId); Id = id; PartitionKey = pk; Type = TypeName; UserId = userId ?? info.FromId; Username = username ?? info.FromName; ChannelId = info.ChannelId; ChannelTeamId = info.ChannelTeamId; CreatedDate = now; if (spotifyAccessToken != null) { SpotifyAuth = new Auth { BearerAccessToken = spotifyAccessToken, CreatedDate = now }; } }
public MockAccountsService() { var token = new BearerAccessToken { AccessToken = "abcd1234", ExpiresIn = 3600 }; token.SetExpires(DateTime.UtcNow); Setup(s => s.GetAppAccessToken()).ReturnsAsync(token); }
public List <CoopProduct> CoopFindEverythingInStore(string storeId) { BearerAccessToken bearerAccessToken = new BearerAccessToken(_token); OpenHttp <CoopProduct> openHttpStore = new OpenHttp <CoopProduct>(bearerAccessToken.GetBearerToken()); string url = linkMaker.GetProductLinke(storeId); openHttpStore.ChangeUrl(url); List <CoopProduct> coopProducts = openHttpStore.ReadAndParseAPI(); return(coopProducts); }
public void SetExpires_ExpiresIn3600_ExpiryIs1HourGreaterThanNow() { // arrange var token = new BearerAccessToken { ExpiresIn = 3600 }; var now = DateTime.UtcNow; // act token.SetExpires(now); // assert Assert.AreEqual(now.AddSeconds(3600), token.Expires.Value); }
public void SetExpires_NowIsUtcDate_ReturnsUtcDate() { // arrange var token = new BearerAccessToken { ExpiresIn = 3600 }; var now = DateTime.UtcNow; // act token.SetExpires(now); // assert Assert.AreEqual(token.Expires.Value.Kind, DateTimeKind.Utc); }
/// <summary> /// If a searchterms yields no results in the databae then this methos is used to check for results in the salling api(currently disabled because of technical issus on sallings side) /// </summary> /// <param name="Searchterm"></param> /// <returns>returns bool based on wheter or not any products are found to match the serchterm</returns> private bool CheckIngredientsInApi(string Searchterm) { System.Threading.Thread.Sleep(4000); BearerAccessToken bearerAccessToken = new BearerAccessToken("fc5aefca-c70f-4e59-aaaa-1c4603607df8"); SallingAPILink linkMaker = new SallingAPILink(); SallingAPIProductSuggestions productSuggestions = new SallingAPIProductSuggestions(); string apiLink = linkMaker.GetProductAPILink(Searchterm); OpenHttp <SallingAPIProductSuggestions> openHttp; try { openHttp = new OpenHttp <SallingAPIProductSuggestions>(apiLink, bearerAccessToken.GetBearerToken()); productSuggestions = openHttp.ReadAndParseAPISingle(); if (productSuggestions.Suggestions != null) { foreach (var p in productSuggestions.Suggestions) { dc.Product.Add(new Product(p.title, p.id, p.prod_id, p.price, p.description, p.link, p.img)); } } } catch (System.Net.WebException) { Console.WriteLine("Exception found is being handled"); System.Threading.Thread.Sleep(30000); Console.WriteLine("Exception resolved"); return(false); } if (productSuggestions.Suggestions != null) { return(productSuggestions.Suggestions.Count != 0 ? true : false); } else { return(false); } }
public List <Product> SearchForProducts(String searchterm) { BearerAccessToken bearerAccessToken = new BearerAccessToken("fc5aefca-c70f-4e59-aaaa-1c4603607df8"); SallingAPILink linkMaker = new SallingAPILink(); SallingAPIProductSuggestions productSuggestions = new SallingAPIProductSuggestions(); // Creates a link to the Salling api with the searchterm as input string apiLink = linkMaker.GetProductAPILink(searchterm); OpenHttp <SallingAPIProductSuggestions> openHttp; List <Product> returnList = new List <Product>(); try { // Opens the Salling API openHttp = new OpenHttp <SallingAPIProductSuggestions>(apiLink, bearerAccessToken.GetBearerToken()); // Parsese the returned Json string into a list of SallingAPIProduct productSuggestions = openHttp.ReadAndParseAPISingle(); if (productSuggestions.Suggestions.Count != 0) { foreach (SallingAPIProduct products in productSuggestions.Suggestions) { // Adds all SallingAPIProduct to the returnList and converts them all to the class Product returnList.Add(new Product(products.id, products.title, products.description, products.price, products.img, "Bilka")); } } } catch (WebException e) { // If there is an error while loading the Salling api. Console.WriteLine("This program is expected to throw WebException on successful run." + "\n\nException Message :" + e.Message); } return(returnList); }
public async Task SaveUserAccessToken_StateTokenSet_StateTokenStillSet() { // arrange const string state = "abc123"; const string userId = "def456"; var token = new BearerAccessToken(); var user = new User { SpotifyAuth = new Auth { State = state } }; var mockLogger = new Mock <ILogger <UserData> >(); // mock IConfiguration var mockConfiguration = new Mock <IConfiguration>(); mockConfiguration.SetReturnsDefault("ghi789"); mockConfiguration.Setup(c => c[ConfigHelper.CosmosDBEndpoint]).Returns("https://localtest.me/"); mockConfiguration.Setup(c => c[ConfigHelper.CosmosDBPrimaryKey]).Returns("aGVsbG93b3JsZA=="); // Use Moq to create a Class Under Test. Mock out the Read and Replace methods var dataCut = new Mock <UserData>(mockConfiguration.Object, mockLogger.Object) { CallBase = true }; dataCut.Setup(d => d.Read <User>(It.IsAny <(string, string)>())).ReturnsAsync(user); dataCut.Setup(d => d.Replace(It.IsAny <CosmosEntity>())).Returns(Task.CompletedTask); // act await dataCut.Object.SaveUserAccessToken(userId, token); // assert Assert.AreEqual(state, user.SpotifyAuth.State); }
public void BearerAccessTokenEnforceInvariants_ExpiresNotSet_Throws() { var token = new BearerAccessToken(); token.EnforceInvariants(); }
public Auth(BearerAccessToken accessToken) { BearerAccessToken = accessToken; CreatedDate = DateTime.UtcNow; }