public void Constructors() { var configurator = new ApiConfigurator(); Assert.Equal(ApiDataFormat.Json, configurator.GetFormat()); Assert.Null(configurator.GetApiKey()); Assert.Null(configurator.GetAppKey()); }
public void AppKey_Method() { Assert.Throws<ArgumentNullException>(() => new ApiConfigurator().AppKey(null)); Assert.Throws<ArgumentException>(() => new ApiConfigurator().AppKey(string.Empty)); var configurator = new ApiConfigurator(); Assert.True(ReferenceEquals(configurator.AppKey("appKey"), configurator)); Assert.Equal("appKey", configurator.GetAppKey()); }
/// <summary> /// <para>Initializes a caller object to perform web requests to RuLaw API.</para> /// </summary> /// <param name="configurator">Delegate to perform API setup process.</param> /// <exception cref="ArgumentNullException">If <paramref name="configurator"/> is a <c>null</c> reference.</exception> public static IApiCaller API(Action<IApiConfigurator> configurator) { Assertion.NotNull(configurator); var apiConfigurator = new ApiConfigurator(); configurator(apiConfigurator); if (apiConfigurator.GetApiKey().IsEmpty()) { throw new InvalidOperationException("API Key was not specified when configuring API caller"); } return new ApiCaller(apiConfigurator.GetFormat(), apiConfigurator.GetApiKey(), apiConfigurator.GetAppKey()); }
public void Format_Method() { var configurator = new ApiConfigurator(); Assert.True(ReferenceEquals(configurator.Format(ApiDataFormat.Xml), configurator)); Assert.Equal(ApiDataFormat.Xml, configurator.GetFormat()); }