Skip to content

Commit

Permalink
Added more information to words.
Browse files Browse the repository at this point in the history
Use interfaces instead classes.
Unit testing.
Change version to v1.1.0
  • Loading branch information
josago97 committed Jul 27, 2023
1 parent fe172ac commit 7ef9720
Show file tree
Hide file tree
Showing 21 changed files with 705 additions and 72 deletions.
33 changes: 25 additions & 8 deletions RAE.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using RAE.Models;

namespace RAE.Demo
{
Expand All @@ -11,6 +12,7 @@ class Program

static Func<Task>[] functions =
{
FetchWordsAsync,
GetKeysAsync,
SearchWordAsync,
WordOfTheDayAsync,
Expand All @@ -37,6 +39,23 @@ static async Task Main()
Console.ReadLine();
}

static async Task FetchWordsAsync()
{
string[] wordsToFetch = { "y", "tonto", "niño", "en", "manada" };

foreach (string wordToFetch in wordsToFetch)
{
IList<IWord> words = await drae.FetchWordsAsync(wordToFetch);

foreach (IWord word in words)
{
Console.WriteLine(word);
}

Console.WriteLine();
}
}

static async Task GetKeysAsync()
{
string query = "w";
Expand All @@ -48,32 +67,30 @@ static async Task GetKeysAsync()
static async Task SearchWordAsync()
{
string query = "a";
IList<Word> words = await drae.SearchWordAsync(query, false);
IEntry[] entries = await drae.SearchWordAsync(query, false);

Console.WriteLine($"SearchWord ({query}): {string.Join(", ", words.Select(w => $"{w.Content} ({w.Id})"))}");
Console.WriteLine($"SearchWord ({query}): {string.Join<IEntry>(", ", entries)}");
}

static async Task WordOfTheDayAsync()
{
Word word = await drae.GetWordOfTheDayAsync();
IEntry word = await drae.GetWordOfTheDayAsync();

Console.WriteLine($"Word of the day: {word} ({word.Id})");
}

static async Task GetRandomWorldAsync()
{
Word word = await drae.GetRandomWordAsync();
IWord word = await drae.GetRandomWordAsync();

Console.WriteLine($"A random word: {word}");
}

static async Task FetchRandomWorldAsync()
{
Word word = await drae.GetRandomWordAsync();
string[] definitions = await drae.FetchWordByIdAsync(word.Id);
IWord word = await drae.GetRandomWordAsync();

Console.WriteLine($"Definitions of {word.Content}:");
Array.ForEach(definitions, Console.WriteLine);
Console.WriteLine(word);
}

static async Task GetWordsStartWithAsync()
Expand Down
2 changes: 1 addition & 1 deletion RAE.Demo/RAE.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 8 additions & 2 deletions RAE.NET.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.87
# Visual Studio Version 17
VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RAE", "RAE\RAE.csproj", "{F214F029-5904-44EB-8C99-B84821558369}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RAE.Demo", "RAE.Demo\RAE.Demo.csproj", "{66258F90-04F3-49B6-B8E0-98A82838D6B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RAE.Tests", "RAE.Tests\RAE.Tests.csproj", "{AE13E843-1DA4-4507-9FE2-F7FCDF0EB899}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{66258F90-04F3-49B6-B8E0-98A82838D6B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66258F90-04F3-49B6-B8E0-98A82838D6B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66258F90-04F3-49B6-B8E0-98A82838D6B5}.Release|Any CPU.Build.0 = Release|Any CPU
{AE13E843-1DA4-4507-9FE2-F7FCDF0EB899}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE13E843-1DA4-4507-9FE2-F7FCDF0EB899}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE13E843-1DA4-4507-9FE2-F7FCDF0EB899}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE13E843-1DA4-4507-9FE2-F7FCDF0EB899}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
160 changes: 160 additions & 0 deletions RAE.Tests/DRAE.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
namespace RAE.Tests;

