public void TestErrorResponse()
        {
            string str = "{\"errorCode\":1,\"message\":\"The requested resource could not be found.\",\"errors\":[{\"errorCode\":1,\"description\":\"The requested resource could not be found.\"}],\"trackingId\":\"xyz\"}";

            var spaces = TeamsObject.FromJsonString <SpaceList>(str);

            var errors = spaces.GetErrors();

            Assert.AreEqual(1, errors[0].ErrorCode);
            Assert.AreEqual("The requested resource could not be found.", errors[0].Description);
        }
Esempio n. 2
0
        public static T Load <T>(string fileName)
            where T : TeamsObject, new()
        {
            T result = null;

            using (var fs = new FileStream(String.Format("{0}{1}{2}", TEAMS_OBJECTS_DIRECTORY, Path.DirectorySeparatorChar, fileName), FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var reader = new StreamReader(fs, UTF8Utils.UTF8_WITHOUT_BOM, true))
                {
                    result = TeamsObject.FromJsonString <T>(reader.ReadToEnd());
                }

            return(result);
        }
        public void TestPartialErrorResponse()
        {
            string str = "{\"items\":[{\"id\":\"id01\",\"title\":\"title01\",\"type\":\"group\",\"isLocked\":true,\"teamId\":\"teamid01\",\"lastActivity\":\"2016-04-21T19:12:48.920Z\",\"created\":\"2016-04-21T19:01:55.966Z\"},{\"id\":\"id02\",\"title\":\"xyz...\",\"errors\":{\"title\":{\"code\":\"kms_failure\",\"reason\":\"Key management server failed to respond appropriately. For more information: https://developer.webex.com/errors.html\"}}}]}";

            var spaces = TeamsObject.FromJsonString <SpaceList>(str);

            var space = spaces.Items[1];

            var errors = space.GetPartialErrors();

            Assert.IsTrue(errors.ContainsKey("title"));
            Assert.AreEqual(PartialErrorCode.KMSFailure, errors["title"].Code);
            Assert.AreEqual("Key management server failed to respond appropriately. For more information: https://developer.webex.com/errors.html", errors["title"].Reason);
        }
Esempio n. 4
0
        public static async Task Init(TestContext testContext)
        {
            byte[] encryptedInfo;
            byte[] entropy;

            Person me = null;

            try
            {
                string userDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

                var dirInfo = new DirectoryInfo(String.Format("{0}{1}.thrzn41{1}unittest{1}teams", userDir, Path.DirectorySeparatorChar));

                using (var stream = new FileStream(String.Format("{0}{1}teamsinfo.dat", dirInfo.FullName, Path.DirectorySeparatorChar), FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var memory = new MemoryStream())
                    {
                        stream.CopyTo(memory);

                        encryptedInfo = memory.ToArray();
                    }

                using (var stream = new FileStream(String.Format("{0}{1}infoentropy.dat", dirInfo.FullName, Path.DirectorySeparatorChar), FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var memory = new MemoryStream())
                    {
                        stream.CopyTo(memory);

                        entropy = memory.ToArray();
                    }

                var info = TeamsObject.FromJsonString <TeamsInfo>(LocalProtectedString.FromEncryptedData(encryptedInfo, entropy).DecryptToString());

                teams = TeamsAPI.CreateVersion1Client(info.APIToken);

                var rMe = await teams.GetMeAsync();

                if (rMe.IsSuccessStatus)
                {
                    me = rMe.Data;
                }
            }
            catch (DirectoryNotFoundException) { }
            catch (FileNotFoundException) { }


            checkTeamsAPIClient(me);
        }
        public void TestDeserializationError()
        {
            string str = "{ abc";

            Assert.ThrowsException <TeamsJsonSerializationException>(() => { TeamsObject.FromJsonString <Message>(str); });

            str = "{ \"id\": 1 \"aaa\": 1 }";
            Assert.ThrowsException <TeamsJsonSerializationException>(() => { TeamsObject.FromJsonString <Message>(str); });

            str = "{ \"id\": 12345, \"created\": 1, \"text\": \"Hello!!!\" }";
            var message = TeamsObject.FromJsonString <Message>(str);

            Assert.IsTrue(message.HasSerializationErrors);
            Assert.AreEqual(1, message.SerializationErrors.Length);
            Assert.AreEqual(TeamsSerializationOperation.Deserialize, message.SerializationErrors[0].Operation);
            Assert.AreEqual(1, message.SerializationErrors[0].LineNumber);
            Assert.AreEqual(27, message.SerializationErrors[0].LinePosition);
            Assert.AreEqual("created", message.SerializationErrors[0].Path);
            Assert.AreEqual("12345", message.Id);
            Assert.AreEqual("Hello!!!", message.Text);
        }
        public static async Task Init(TestContext testContext)
        {
            byte[] encryptedInfo;
            byte[] entropy;

            Person me = null;

            try
            {
                string userDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

                var dirInfo = new DirectoryInfo(String.Format("{0}{1}.thrzn41{1}unittest{1}teams", userDir, Path.DirectorySeparatorChar));

                using (var stream = new FileStream(String.Format("{0}{1}teamsintegration.dat", dirInfo.FullName, Path.DirectorySeparatorChar), FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var memory = new MemoryStream())
                    {
                        stream.CopyTo(memory);

                        encryptedInfo = memory.ToArray();
                    }

                using (var stream = new FileStream(String.Format("{0}{1}integrationentropy.dat", dirInfo.FullName, Path.DirectorySeparatorChar), FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var memory = new MemoryStream())
                    {
                        stream.CopyTo(memory);

                        entropy = memory.ToArray();
                    }

                var token = TeamsObject.FromJsonString <TeamsIntegrationInfo>(LocalProtectedString.FromEncryptedData(encryptedInfo, entropy).DecryptToString());

                teams = TeamsAPI.CreateVersion1Client(token.TokenInfo, new TeamsRetryOnErrorHandler(4, TimeSpan.FromSeconds(15.0f)));

                var rMe = await teams.GetMeAsync();

                if (rMe.IsSuccessStatus)
                {
                    me = rMe.Data;

                    var e = (await teams.ListSpacesAsync(type: SpaceType.Group, sortBy: SpaceSortBy.Created, max: 50)).GetListResultEnumerator();

                    while (await e.MoveNextAsync())
                    {
                        var r = e.CurrentResult;

                        if (r.IsSuccessStatus && r.Data.HasItems)
                        {
                            foreach (var item in r.Data.Items)
                            {
                                if (item.Title.Contains(UNIT_TEST_SPACE_TAG))
                                {
                                    unitTestSpace = item;
                                    break;
                                }
                            }
                        }

                        if (unitTestSpace != null)
                        {
                            break;
                        }
                    }
                }
            }
            catch (DirectoryNotFoundException) { }
            catch (FileNotFoundException) { }

            checkTeamsAPIClient(me);
            checkUnitTestSpace();
        }