public async Task TestBindAuthAsync() { string token = await Utils.GetTestToken(); string authResponsePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ApiResults", "ValidAuthResponse.json"); string authResponse = File.ReadAllText(authResponsePath); string testResultPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ApiResults", "GetTokenSuccessResult.json"); string json = File.ReadAllText(testResultPath); JObject jObject = JObject.Parse(json); jObject["access_token"] = token; json = JsonConvert.SerializeObject(jObject); Guid clientId = Guid.NewGuid(); var mocks = Utils.CreateDefaultGraphApiMock(json); await Utils.SetOneValueDbContextAsync(clientId); BotDbContext db = Utils.CreateMemoryDbContext(); DefaultGraphApi defaultGraphApi = new DefaultGraphApi(db, mocks.Item1, mocks.Item2); string name = "test Bind"; BindHandler bindHandler = new BindHandler(db, defaultGraphApi); await bindHandler.BindAuthAsync(clientId.ToString(), authResponse, name); await db.DisposeAsync(); db = Utils.CreateMemoryDbContext(); Assert.AreEqual(2, await db.AppAuths.AsQueryable().CountAsync()); Assert.IsTrue(await db.AppAuths.AsQueryable().AnyAsync(appAuth => appAuth.Name == name)); }
public async Task TestBindAuthInvalidAuthAsync() { string authResponsePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ApiResults", "InvalidAuthResponse.json"); string authResponse = File.ReadAllText(authResponsePath); BindHandler bindHandler = new BindHandler(null, null); await bindHandler.BindAuthAsync(Guid.Empty.ToString(), authResponse, string.Empty); }
public async Task TestBindAuthErrorFormatAsync() { BindHandler bindHandler = new BindHandler(null, null); await bindHandler.BindAuthAsync(Guid.Empty.ToString(), string.Empty, string.Empty); }
public async Task TestBindAuthInvalidJsonAsync() { string authResponse = @"{ ""Hi"": ""123"" }"; BindHandler bindHandler = new BindHandler(null, null); await bindHandler.BindAuthAsync(Guid.Empty.ToString(), authResponse, string.Empty); }