<commit_before>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Maybe5.SharpSpark;
using System.Configuration;

namespace Maybe5.SharpSpark.Tests
{
    [TestClass]
    public class SparkClientTests
    {
        SparkClient client;

        [TestInitialize]
        public void Setup()
        {
            var accessToken = ConfigurationManager.AppSettings["accessToken"];
            var deviceId = ConfigurationManager.AppSettings["deviceId"];
            client = new SparkClient(accessToken, deviceId);
        }

        [TestMethod]
        public void GivenClientInfoExpectDeviceInfo()
        {
            SparkDevice device = client.GetDevice();

            Assert.IsNotNull(device);
            Assert.IsNotNull(device.Name);
            Assert.AreEqual(client.DeviceId, device.Id);
        }

        [TestMethod]
        public void GivenInvalidFunctionExpectErrorFunctionNotFound()
        {
            SparkResult result = client.ExecuteFunction("thisdoesnotexist");

            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual("Function not found", result.ErrorResult.Error);
        }

        [Ignore]//This test only passes if the device is offline
        [TestMethod]
        public void GivenOfflineDeviceFunctionExpectErrorTimedOut()
        {
            SparkResult result = client.ExecuteFunction("digitalRead");

            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual("Timed out.", result.ErrorResult.Error);
        }
        
    }
}
<commit_msg>added test for invalid access token<commit_after>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Maybe5.SharpSpark;
using System.Configuration;

namespace Maybe5.SharpSpark.Tests
{
    [TestClass]
    public class SparkClientTests
    {
        SparkClient client;

        [TestInitialize]
        public void Setup()
        {
            var accessToken = ConfigurationManager.AppSettings["accessToken"];
            var deviceId = ConfigurationManager.AppSettings["deviceId"];
            client = new SparkClient(accessToken, deviceId);
        }

        [TestMethod]
        public void GivenClientInfoExpectDeviceInfo()
        {
            SparkDevice device = client.GetDevice();

            Assert.IsNotNull(device);
            Assert.IsNotNull(device.Name);
            Assert.AreEqual(client.DeviceId, device.Id);
        }

        [TestMethod]
        public void GivenInvalidFunctionExpectErrorFunctionNotFound()
        {
            SparkResult result = client.ExecuteFunction("thisdoesnotexist");

            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual("Function not found", result.ErrorResult.Error);
        }

        [TestMethod]
        public void GivenInvalidAccessTokenExpectErrorInvalidGrant()
        {
            var badClient = new SparkClient("badtoken", "");
            SparkResult result = badClient.ExecuteFunction("thisdoesnotexist");

            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual("invalid_grant", result.ErrorResult.Error);
        }

        [Ignore]//This test only passes if the device is offline
        [TestMethod]
        public void GivenOfflineDeviceFunctionExpectErrorTimedOut()
        {
            SparkResult result = client.ExecuteFunction("digitalRead");

            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual("Timed out.", result.ErrorResult.Error);
        }
        
    }
}

{'fraction_non_alphanumeric': 0.08728323699421965, 'fraction_numerical': 0.0011560693641618498, 'mean_word_length': 2.383186705767351, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3501230', 'n_tokens_mistral': 876, 'n_tokens_neox': 845, 'n_words': 165}