<commit_before>﻿using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NoTPK.APIWrapper.ObsidianPortal;

namespace APIWrapper.ObsidianPortal.Tests
{
	[TestClass]
	public class API_Characters_Tests
	{
		private static string _appId = "";
		private static string _appSecret = "";
		private static string _token = "";
		private static string _tokenSecret = "";

		private static XElement _approvedResults;
		private static XElement _testVariables;

		[ClassInitialize]
		public static void LoadConstants(TestContext testContext)
		{
			var configPath = Path.GetFullPath(@"..\..\..\..\..\..\Configs\NoTPK.APIWrapper.ObsidianPortal.Tests.Config.xml");
			var configDoc = XDocument.Load(configPath);
			var tokens = (from t in configDoc.Descendants("TestTokens") select t).FirstOrDefault();

			if (tokens != null)
			{
				_appId = (string)tokens.Element("AppId");
				_appSecret = (string)tokens.Element("AppSecret");
				_token = (string)tokens.Element("AccessToken");
				_tokenSecret = (string)tokens.Element("AccessTokenSecret");
			}

			var approvedPath = Path.GetFullPath(@"..\..\..\..\..\..\Configs\NoTPK.APIWrapper.ObsidianPortal.Tests.Approved.xml");
			var approvedDOc = XDocument.Load(approvedPath);

			_approvedResults = (from a in approvedDOc.Descendants("ApprovedValues").Descendants("Characters") select a).FirstOrDefault();
			_testVariables = (from v in configDoc.Descendants("TestVariables") select v).FirstOrDefault();
		}