public class DRAE
{
private RAE.DRAE Drae { get; } = new RAE.DRAE();

[Theory]
[InlineData("-ato")]
[InlineData("en")]
[InlineData("en-")]
[InlineData("manada")]
[InlineData("niño")]
[InlineData("tonto")]
[InlineData("y")]
public async Task FetchWordsExist(string word)
{
IList<IWord> words = await Drae.FetchWordsAsync(word);

Assert.NotNull(words);
Assert.NotEmpty(words);
}

[Theory]
[InlineData("asdadasdada")]
public async Task FetchWordsNoExist(string word)
{
IList<IWord> words = await Drae.FetchWordsAsync(word);

Assert.NotNull(words);
Assert.Empty(words);
}

[Theory]
[InlineData("SPSNBuG")] //pelo
[InlineData("R9dHZWB")] //ordenador
public async Task FetchWordByIdExist(string wordId)
{
IWord word = await Drae.FetchWordByIdAsync(wordId);

Assert.NotNull(word);
}

[Theory]
[InlineData("sadafasda")]
public async Task FetchWordByIdNoExist(string wordId)
{
IWord word = await Drae.FetchWordByIdAsync(wordId);

Assert.Null(word);
}

[Fact]
public async Task GetAllWords()
{
string[] allWords = await Drae.GetAllWordsAsync();

Assert.NotNull(allWords);
Assert.NotEmpty(allWords);
}

[Theory]
[InlineData("a")]
[InlineData("la")]
public async Task GetKeysExist(string query)
{
string[] keys = await Drae.GetKeysAsync(query);

Assert.NotNull(keys);
Assert.NotEmpty(keys);
}

[Theory]
[InlineData("asdasdsad")]
public async Task GetKeysNoExist(string query)
{
string[] keys = await Drae.GetKeysAsync(query);

Assert.NotNull(keys);
Assert.Empty(keys);
}

[Fact]
public async Task GetRandomWord()
{
IWord word = await Drae.GetRandomWordAsync();

Assert.NotNull(word);
}

[Fact]
public async Task GetWordOfTheDay()
{
IEntry word = await Drae.GetWordOfTheDayAsync();

Assert.NotNull(word);
}

[Theory]
[InlineData("a")]
[InlineData("la")]
public async Task GetWordsStartWithExist(string query)
{
string[] words = await Drae.GetWordsStartWithAsync(query);

Assert.NotNull(words);
Assert.NotEmpty(words);
}

[Theory]
[InlineData("aadadsadasdc")]
public async Task GetWordsStartWithNoExist(string query)
{
string[] words = await Drae.GetWordsStartWithAsync(query);

Assert.NotNull(words);
Assert.Empty(words);
}

[Theory]
[InlineData("a")]
[InlineData("la")]
public async Task GetWordsContainExist(string query)
{
string[] words = await Drae.GetWordsContainAsync(query);

Assert.NotNull(words);
Assert.NotEmpty(words);
}

[Theory]
[InlineData("dfsdfsdfsfdsa")]
public async Task GetWordsContainNoExist(string query)
{
string[] words = await Drae.GetWordsContainAsync(query);

Assert.NotNull(words);
Assert.Empty(words);
}

[Theory]
[InlineData("avión")]
[InlineData("planeta")]
public async Task SearchWordExist(string word)
{
IEntry[] entries = await Drae.SearchWordAsync(word, true);

Assert.NotNull(entries);
Assert.NotEmpty(entries);
}

[Theory]
[InlineData("sdfsfsdfsfssdfsdfs")]
public async Task SearchWordNoExist(string word)
{
IEntry[] entries = await Drae.SearchWordAsync(word, true);

Assert.NotNull(entries);
Assert.Empty(entries);
}
}
29 changes: 29 additions & 0 deletions RAE.Tests/RAE.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RAE\RAE.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions RAE.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Loading

0 comments on commit 7ef9720

Please sign in to comment.