<commit_before>﻿using System;
using MyAnimeListSharp.Parameters;
using MyAnimeListSharp.Util;
using Project.MyAnimeList.Test.Fixture;
using Xunit;
using Xunit.Abstractions;

namespace Project.MyAnimeList.Test.Tests
{
	public class MangaListMethodsTest : 
		CredentialCollectionTest, 
		IClassFixture<MangaValuesFixture>,
		IClassFixture<MangaListMethodsFixture>
	{
		private readonly ITestOutputHelper _output;
		private readonly MangaValuesFixture _mangaValuesFixture;
		private readonly MangaListMethodsFixture _mangaListMethodsFixture;

		public MangaListMethodsTest(
			CredentialContextFixture credentialContextFixture, 
			ITestOutputHelper output,
			MangaValuesFixture mangaValuesFixture,
			MangaListMethodsFixture mangaListMethodsFixture)
			: base(credentialContextFixture)
		{
			_output = output;
			_mangaValuesFixture = mangaValuesFixture;
			_mangaListMethodsFixture = mangaListMethodsFixture;
		}

		[Fact]
		public void AddMangaRequestParametersMethodReturnsPostHttpMethod()
		{
			var sut = new AddMangaRequestParameters(CredentialContextFixture.CredentialContext, MangaValuesFixture.ID, MangaValuesFixture.Data);

		    const string expected = "GET";
		    Assert.Equal(expected, sut.HttpMethod);
		}

		[Fact]
		public void TestAddMangaRequestParametersBaseUri()
		{
			var requestParameters = new AddMangaRequestParameters(CredentialContextFixture.CredentialContext, MangaValuesFixture.ID, MangaValuesFixture.Data);
			var sut = new RequestUriBuilder(requestParameters);

			var actualUri = sut.GetRequestUri();

			Assert.Equal($"https://myanimelist.net/api/mangalist/add/{MangaValuesFixture.ID}.xml", actualUri);
		}

		[Fact]
		public void AddMangaRequestResponseReturnsUniqueRowId()
		{
			var sut = _mangaListMethodsFixture.MangaListMethods;

			var actualResponseString = sut.AddManga(MangaValuesFixture.ID, MangaValuesFixture.Data);

			_output.WriteLine(actualResponseString);

			// If no record was added, then a unique ID returned,
			int uniqueId;
			bool isNumber = int.TryParse(actualResponseString, out uniqueId);
			// Else "201 Created" response is returned.
			bool hasCreatedTextInIt = actualResponseString.Contains("Created");

			Assert.True(isNumber || hasCreatedTextInIt);
		}

		[Fact]
		public void AddMangaUsingMangaValuesObjectInstance()
		{
			var sut = _mangaListMethodsFixture.MangaListMethods;

			const string expectedSubstring = "Created";
			var actualResponseString = sut.AddManga(MangaValuesFixture.ID, _mangaValuesFixture.Values);

			// If no record was added, then a unique ID returned,
			int uniqueId;
			bool isNumber = int.TryParse(actualResponseString, out uniqueId);
			// Else "201 Created" response is returned.
			bool hasCreatedTextInIt = actualResponseString.Contains(expectedSubstring);

			Assert.True(isNumber || hasCreatedTextInIt);
		}<commit_msg>Fixed test's expected data for "AddMangaUsingMangaValuesObjectInstance" since AddManga return value has been changed by MAL<commit_after>﻿using System;
using MyAnimeListSharp.Parameters;
using MyAnimeListSharp.Util;
using Project.MyAnimeList.Test.Fixture;
using Xunit;
using Xunit.Abstractions;

namespace Project.MyAnimeList.Test.Tests
{
	public class MangaListMethodsTest : 
		CredentialCollectionTest, 
		IClassFixture<MangaValuesFixture>,
		IClassFixture<MangaListMethodsFixture>
	{
		private readonly ITestOutputHelper _output;
		private readonly MangaValuesFixture _mangaValuesFixture;
		private readonly MangaListMethodsFixture _mangaListMethodsFixture;

		public MangaListMethodsTest(
			CredentialContextFixture credentialContextFixture, 
			ITestOutputHelper output,
			MangaValuesFixture mangaValuesFixture,
			MangaListMethodsFixture mangaListMethodsFixture)
			: base(credentialContextFixture)
		{
			_output = output;
			_mangaValuesFixture = mangaValuesFixture;
			_mangaListMethodsFixture = mangaListMethodsFixture;
		}

		[Fact]
		public void AddMangaRequestParametersMethodReturnsPostHttpMethod()
		{
			var sut = new AddMangaRequestParameters(CredentialContextFixture.CredentialContext, MangaValuesFixture.ID, MangaValuesFixture.Data);

		    const string expected = "GET";
		    Assert.Equal(expected, sut.HttpMethod);
		}

		[Fact]
		public void TestAddMangaRequestParametersBaseUri()
		{
			var requestParameters = new AddMangaRequestParameters(CredentialContextFixture.CredentialContext, MangaValuesFixture.ID, MangaValuesFixture.Data);
			var sut = new RequestUriBuilder(requestParameters);

			var actualUri = sut.GetRequestUri();

			Assert.Equal($"https://myanimelist.net/api/mangalist/add/{MangaValuesFixture.ID}.xml", actualUri);
		}

		[Fact]
		public void AddMangaRequestResponseReturnsUniqueRowId()
		{
			var sut = _mangaListMethodsFixture.MangaListMethods;

			var actualResponseString = sut.AddManga(MangaValuesFixture.ID, MangaValuesFixture.Data);

			_output.WriteLine(actualResponseString);

			// If no record was added, then a unique ID returned,
			int uniqueId;
			bool isNumber = int.TryParse(actualResponseString, out uniqueId);
			// Else "201 Created" response is returned.
			bool hasCreatedTextInIt = actualResponseString.Contains("Created");

			Assert.True(isNumber || hasCreatedTextInIt);
		}

		[Fact]
		public void AddMangaUsingMangaValuesObjectInstance()
		{
			var sut = _mangaListMethodsFixture.MangaListMethods;

			var actualResponseString = sut.AddManga(MangaValuesFixture.ID, _mangaValuesFixture.Values);

			// If no record was added, then a unique ID returned,
			int uniqueId;
			bool isNumber = int.TryParse(actualResponseString, out uniqueId);
            // Else "201 Created" response is returned.

            string alreadyExistsText = $"The manga (id: {MangaValuesFixture.ID}) is already in the list.";
		    bool isMangaAlreadyAdded = actualResponseString == alreadyExistsText;

			Assert.True(isNumber || isMangaAlreadyAdded);
		}
{'fraction_non_alphanumeric': 0.07518022657054584, 'fraction_numerical': 0.0020597322348094747, 'mean_word_length': 5.3962678375411635, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3837312', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1694, 'n_words': 356}