-
Notifications
You must be signed in to change notification settings - Fork 1
/
AvitoHtmlXPathTemplateFinderFixture.cs
55 lines (50 loc) · 2.14 KB
/
AvitoHtmlXPathTemplateFinderFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.IO;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
namespace Html.Template.Finder.Tests
{
[TestFixture]
public class AvitoHtmlXPathTemplateFinderFixture
{
[Test]
public void FindEntitiesTest()
{
AvitoEntity[] entities =
new HtmlXPathTemplateFinder<AvitoEntity>(
new HtmlXPathTemplateReader(
File.ReadAllText(Constants.AvitoXPathTemplateFile),
new HtmlTemplateOptions(
tabulator: " ",
Environment.NewLine)),
new JsonEntityFactory<AvitoEntity>(),
new HtmlXPathTemplateFinderOptions(trimValues: true, readTemplateOnInit: true))
.FindEntities(File.ReadAllText(Constants.AvitoHtmlFile))
.ToArray();
entities.Length.Should().Be(50);
for (int i = 0; i < entities.Length; i++)
{
var entity = entities[i];
entity.url.Should().NotBeNullOrEmpty();
entity.img.Should().NotBeNullOrEmpty();
entity.price.Should().NotBeNullOrEmpty();
entity.title.Should().NotBeNullOrEmpty();
entity.category.Should().NotBeNullOrEmpty();
entity.address.Should().NotBeNullOrEmpty();
entity.date.Should().NotBeNullOrEmpty();
}
VerifyAnEntity(entities.First());
}
private static void VerifyAnEntity(AvitoEntity entity)
{
entity.url.Should().Be("/chasy_i_ukrasheniya/apple_watch_5_kopiya_vysokogo_kachestva_2008604170");
entity.address.Should().Be("Гостиный двор");
entity.category.Should().Be("Часы и украшения");
entity.date.Should().Be("1 день назад");
entity.img.Should().Be("https://00.img.avito.st/208x156/9148229700.jpg");
entity.price.Should().Be("2 499 ₽");
entity.title.Should().Be("Apple watch 5 копия высокого качества");
}
}
}