Ejemplo n.º 1
0
        public void WebService_UseEmptyFetchConfiguration_CanProperlySerializeAndDeserilizeFetchConfiguration()
        {
            // Arrange
            var config1 = new FetchConfiguration(
                DateTime.MinValue,
                new DataSourceDefinition[] {
                new DataSourceDefinition(0, "", "", "", "", new string [0])
            },
                new VariableDefinition[] {
                new VariableDefinition("", "", "")
            });

            // Act
            var json    = JsonConvert.SerializeObject(config1);
            var config2 = JsonConvert.DeserializeObject <Microsoft.Research.Science.FetchClimate2.Serializable.FetchConfiguration>(json).ConvertFromSerializable();

            // Assert
            Assert.IsNotNull(config2, "Error: Deserilized object is null");
            Assert.AreEqual <DateTime>(config1.TimeStamp, config2.TimeStamp);
            Assert.IsNotNull(config2.DataSources);
            Assert.AreEqual <int>(config1.DataSources.Length, config2.DataSources.Length);
            Assert.IsNotNull(config2.DataSources[0]);
            Assert.AreEqual <ushort>(config1.DataSources[0].ID, config2.DataSources[0].ID);
            Assert.AreEqual <string>(config1.DataSources[0].Name, config2.DataSources[0].Name);
            Assert.AreEqual <string>(config1.DataSources[0].Description, config2.DataSources[0].Description);
            Assert.AreEqual <string>(config1.DataSources[0].Copyright, config2.DataSources[0].Copyright);
            Assert.IsNotNull(config2.DataSources[0].ProvidedVariables);
            Assert.AreEqual <int>(config1.DataSources[0].ProvidedVariables.Length, config2.DataSources[0].ProvidedVariables.Length);
            Assert.IsNotNull(config2.EnvironmentalVariables);
            Assert.AreEqual <int>(config1.EnvironmentalVariables.Length, config2.EnvironmentalVariables.Length);
            Assert.IsNotNull(config2.EnvironmentalVariables[0]);
            Assert.AreEqual <string>(config1.EnvironmentalVariables[0].Name, config2.EnvironmentalVariables[0].Name);
            Assert.AreEqual <string>(config1.EnvironmentalVariables[0].Units, config2.EnvironmentalVariables[0].Units);
            Assert.AreEqual <string>(config1.EnvironmentalVariables[0].Description, config2.EnvironmentalVariables[0].Description);
        }
Ejemplo n.º 2
0
 public PostFetcherService(
     IBooruHttpClient httpClient,
     PostFetcherServiceHelper helper,
     FetchConfiguration configuration)
 {
     _httpClient = httpClient;
     _helper     = helper;
     _initLimit  = configuration.PostLimit;
 }
Ejemplo n.º 3
0
        public void WebService_RequestFetchConfiguration_CanProperlyDeserilizeJsonResult()
        {
            // Arrange
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(TestConstants.CloudServiceURI);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Add an accept header for JSON format

            HttpResponseMessage response = null;
            FetchConfiguration  config   = null;

            // Act
            response = client.GetAsync("api/configuration").Result;  // Blocking call
            if (response.IsSuccessStatusCode)
            {
                // Parse the response body. Blocking.
                config = response.Content.ReadAsAsync <Microsoft.Research.Science.FetchClimate2.Serializable.FetchConfiguration>().Result.ConvertFromSerializable();
            }

            // Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Error: (" + response.StatusCode + ") " + response.ReasonPhrase);
            Assert.IsNotNull(config, "Error: Deserilized object is null");
        }
Ejemplo n.º 4
0
 public static void ClassInit(TestContext ctx)
 {
     config = JsonConvert.DeserializeObject <Serializable.FetchConfiguration>(File.ReadAllText("sampleconfig.json")).ConvertFromSerializable();
 }
Ejemplo n.º 5
0
 public PostFetcherServiceHelper(IBooruConfiguration configuration)
 {
     _fetchConfiguration = configuration.FetchConfiguration;
 }