Skip to content

Commit

Permalink
refactor: Renamed projects for better segregation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Ivanov committed Jun 8, 2024
1 parent 648f50d commit 77cd2b4
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace WebSiteComparer.Core.Configurations;
namespace WebSiteComparer.Core.Configurations;

public class WebSiteComparerConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace WebSiteComparer.Core.Configurations;
namespace WebSiteComparer.Core.Configurations;

public class WebsiteConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using WebSiteComparer.Core.Configurations;
using WebSiteComparer.Core.Configurations;

namespace WebSiteComparer.Core.ChangesTracking;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using ImageProcessing.Models;
using ImageProcessing.Models;

namespace WebSiteComparer.Core.Screenshots;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ImageProcessing.Models;
using ImageProcessing.Models;
using Microsoft.Playwright;

namespace WebSiteComparer.Core.Screenshots;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using WebSiteComparer.Core.Configurations;
using WebSiteComparer.Core.Configurations;

namespace WebSiteComparer.Core.Screenshots;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>WebSiteComparer.Interfaces</RootNamespace>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Microsoft.Playwright" Version="1.41.0" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions UiTesting.Comparing/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo( "UiTesting.Comparing.Tests" )]
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Microsoft.Extensions.DependencyInjection;
using ImageProcessing;
using ImageProcessing.Implementation.Comparing;
using UiTesting.Comparing.Implementation.ChangesDetecting;
using UiTesting.Comparing.Implementation.Screenshots;
using WebSiteComparer.Core.ChangesTracking;
using WebSiteComparer.Core.Configurations;
using WebSiteComparer.Core.Implementation.ChangesDetecting;
using WebSiteComparer.Core.Implementation.Screenshots;
using WebSiteComparer.Core.Screenshots;

namespace WebSiteComparer.Core;
namespace UiTesting.Comparing;

public static class ConfigureDependencies
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
using UiTesting.Playwright.Factories;
using Microsoft.Extensions.Logging;
using Microsoft.Playwright;
using UiTesting.Comparing.Implementation.Extensions;
using WebSiteComparer.Core.ChangesTracking;
using WebSiteComparer.Core.Configurations;
using WebSiteComparer.Core.Implementation.Extensions;
using WebSiteComparer.Core.Screenshots;

namespace WebSiteComparer.Core.Implementation.ChangesDetecting;
namespace UiTesting.Comparing.Implementation.ChangesDetecting;