		[TestMethod]
		public async Task Test_Characters_Index__ByCampaignId()
		{
			var approved = (string)_approvedResults.Element("Index_Character");
			var campaignId = (string)_testVariables.Element("CampaignId");

			var result = await API_Characters.IndexByCampaignId(_appId, _appSecret, _token, _tokenSecret, campaignId);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		public async Task Test_Characters_Show__ByCharacterId()
		{
			var approved = (string)_approvedResults.Element("Show_CharacterById");
			var campaignId = (string)_testVariables.Element("CampaignId");
			var characterId = (string)_testVariables.Element("CharacterId");

			var result = await API_Characters.ShowById(_appId, _appSecret, _token, _tokenSecret, campaignId, characterId);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		public async Task Test_Characters_Show__ByCharacterSlug()
		{
			var approved = (string)_approvedResults.Element("Show_CharacterBySlug");
			var campaignId = (string)_testVariables.Element("CampaignId");
			var characterSlug = (string)_testVariables.Element("CharacterSlug");

			var result = await API_Characters.ShowBySlug(_appId, _appSecret, _token, _tokenSecret, campaignId, characterSlug);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		[Ignore] // Destructive -- Need mocking, perhaps
		public async Task Test_Characters_Create__ByCampaignId()
		{
			var approved = (string)_approvedResults.Element("Show_CreateCharacter");
			var campaignId = (string)_testVariables.Element("ModifiableCampaign");
			var newCharacter = (string)_testVariables.Element("NewCharacter");

			var result = await API_Characters.Create(_appId, _appSecret, _token, _tokenSecret, campaignId, newCharacter);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		[Ignore] // Destructive -- Need mocking, perhaps
		public async Task Test_Characters_Update__ByCharacterId()
		{
			var approved = (string) _approvedResults.Element("Show_UpdateCharacter");
			var campaignId = (string) _testVariables.Element("ModifiableCampaign");
			var updateCharacter = (string)_testVariables.Element("UpdateCharacterId");
			var updateContent = (string) _testVariables.Element("UpdateContent");

			var result = await API_Characters.Update(_appId, _appSecret, _token, _tokenSecret, campaignId, updateCharacter, updateContent);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		[Ignore] // Destructive -- Need mocking, perhaps
		public async Task Test_Characters_Delete__ByCharacterId()
		{
			var approved = (string) _approvedResults.Element("Show_DeleteCharacter");
			var campaignId = (string) _testVariables.Element("ModifiableCampaign");
			var deleteCharacter = (string) _testVariables.Element("DeleteCharacterId");

			var result = await API_Characters.Delete(_appId, _appSecret, _token, _tokenSecret, campaignId, deleteCharacter);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		public async Task Test_Characters_StoreLocal__ByCharacterId()
		{
			// Store the character locally to allow for undoing
			var approved = (string) _approvedResults.Element("Show_CharacterById");
			var campaignId = (string)_testVariables.Element("CampaignId");
			var characterId = (string)_testVariables.Element("CharacterId");

			var result = await API_Characters.ShowById(_appId, _appSecret, _token, _tokenSecret, campaignId, characterId);

			var storageLocation = API_Characters.StoreLocal(characterId, result);

			var recoverCharacter = API_Characters.RetrieveLocal(storageLocation);
			Assert.AreEqual(approved, recoverCharacter);
		}
	}
}<commit_msg>Migrating another class away from xml stored approved values<commit_after>﻿using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NoTPK.APIWrapper.ObsidianPortal;
using APIWrapper.ObsidianPortal.Tests.Support;

namespace APIWrapper.ObsidianPortal.Tests
{
	[TestClass]
	public class API_Characters_Tests
	{
		private static string _appId = "";
		private static string _appSecret = "";
		private static string _token = "";
		private static string _tokenSecret = "";

		private static XElement _testVariables;

		[ClassInitialize]
		public static void LoadConstants(TestContext testContext)
		{
			var configPath = Path.GetFullPath(@"..\..\..\..\..\..\Configs\NoTPK.APIWrapper.ObsidianPortal.Tests.Config.xml");
			var configDoc = XDocument.Load(configPath);
			var tokens = (from t in configDoc.Descendants("TestTokens") select t).FirstOrDefault();

			if (tokens != null)
			{
				_appId = (string)tokens.Element("AppId");
				_appSecret = (string)tokens.Element("AppSecret");
				_token = (string)tokens.Element("AccessToken");
				_tokenSecret = (string)tokens.Element("AccessTokenSecret");
			}

			_testVariables = (from v in configDoc.Descendants("TestVariables") select v).FirstOrDefault();
		}

		[TestMethod]
		public async Task Test_Characters_Index__ByCampaignId()
		{
			var approved = Helpers.GetApprovedResults("Index_Character");
			var campaignId = (string)_testVariables.Element("CampaignId");

			var result = await API_Characters.IndexByCampaignId(_appId, _appSecret, _token, _tokenSecret, campaignId);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		public async Task Test_Characters_Show__ByCharacterId()
		{
			var approved = Helpers.GetApprovedResults("Show_CharacterById");
			var campaignId = (string)_testVariables.Element("CampaignId");
			var characterId = (string)_testVariables.Element("CharacterId");

			var result = await API_Characters.ShowById(_appId, _appSecret, _token, _tokenSecret, campaignId, characterId);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		public async Task Test_Characters_Show__ByCharacterSlug()
		{
			var approved = Helpers.GetApprovedResults("Show_CharacterBySlug");
			var campaignId = (string)_testVariables.Element("CampaignId");
			var characterSlug = (string)_testVariables.Element("CharacterSlug");

			var result = await API_Characters.ShowBySlug(_appId, _appSecret, _token, _tokenSecret, campaignId, characterSlug);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		[Ignore] // Destructive -- Need mocking, perhaps
		public async Task Test_Characters_Create__ByCampaignId()
		{
			var approved = Helpers.GetApprovedResults("Show_CreateCharacter");
			var campaignId = (string)_testVariables.Element("ModifiableCampaign");
			var newCharacter = (string)_testVariables.Element("NewCharacter");

			var result = await API_Characters.Create(_appId, _appSecret, _token, _tokenSecret, campaignId, newCharacter);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		[Ignore] // Destructive -- Need mocking, perhaps
		public async Task Test_Characters_Update__ByCharacterId()
		{
			var approved = Helpers.GetApprovedResults("Show_UpdateCharacter");
			var campaignId = (string) _testVariables.Element("ModifiableCampaign");
			var updateCharacter = (string)_testVariables.Element("UpdateCharacterId");
			var updateContent = (string) _testVariables.Element("UpdateContent");

			var result = await API_Characters.Update(_appId, _appSecret, _token, _tokenSecret, campaignId, updateCharacter, updateContent);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		[Ignore] // Destructive -- Need mocking, perhaps
		public async Task Test_Characters_Delete__ByCharacterId()
		{
			var approved = Helpers.GetApprovedResults("Show_DeleteCharacter");
			var campaignId = (string) _testVariables.Element("ModifiableCampaign");
			var deleteCharacter = (string) _testVariables.Element("DeleteCharacterId");

			var result = await API_Characters.Delete(_appId, _appSecret, _token, _tokenSecret, campaignId, deleteCharacter);
			Assert.AreEqual(approved, result);
		}

		[TestMethod]
		public async Task Test_Characters_StoreLocal__ByCharacterId()
		{
			// Store the character locally to allow for undoing
			var approved = Helpers.GetApprovedResults("Show_CharacterById");
			var campaignId = (string)_testVariables.Element("CampaignId");
			var characterId = (string)_testVariables.Element("CharacterId");

			var result = await API_Characters.ShowById(_appId, _appSecret, _token, _tokenSecret, campaignId, characterId);

			var storageLocation = API_Characters.StoreLocal(characterId, result);

			var recoverCharacter = API_Characters.RetrieveLocal(storageLocation);
			Assert.AreEqual(approved, recoverCharacter);
		}
	}
}
{'fraction_non_alphanumeric': 0.10992592592592593, 'fraction_numerical': 0.0, 'mean_word_length': 5.618300653594771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3960929', 'n_tokens_mistral': 3276, 'n_tokens_neox': 2878, 'n_words': 612}