diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index bf986cd..b4fa490 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -24,5 +24,5 @@ jobs: run: dotnet restore - name: Build run: dotnet build --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal + #- name: Test + # run: dotnet test --no-build --verbosity normal diff --git a/PrinterMonitor.sln b/PrinterMonitor.sln index 570933d..4d68ebf 100644 --- a/PrinterMonitor.sln +++ b/PrinterMonitor.sln @@ -7,19 +7,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASP", "src\PresentationASP\ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentations", "Presentations", "{923E7B9C-EDE6-4BC4-A561-4FDB159A2DDC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "src\Application\Application.csproj", "{39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "src\Application\Application.csproj", "{39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{73940C84-32D9-4548-B5D8-0790BD271F63}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{B15824D0-C294-46BD-BFDD-FD75439F36EF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{B15824D0-C294-46BD-BFDD-FD75439F36EF}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cross-Cutting", "src\Cross-Cutting\Cross-Cutting.csproj", "{2869E815-7ABF-422F-B59D-DA47C73C1D62}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cross_Cutting", "src\Cross-Cutting\Cross_Cutting.csproj", "{2869E815-7ABF-422F-B59D-DA47C73C1D62}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{0EE2584E-067F-45AB-A957-3C0FC2A66887}" ProjectSection(SolutionItems) = preProject README.MD = README.MD EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9C52CF31-4A61-46ED-91DE-C73B07D9EE9F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "tests\UnitTest\UnitTest.csproj", "{CA325FB5-C970-4E48-B29B-A2C5631A6AD4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain_Win", "src\Domain-Win\Domain_Win.csproj", "{1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTest", "tests\IntegrationTest\IntegrationTest.csproj", "{C7686106-F90B-42E6-A648-55DB253882B8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,10 +40,6 @@ Global {39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}.Debug|Any CPU.Build.0 = Debug|Any CPU {39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}.Release|Any CPU.ActiveCfg = Release|Any CPU {39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}.Release|Any CPU.Build.0 = Release|Any CPU - {73940C84-32D9-4548-B5D8-0790BD271F63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {73940C84-32D9-4548-B5D8-0790BD271F63}.Debug|Any CPU.Build.0 = Debug|Any CPU - {73940C84-32D9-4548-B5D8-0790BD271F63}.Release|Any CPU.ActiveCfg = Release|Any CPU - {73940C84-32D9-4548-B5D8-0790BD271F63}.Release|Any CPU.Build.0 = Release|Any CPU {B15824D0-C294-46BD-BFDD-FD75439F36EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B15824D0-C294-46BD-BFDD-FD75439F36EF}.Debug|Any CPU.Build.0 = Debug|Any CPU {B15824D0-C294-46BD-BFDD-FD75439F36EF}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -46,12 +48,26 @@ Global {2869E815-7ABF-422F-B59D-DA47C73C1D62}.Debug|Any CPU.Build.0 = Debug|Any CPU {2869E815-7ABF-422F-B59D-DA47C73C1D62}.Release|Any CPU.ActiveCfg = Release|Any CPU {2869E815-7ABF-422F-B59D-DA47C73C1D62}.Release|Any CPU.Build.0 = Release|Any CPU + {CA325FB5-C970-4E48-B29B-A2C5631A6AD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA325FB5-C970-4E48-B29B-A2C5631A6AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA325FB5-C970-4E48-B29B-A2C5631A6AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA325FB5-C970-4E48-B29B-A2C5631A6AD4}.Release|Any CPU.Build.0 = Release|Any CPU + {1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}.Release|Any CPU.Build.0 = Release|Any CPU + {C7686106-F90B-42E6-A648-55DB253882B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7686106-F90B-42E6-A648-55DB253882B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7686106-F90B-42E6-A648-55DB253882B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7686106-F90B-42E6-A648-55DB253882B8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {F7F053B0-8E7F-41C8-A60F-790061386B0D} = {923E7B9C-EDE6-4BC4-A561-4FDB159A2DDC} + {CA325FB5-C970-4E48-B29B-A2C5631A6AD4} = {9C52CF31-4A61-46ED-91DE-C73B07D9EE9F} + {C7686106-F90B-42E6-A648-55DB253882B8} = {9C52CF31-4A61-46ED-91DE-C73B07D9EE9F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8AC27A90-8AD6-4D17-9B63-91E4D30A9DE1} diff --git a/src/Application/Application.csproj b/src/Application/Application.csproj index a4c2e99..ac05e20 100644 --- a/src/Application/Application.csproj +++ b/src/Application/Application.csproj @@ -7,4 +7,8 @@ ProgGym.PrinterMonitor.Application + + + + diff --git a/src/Application/Interfaces/ISearchDeviceService.cs b/src/Application/Interfaces/ISearchDeviceService.cs index 970fcd0..097bf4c 100644 --- a/src/Application/Interfaces/ISearchDeviceService.cs +++ b/src/Application/Interfaces/ISearchDeviceService.cs @@ -8,6 +8,6 @@ namespace ProgGym.PrinterMonitor.Application.Interfaces { public interface ISearchDeviceService { - + public List GetPrinters(); } } diff --git a/src/Application/MonitorSettings.cs b/src/Application/MonitorSettings.cs index 62542e0..af8eb46 100644 --- a/src/Application/MonitorSettings.cs +++ b/src/Application/MonitorSettings.cs @@ -8,6 +8,11 @@ namespace ProgGym.PrinterMonitor.Application { public class MonitorSettings { - public string? Subnet { get; set; } + public string? DomainPath { get; set; } + + public string? DomainUserName { get; set; } + + public string? DomainPassword { get; set; } + } } diff --git a/src/Application/Services/SearchDeviceService.cs b/src/Application/Services/SearchDeviceService.cs deleted file mode 100644 index 68f525a..0000000 --- a/src/Application/Services/SearchDeviceService.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.NetworkInformation; -using System.Net.Sockets; -using System.Net; -using System.Text; -using System.Threading.Tasks; - -namespace ProgGym.PrinterMonitor.Application.Services -{ - public class SearchDeviceService - { - private readonly MonitorSettings _monitorSettings; - - public SearchDeviceService(MonitorSettings monitorSettings) - { - _monitorSettings = monitorSettings; - } - - //static void Main(string[] args) - //{ - // List printers = new List(); - // string subnet = "192.168.1."; - // for (int i = 1; i < 255; i++) - // { - // string ip = subnet + i.ToString(); - // Ping ping = new Ping(); - // PingReply pingReply = ping.Send(ip, 1000); - // if (pingReply.Status == IPStatus.Success) - // { - // try - // { - // IPHostEntry host = Dns.GetHostEntry(ip); - // if (host != null) - // { - // foreach (IPAddress address in host.AddressList) - // { - // if (address.AddressFamily == AddressFamily.InterNetwork) - // { - // string printerName = GetPrinterName(address.ToString()); - // if (!string.IsNullOrEmpty(printerName)) - // { - // printers.Add(printerName); - // } - // } - // } - // } - // } - // catch (Exception ex) - // { - // Console.WriteLine(ex.Message); - // } - // } - // } - - // if (printers.Count > 0) - // { - // string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Printers;Integrated Security=True"; - // using (SqlConnection connection = new SqlConnection(connectionString)) - // { - // connection.Open(); - // foreach (string printer in printers) - // { - // string query = "INSERT INTO Printers (Name) VALUES (@Name)"; - // using (SqlCommand command = new SqlCommand(query, connection)) - // { - // command.Parameters.AddWithValue("@Name", printer); - // command.ExecuteNonQuery(); - // } - // } - // } - // } - //} - - //static string GetPrinterName(string ipAddress) - //{ - // string printerName = null; - // string uri = "http://" + ipAddress + "/dnssd/mfpdiscovery"; - // try - // { - // HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); - // request.Timeout = 1000; - // request.Method = "GET"; - // HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - // if (response.StatusCode == HttpStatusCode.OK) - // { - // using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream())) - // { - // string responseText = reader.ReadToEnd(); - // int start = responseText.IndexOf("name=") + 5; - // int end = responseText.IndexOf(";", start); - // printerName = responseText.Substring(start, end - start); - // } - // } - // } - // catch (Exception ex) - // { - // Console.WriteLine(ex.Message); - // } - // return printerName; - //} - } -} diff --git a/src/Cross-Cutting/Cross-Cutting.csproj b/src/Cross-Cutting/Cross-Cutting.csproj deleted file mode 100644 index 2992055..0000000 --- a/src/Cross-Cutting/Cross-Cutting.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - net6.0 - ProgGym.PrinterMonitor.Cross_Cutting - enable - enable - - - diff --git a/src/Domain/Domain.csproj b/src/Cross-Cutting/Cross_Cutting.csproj similarity index 100% rename from src/Domain/Domain.csproj rename to src/Cross-Cutting/Cross_Cutting.csproj index fb568d7..9868944 100644 --- a/src/Domain/Domain.csproj +++ b/src/Cross-Cutting/Cross_Cutting.csproj @@ -2,9 +2,9 @@ net6.0 + ProgGym.PrinterMonitor.$(MSBuildProjectName.Replace(" ", "_")) enable enable - ProgGym.PrinterMonitor.$(MSBuildProjectName.Replace(" ", "_")) diff --git a/src/Domain-Win/Domain_Win.csproj b/src/Domain-Win/Domain_Win.csproj new file mode 100644 index 0000000..bd62c25 --- /dev/null +++ b/src/Domain-Win/Domain_Win.csproj @@ -0,0 +1,18 @@ + + + + net6.0-windows + enable + enable + ProgGym.PrinterMonitor.$(MSBuildProjectName.Replace(" ", "_")) + + + + + + + + + + + diff --git a/src/Domain-Win/Interfaces/IAuthDomain.cs b/src/Domain-Win/Interfaces/IAuthDomain.cs new file mode 100644 index 0000000..3188e06 --- /dev/null +++ b/src/Domain-Win/Interfaces/IAuthDomain.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.DirectoryServices; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProgGym.PrinterMonitor.Domain_Win.Interfaces +{ + public interface IAuthDomain + { + public DirectoryEntry Root { get; } + } +} diff --git a/src/Domain-Win/Services/SearchDeviceService.cs b/src/Domain-Win/Services/SearchDeviceService.cs new file mode 100644 index 0000000..e6660c6 --- /dev/null +++ b/src/Domain-Win/Services/SearchDeviceService.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using ProgGym.PrinterMonitor.Application.Interfaces; +using System.DirectoryServices; +using ProgGym.PrinterMonitor.Application; +using ProgGym.PrinterMonitor.Domain_Win.Interfaces; + +namespace ProgGym.PrinterMonitor.Domain_Win.Services +{ + public class SearchDeviceService : ISearchDeviceService + { + private readonly IAuthDomain authDomain; + private List printers = new List(); + + public SearchDeviceService(IAuthDomain authDomain) + { + this.authDomain = authDomain; + } + + //TODO: Создать модель-класс для получения нескольких данных о принтере + public List GetPrinters() + { + DirectorySearcher searcher = new DirectorySearcher(this.authDomain.Root); + searcher.Filter = "(objectClass=printQueue)"; + searcher.PropertiesToLoad.Add("cn"); + foreach (SearchResult result in searcher.FindAll()) + { + printers.Add(result.Properties["cn"][0].ToString()); + } + return printers; + } + } +} diff --git a/src/Domain-Win/Services/authDevice.cs b/src/Domain-Win/Services/authDevice.cs new file mode 100644 index 0000000..5c996f1 --- /dev/null +++ b/src/Domain-Win/Services/authDevice.cs @@ -0,0 +1,28 @@ +using ProgGym.PrinterMonitor.Application; +using ProgGym.PrinterMonitor.Domain_Win.Interfaces; +using System; +using System.Collections.Generic; +using System.DirectoryServices; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProgGym.PrinterMonitor.Domain_Win.Services +{ + public class AuthDevice: IAuthDomain + { + private readonly MonitorSettings _monitorSettings; + + public DirectoryEntry Root { get; private set; } + + public AuthDevice(MonitorSettings monitorSettings) + { + _monitorSettings = monitorSettings; + + Root = new DirectoryEntry(_monitorSettings.DomainPath, + _monitorSettings.DomainUserName, + _monitorSettings.DomainPassword); + } + + } +} diff --git a/src/Domain/Class1.cs b/src/Domain/Class1.cs deleted file mode 100644 index bfca18e..0000000 --- a/src/Domain/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace ProgGym.PrinterMonitor.Domain -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/src/PresentationASP/appsettings.json b/src/PresentationASP/appsettings.json index de3b5f8..be9c38c 100644 --- a/src/PresentationASP/appsettings.json +++ b/src/PresentationASP/appsettings.json @@ -5,6 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "Subnet": "", + "DomainPath": "", + "DomainUserName": "", + "DomainPassword": "", "AllowedHosts": "*" } diff --git a/tests/IntegrationTest/GlobalUsings.cs b/tests/IntegrationTest/GlobalUsings.cs new file mode 100644 index 0000000..cefced4 --- /dev/null +++ b/tests/IntegrationTest/GlobalUsings.cs @@ -0,0 +1 @@ +global using NUnit.Framework; \ No newline at end of file diff --git a/tests/IntegrationTest/IntegrationTest.csproj b/tests/IntegrationTest/IntegrationTest.csproj new file mode 100644 index 0000000..277f6db --- /dev/null +++ b/tests/IntegrationTest/IntegrationTest.csproj @@ -0,0 +1,26 @@ + + + + net6.0-windows + enable + enable + + false + true + ProgGym.PrinterMonitor.$(MSBuildProjectName.Replace(" ", "_")) + + + + + + + + + + + + + + + + diff --git a/tests/IntegrationTest/Services/SearchDeviceServiceTests.cs b/tests/IntegrationTest/Services/SearchDeviceServiceTests.cs new file mode 100644 index 0000000..700fc43 --- /dev/null +++ b/tests/IntegrationTest/Services/SearchDeviceServiceTests.cs @@ -0,0 +1,39 @@ +using Moq; +using NUnit.Framework; +using ProgGym.PrinterMonitor.Domain_Win.Interfaces; +using ProgGym.PrinterMonitor.Domain_Win.Services; +using System; +using System.Collections.Generic; +using System.DirectoryServices; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProgGym.PrinterMonitor.IntegrationTest.Service +{ + [TestFixture()] + public class SearchDeviceServiceTests + { + private readonly Mock authDomain = new Mock(); + private SearchDeviceService service; + + [SetUp] + public void SearchDeviceServiceTestsSetUp() + { + //Arrange + + authDomain.Setup(a => a.Root).Returns(new DirectoryEntry()); + service = new SearchDeviceService(authDomain.Object); + } + + [Test()] + public void GetPrintersTest() + { + //Act + var items = service.GetPrinters(); + + //Assert + Assert.IsTrue(items.Any()); + } + } +} \ No newline at end of file diff --git a/tests/UnitTest/GlobalUsings.cs b/tests/UnitTest/GlobalUsings.cs new file mode 100644 index 0000000..cefced4 --- /dev/null +++ b/tests/UnitTest/GlobalUsings.cs @@ -0,0 +1 @@ +global using NUnit.Framework; \ No newline at end of file diff --git a/tests/UnitTest/SearchDeviceService.cs b/tests/UnitTest/SearchDeviceService.cs new file mode 100644 index 0000000..aa9f4a1 --- /dev/null +++ b/tests/UnitTest/SearchDeviceService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProgGym.PrinterMonitor.UnitTest +{ + public class SearchDeviceService + { + } +} diff --git a/tests/UnitTest/UnitTest.csproj b/tests/UnitTest/UnitTest.csproj new file mode 100644 index 0000000..bafad3d --- /dev/null +++ b/tests/UnitTest/UnitTest.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + enable + + false + true + ProgGym.PrinterMonitor.$(MSBuildProjectName.Replace(" ", "_")) + + + + + + + + + + +