internal class ChangesDetector : IChangesDetector
{
private readonly IScreenshotTaker _screenshotTaker;
private readonly IScreenshotRepository _screenshotRepository;
private readonly IImageComparer _imageComparer;
private readonly ILogger _logger;

private readonly string _comparingOutputDirectory;

public ChangesDetector(
public ChangesDetector(
IImageComparer imageComparer,
ILogger<ChangesDetector> logger,
IScreenshotTaker screenshotTaker,
Expand All @@ -44,7 +44,7 @@ public Task FindChangesAsync( IEnumerable<WebsiteConfiguration> configurations )
var screenshotOptions = configurations
.SelectMany( configuration => configuration.Urls
.Select( url => new ScreenshotOptions(
new Uri( url ),
new Uri( url ),
configuration.ScreenshotWidth,
configuration.PageLoadingConfiguration ) ) )
.ToList();
Expand All @@ -55,7 +55,7 @@ public Task FindChangesAsync( IEnumerable<WebsiteConfiguration> configurations )
public Task FindChangesAsync( WebsiteConfiguration configuration )
{
var screenshotOptions = configuration.Urls
.Select( url => new ScreenshotOptions(
.Select( url => new ScreenshotOptions(
new Uri( url ),
configuration.ScreenshotWidth,
configuration.PageLoadingConfiguration ) )
Expand All @@ -72,25 +72,24 @@ private async Task FindChangesInternalAsync( List<ScreenshotOptions> screenshotO
directoryInfo.ClearDirectory();
}

await using ( var browserFactory = new BrowserFactory() )
{
IBrowser browser = await browserFactory.GetBrowserAsync();

await Parallel.ForEachAsync(
screenshotOptions,
async ( screenshotOption, _ ) =>
{
IPage page = await browser.NewPageAsync(
screenshotOption
.PageLoadingConfiguration
.ToPlaywrightPageOptions() );
CashedBitmap screenshot = await _screenshotTaker.TakeScreenshotAsync( page, screenshotOption );

await Task.WhenAll(
CompareToOldVersionAsync( screenshotOption.Uri, screenshot ),
page.CloseAsync() );
} );
}
await using var browserFactory = new BrowserFactory();
IBrowser browser = await browserFactory.GetBrowserAsync();

await Parallel.ForEachAsync(
screenshotOptions,
async ( screenshotOption, _ ) =>
{
IPage page = await browser.NewPageAsync(
screenshotOption
.PageLoadingConfiguration
.ToPlaywrightPageOptions() );

CashedBitmap screenshot = await _screenshotTaker.TakeScreenshotAsync( page, screenshotOption );

await Task.WhenAll(
CompareToOldVersionAsync( screenshotOption.Uri, screenshot ),
page.CloseAsync() );
} );
}

private async Task CompareToOldVersionAsync( Uri uri, CashedBitmap newState )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.IO;

namespace WebSiteComparer.Core.Implementation.Extensions;
namespace UiTesting.Comparing.Implementation.Extensions;

internal static class DirectoryInfoExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Playwright;
using WebSiteComparer.Core.Configurations;

namespace WebSiteComparer.Core.Implementation.Extensions;
namespace UiTesting.Comparing.Implementation.Extensions;

internal static class PageLoadingConfigurationExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Text;

namespace WebSiteComparer.Core.Implementation.Extensions;
namespace UiTesting.Comparing.Implementation.Extensions;

internal static class UriExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Microsoft.Playwright;
using WebSiteComparer.Core.Screenshots;

namespace WebSiteComparer.Core.Implementation.Screenshots;
namespace UiTesting.Comparing.Implementation.Screenshots;

internal class ScreenshotTaker : IScreenshotTaker
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.IO;
using ImageProcessing.Models;
using UiTesting.Comparing.Implementation.Extensions;
using WebSiteComparer.Core.Configurations;
using WebSiteComparer.Core.Implementation.Extensions;
using WebSiteComparer.Core.Screenshots;

namespace WebSiteComparer.Core.Implementation.Screenshots;
namespace UiTesting.Comparing.Implementation.Screenshots;

internal class ScreenshotsRepository : IScreenshotRepository
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,6 +17,7 @@
<ProjectReference Include="..\ImageProcessing.Extensions\ImageProcessing.Extensions.csproj" />
<ProjectReference Include="..\ImageProcessing\ImageProcessing.csproj" />
<ProjectReference Include="..\UiTesting.Playwright\UiTesting.Playwright.csproj" />
<ProjectReference Include="..\UiTesting.Comparing.Interfaces\UiTesting.Comparing.Interfaces.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion WebSiteComparer.Console/ConfigureDependencies.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using WebSiteComparer.Console.Commands;
using WebSiteComparer.Core;
using UiTesting.Comparing;
using WebSiteComparer.Core.Configurations;
using WebSiteComparer.UseCases;

Expand Down
4 changes: 2 additions & 2 deletions WebSiteComparer.Console/WebSiteComparer.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WebSiteComparer.Core\WebSiteComparer.Core.csproj" />
<ProjectReference Include="..\UiTesting.Comparing\UiTesting.Comparing.csproj" />
<ProjectReference Include="..\WebSiteComparer.UseCases\WebSiteComparer.UseCases.csproj" />
</ItemGroup>

Expand Down
3 changes: 0 additions & 3 deletions WebSiteComparer.Core/AssemblyInfo.cs

This file was deleted.

4 changes: 2 additions & 2 deletions WebSiteComparer.UseCases/WebSiteComparer.UseCases.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<ProjectReference Include="..\ImageProcessing.Extensions\ImageProcessing.Extensions.csproj" />
<ProjectReference Include="..\ImageProcessing\ImageProcessing.csproj" />
<ProjectReference Include="..\WebSiteComparer.Core\WebSiteComparer.Core.csproj" />
<ProjectReference Include="..\UiTesting.Comparing\UiTesting.Comparing.csproj" />
</ItemGroup>

</Project>
17 changes: 16 additions & 1 deletion WebSiteComparer.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebSiteComparer.Core", "WebSiteComparer.Core\WebSiteComparer.Core.csproj", "{97236950-46B3-4196-B1E6-CDE9CCC3D7A9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UiTesting.Comparing", "UiTesting.Comparing\UiTesting.Comparing.csproj", "{97236950-46B3-4196-B1E6-CDE9CCC3D7A9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Public", "Public", "{D9ECE104-9F8D-448E-B057-4C22279B056C}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -31,6 +31,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UI", "UI", "{F2B23B85-C5D9-
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebSiteComparer.Console", "WebSiteComparer.Console\WebSiteComparer.Console.csproj", "{04E8E77B-D3C2-4C1A-BDFB-49C6870E01B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UiTesting.Comparing.Interfaces", "UiTesting.Comparing.Interfaces\UiTesting.Comparing.Interfaces.csproj", "{98F96635-026D-43BB-825B-C8A151D061B1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{577AF1AD-BFF0-460D-9F66-AAE5F8EEE0B9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{F7483EBC-66FA-4BBA-B142-6F2EFA9AE1D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -65,12 +71,21 @@ Global
{04E8E77B-D3C2-4C1A-BDFB-49C6870E01B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04E8E77B-D3C2-4C1A-BDFB-49C6870E01B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04E8E77B-D3C2-4C1A-BDFB-49C6870E01B9}.Release|Any CPU.Build.0 = Release|Any CPU
{98F96635-026D-43BB-825B-C8A151D061B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98F96635-026D-43BB-825B-C8A151D061B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98F96635-026D-43BB-825B-C8A151D061B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98F96635-026D-43BB-825B-C8A151D061B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FB48C990-7318-412F-A4B3-9FAADC4A77E0} = {D9ECE104-9F8D-448E-B057-4C22279B056C}
{5CE0B3B7-7D3D-409E-BED3-8F5CAEAB0CBD} = {3E71BFB6-07F3-4E09-B265-9495EA6D50F8}
{30ACFF24-A636-4EAC-99ED-3C6AD5CBD214} = {3E71BFB6-07F3-4E09-B265-9495EA6D50F8}
{406A06C2-656B-46CE-9CBA-0FB39E791AE1} = {B909EDB8-23E6-4C63-966E-82C92BAC4DC4}
{04E8E77B-D3C2-4C1A-BDFB-49C6870E01B9} = {F2B23B85-C5D9-42BA-B104-0EBCDA9618B8}
{3E71BFB6-07F3-4E09-B265-9495EA6D50F8} = {577AF1AD-BFF0-460D-9F66-AAE5F8EEE0B9}
{97236950-46B3-4196-B1E6-CDE9CCC3D7A9} = {577AF1AD-BFF0-460D-9F66-AAE5F8EEE0B9}
{98F96635-026D-43BB-825B-C8A151D061B1} = {577AF1AD-BFF0-460D-9F66-AAE5F8EEE0B9}
{F7D8F3A5-7D76-4CBD-B2A1-B8F99CFF856D} = {577AF1AD-BFF0-460D-9F66-AAE5F8EEE0B9}
{326C8927-663B-402D-A149-5FF0620C6B42} = {F7483EBC-66FA-4BBA-B142-6F2EFA9AE1D8}
EndGlobalSection
EndGlobal

0 comments on commit 77cd2b4

Please sign in to comment.