예제 #1
0
    public void Constructors()
    {
      Assert.Throws<ArgumentNullException>(() => new ApiCaller(ApiDataFormat.Xml, null));
      Assert.Throws<ArgumentException>(() => new ApiCaller(ApiDataFormat.Xml, string.Empty));

      var caller = new ApiCaller(ApiDataFormat.Xml, "apiToken", "appToken");
      Assert.Equal("apiToken", caller.ApiToken);
      Assert.Equal("appToken", caller.AppToken);
      Assert.Equal(ApiDataFormat.Xml, caller.Format);
      Assert.True(caller.Field("jsonSerializer").To<ISerializer>() is RuLawJsonSerializer);
      Assert.True(caller.Field("jsonDeserializer").To<IDeserializer>() is RuLawJsonDeserializer);
      Assert.True(caller.Field("xmlSerializer").To<ISerializer>() is RuLawXmlSerializer);
      Assert.True(caller.Field("xmlDeserializer").To<IDeserializer>() is RuLawXmlDeserializer);

      var client = caller.Field("restClient").To<RestClient>();
      Assert.Equal("http://api.duma.gov.ru/api", client.BaseUrl.ToString());
      var token = client.DefaultParameters.FirstOrDefault(x => x.Name == "app_token");
      Assert.NotNull(token);
      Assert.Equal("appToken", token.Value);
    }