Made progress on implementing some shops.
Performed some folder restructuring as well.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Props.Shop.Adafruit.Api;
|
||||
using Xunit;
|
||||
|
||||
namespace Props.Shop.Adafruit.Tests
|
||||
{
|
||||
public class ListingParserTest
|
||||
{
|
||||
[Fact]
|
||||
public void TestParsing()
|
||||
{
|
||||
ListingsParser mockParser = new ListingsParser(File.ReadAllText("./Assets/products.json"));
|
||||
Assert.NotEmpty(mockParser.ProductListings);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Props.Shop.Adafruit.Api;
|
||||
using Props.Shop.Framework;
|
||||
using Xunit;
|
||||
|
||||
namespace Props.Shop.Adafruit.Tests.Api
|
||||
{
|
||||
public class ProductListingManagerTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task TestSearch()
|
||||
{
|
||||
ProductListingManager mockProductListingManager = new ProductListingManager();
|
||||
mockProductListingManager.SetListings(File.ReadAllText("./Assets/products.json"));
|
||||
List<ProductListing> results = new List<ProductListing>();
|
||||
await foreach (ProductListing item in mockProductListingManager.Search("arduino", 0.5f))
|
||||
{
|
||||
results.Add(item);
|
||||
}
|
||||
Assert.NotEmpty(results);
|
||||
}
|
||||
}
|
||||
}
|
158548
Props-Modules/test/Props.Shop/Adafruit.Tests/Assets/products.json
Normal file
158548
Props-Modules/test/Props.Shop/Adafruit.Tests/Assets/products.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -20,8 +20,13 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\Libraries\SimpleLogger\SimpleLogger.csproj" />
|
||||
<ProjectReference Include="..\..\..\Props.Shop\AliExpressModule\Props.Shop.AliExpressModule.csproj" />
|
||||
<ProjectReference Include="..\..\..\Props.Shop\Adafruit\Props.Shop.Adafruit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@@ -1,59 +0,0 @@
|
||||
using Props.Shop.Framework;
|
||||
using SimpleLogger;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Props.Shop.AliExpressModule.Tests
|
||||
{
|
||||
public class ShopTest
|
||||
{
|
||||
public ShopTest(ITestOutputHelper output)
|
||||
{
|
||||
Logger.AddLogListener(new XUnitLogger(output));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Search_SearchForItem_MultiplePages()
|
||||
{
|
||||
//Given
|
||||
const int MAX_RESULTS = 120;
|
||||
Shop shop = new Shop();
|
||||
shop.UseProxy = false;
|
||||
shop.Initialize();
|
||||
//When
|
||||
shop.SetupSession("mpu6050", Currency.CAD);
|
||||
//Then
|
||||
int count = 0;
|
||||
await foreach (ProductListing listing in shop)
|
||||
{
|
||||
Assert.False(string.IsNullOrWhiteSpace(listing.Name));
|
||||
count += 1;
|
||||
if (count > MAX_RESULTS) return;
|
||||
}
|
||||
shop.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Search_USD_ResultsFound()
|
||||
{
|
||||
//Given
|
||||
const int MAX_RESULTS = 120;
|
||||
Shop shop = new Shop();
|
||||
shop.UseProxy = false;
|
||||
shop.Initialize();
|
||||
//When
|
||||
shop.SetupSession("mpu6050", Currency.USD);
|
||||
//Then
|
||||
|
||||
int count = 0;
|
||||
await foreach (ProductListing listing in shop)
|
||||
{
|
||||
Assert.False(string.IsNullOrWhiteSpace(listing.Name));
|
||||
Assert.True(listing.LowerPrice != 0);
|
||||
count += 1;
|
||||
if (count > MAX_RESULTS) return;
|
||||
}
|
||||
shop.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using SimpleLogger;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Props.Shop.AliExpressModule
|
||||
{
|
||||
public class XUnitLogger : ILogReceiver
|
||||
{
|
||||
public LogLevel Level => LogLevel.Debug;
|
||||
|
||||
public string Identifier => GetType().Name;
|
||||
|
||||
private ITestOutputHelper outputHelper;
|
||||
|
||||
public XUnitLogger(ITestOutputHelper output)
|
||||
{
|
||||
this.outputHelper = output;
|
||||
}
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
}
|
||||
|
||||
public void LogMessage(string message, DateTime time, LogLevel level)
|
||||
{
|
||||
try
|
||||
{
|
||||
outputHelper.WriteLine($"[{time.ToShortTimeString()}][{level.ToString()}]: {message}");
|
||||
}
|
||||
catch (InvalidOperationException) { };
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="1.3.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Props.Shop\BanggoodModule\Props.Shop.BanggoodModule.csproj" />
|
||||
<ProjectReference Include="..\..\..\..\Libraries\SimpleLogger\SimpleLogger.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@@ -1,35 +0,0 @@
|
||||
using Props.Shop.Framework;
|
||||
using SimpleLogger;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Props.Shop.BanggoodModule.Tests
|
||||
{
|
||||
public class ShopTest
|
||||
{
|
||||
public ShopTest(ITestOutputHelper output)
|
||||
{
|
||||
Logger.AddLogListener(new XUnitLogger(output));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Search_CAD_ResultsFound()
|
||||
{
|
||||
//Given
|
||||
const int MAX_RESULTS = 100;
|
||||
Shop shop = new Shop();
|
||||
shop.UseProxy = false;
|
||||
//When
|
||||
shop.Initialize();
|
||||
shop.SetupSession("samsung galaxy 20 case", Currency.CAD);
|
||||
//Then
|
||||
int count = 0;
|
||||
await foreach (ProductListing listing in shop)
|
||||
{
|
||||
count += 1;
|
||||
Assert.False(string.IsNullOrWhiteSpace(listing.Name));
|
||||
if (count >= MAX_RESULTS) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using SimpleLogger;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Props.Shop.BanggoodModule
|
||||
{
|
||||
public class XUnitLogger : ILogReceiver
|
||||
{
|
||||
public LogLevel Level => LogLevel.Debug;
|
||||
|
||||
public string Identifier => GetType().Name;
|
||||
|
||||
private ITestOutputHelper outputHelper;
|
||||
|
||||
public XUnitLogger(ITestOutputHelper output)
|
||||
{
|
||||
this.outputHelper = output;
|
||||
}
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
}
|
||||
|
||||
public void LogMessage(string message, DateTime time, LogLevel level)
|
||||
{
|
||||
try
|
||||
{
|
||||
outputHelper.WriteLine($"[{time.ToShortTimeString()}][{level.ToString()}]: {message}");
|
||||
}
|
||||
catch (InvalidOperationException) { };
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user