protected void DrawLine(SKCanvas canvas, SKRect drawRect, LineConfiguration lineConfig) { // Create path var plot = new SKPath(); lineConfig.Drawer.CreatePath(plot, drawRect, lineConfig); // Draw the data canvas.DrawPath(plot, lineConfig.LinePaint); }
public void ThrowsNotExceptionWhenLoggerIsNull() { var configuration = new LineConfiguration() { ChannelAccessToken = "ChannelAccessToken", ChannelSecret = "ChannelSecret", }; new LineBot(configuration, null); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(typeof(ILineConfiguration), (IServiceProvider serviceProvider) => { var instance = new LineConfiguration(); //建立Line機器人實例 Configuration.Bind("LineConfiguration", instance); //綁定屬性 return(instance); }); services.AddSingleton(typeof(ILineBot), typeof(LineBot)); services.AddScoped(typeof(LineBotService)); services.InstallModules(Environment.ContentRootPath); }
public void ShouldReturnNewInstance() { LineConfiguration configuration = new LineConfiguration() { ChannelAccessToken = nameof(ShouldReturnNewInstance) }; HttpClient clientA = HttpClientFactory.Create(configuration, null); HttpClient clientB = HttpClientFactory.Create(configuration, null); Assert.AreNotEqual(clientA, clientB); }
public void Create_SameChannelAccessToken_ReturnsSameInstance() { LineConfiguration configuration = new LineConfiguration() { ChannelAccessToken = nameof(Create_SameChannelAccessToken_ReturnsSameInstance) }; HttpClient clientA = HttpClientFactory.Create(configuration); HttpClient clientB = HttpClientFactory.Create(configuration); Assert.AreEqual(clientA, clientB); }
public void ThrowsExceptionWhenChannelSecretTokenIsEmpty() { var configuration = new LineConfiguration() { ChannelAccessToken = "ChannelAccessToken", ChannelSecret = string.Empty, }; ExceptionAssert.ThrowsArgumentException("configuration", "The ChannelSecret cannot be null or whitespace.", () => { new LineBot(configuration); }); }
public void ThrowsExceptionWhenChannelAccessTokenIsWhitespace() { LineConfiguration configuration = new LineConfiguration() { ChannelAccessToken = " ", ChannelSecret = "ChannelSecret", }; ExceptionAssert.ThrowsArgumentException("configuration", "The ChannelAccessToken cannot be null or whitespace.", () => { new LineBot(configuration); }); }
public void Constructor_ChannelSecretTokenIsNull_ThrowsException() { LineConfiguration configuration = new LineConfiguration() { ChannelAccessToken = "ChannelAccessToken", ChannelSecret = null, }; ExceptionAssert.ThrowsArgumentException("configuration", "The ChannelSecret cannot be null or whitespace.", () => { new LineBot(configuration); }); }
public void ShouldReturnInitializedHttpClient() { LineConfiguration configuration = new LineConfiguration() { ChannelAccessToken = nameof(ShouldReturnInitializedHttpClient) }; HttpClient client = HttpClientFactory.Create(configuration, null); Assert.AreEqual(new Uri("https://api.line.me/v2/bot/"), client.BaseAddress); string authorization = client.DefaultRequestHeaders.GetValues("Authorization").First(); Assert.AreEqual("Bearer " + nameof(ShouldReturnInitializedHttpClient), authorization); }
public void ShouldSetInnerHandlerToLineBotLogger() { LineConfiguration configuration = new LineConfiguration() { ChannelAccessToken = nameof(ShouldReturnInitializedHttpClient) }; HttpClient client = HttpClientFactory.Create(configuration, null); FieldInfo field = client.GetType().BaseType.GetRuntimeFields().Where(f => f.Name == "_handler").First(); LoggingDelegatingHandler logger = field.GetValue(client) as LoggingDelegatingHandler; Assert.IsNotNull(logger); Assert.IsInstanceOfType(logger.InnerHandler, typeof(HttpClientHandler)); }
public void ShouldSetBaseAddressToApiWhenHttpFactoryIsUsed() { var configuration = new LineConfiguration() { ChannelAccessToken = "ChannelAccessToken", ChannelSecret = "ChannelSecret", }; ILineBot bot = new LineBot(configuration); var field = bot.GetType().GetRuntimeFields().Where(f => f.Name == "_client").First(); var client = (HttpClient)field.GetValue(bot); Assert.AreEqual(new Uri("https://api.line.me/v2/bot/"), client.BaseAddress); }
public void Constructor_HttpFactoryIsUsed_BaseAddressUsesApi() { LineConfiguration configuration = new LineConfiguration() { ChannelAccessToken = "ChannelAccessToken", ChannelSecret = "ChannelSecret", }; ILineBot bot = new LineBot(configuration); FieldInfo field = bot.GetType().GetRuntimeFields().Where(f => f.Name == "_client").First(); HttpClient client = (HttpClient)field.GetValue(bot); Assert.AreEqual(new Uri("https://api.line.me/v2/bot/"), client.BaseAddress); }
public void Create_DifferentChannelAccessToken_ReturnsDifferentInstance() { LineConfiguration configurationA = new LineConfiguration() { ChannelAccessToken = $"{nameof(Create_DifferentChannelAccessToken_ReturnsDifferentInstance)}A" }; LineConfiguration configurationB = new LineConfiguration() { ChannelAccessToken = $"{nameof(Create_DifferentChannelAccessToken_ReturnsDifferentInstance)}B" }; HttpClient clientA = HttpClientFactory.Create(configurationA); HttpClient clientB = HttpClientFactory.Create(configurationB); Assert.AreNotEqual(clientA, clientB); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(typeof(ILineConfiguration), (IServiceProvider serviceProvider) => { var instance = new LineConfiguration(); //建立Line機器人實例 Configuration.Bind("LineConfiguration", instance); //綁定屬性 return(instance); }); services.AddSingleton(typeof(ILineBot), typeof(Line.LineBot)); PluginManager.Instance.ConfigurePlugin( services, typeof(EchoResponder).Assembly, typeof(PttBeautyResponder).Assembly, typeof(WeatherResponder).Assembly, typeof(CiController).Assembly ) .GetAwaiter().GetResult(); }
private bool TryGetValuesPackages(LineConfiguration aLineConfiguration, out ValuesPackage aPackage) { aPackage = new ValuesPackage(); aPackage.LineId = aLineConfiguration.Id; try { var parameters = new List <ValueParameter>(); foreach (var queryParameter in aLineConfiguration.Parameters) { var parameterValue = kppConnector.GetValue(queryParameter); parameters.Add(parameterValue); } aPackage.Parameters = parameters.ToArray(); } catch (Exception ex) { logger.Error("Ошибка при получении данных: " + ex.Message); aPackage = null; return(false); } return(true); }