Преглед изворни кода

Добавлены юнит-тесты

TriPSglitch пре 2 година
родитељ
комит
d8b4e625a7

+ 6 - 0
Cafe.sln

@@ -5,6 +5,8 @@ VisualStudioVersion = 17.2.32630.192
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cafe", "Cafe2\Cafe.csproj", "{3C1FDBA5-FF5C-4343-8D21-DC14A25D653C}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CafeTests", "CafeTests\CafeTests.csproj", "{F46E7A8F-B775-4437-BDF6-32B6C53CA461}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
 		{3C1FDBA5-FF5C-4343-8D21-DC14A25D653C}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{3C1FDBA5-FF5C-4343-8D21-DC14A25D653C}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{3C1FDBA5-FF5C-4343-8D21-DC14A25D653C}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F46E7A8F-B775-4437-BDF6-32B6C53CA461}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F46E7A8F-B775-4437-BDF6-32B6C53CA461}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F46E7A8F-B775-4437-BDF6-32B6C53CA461}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F46E7A8F-B775-4437-BDF6-32B6C53CA461}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 45 - 32
Cafe2/AddWindows/AddEmployeeWindow.xaml.cs

@@ -16,70 +16,76 @@ namespace Cafe.AddWindows
 
         private void RegistrationClick(object sender, RoutedEventArgs e)
         {
-            bool regRes = Registration(Login.Text.ToString(), Password.Password.ToString(), FirstName.Text.ToString(),
-                                        SecondName.Text.ToString(), MiddleName.Text.ToString(), Email.Text.ToString());
+
+
+            bool regRes = RegistrationValidation(Login.Text.ToString(), Password.Password.ToString(), FirstName.Text.ToString(),
+                                        SecondName.Text.ToString(), MiddleName.Text.ToString(), Email.Text.ToString(), 
+                                        RoleBox.SelectedItem.ToString());
 
             if (regRes)
             {
+                int roleID = GetRoleID(RoleBox.SelectedItem.ToString());
+
+                Users user = new Users()
+                {
+                    Login = Login.Text,
+                    Password = Encrypt.Hash(Password.Password),
+                    SecondName = SecondName.Text,
+                    FirstName = FirstName.Text,
+                    Email = Email.Text,
+                    IDRole = roleID,
+                    IsFired = false
+                };
+
+                if (MiddleName.Text != "")
+                {
+                    user.MiddleName = MiddleName.Text;
+                }
+
+                Connection.db.Users.Add(user);
+                Connection.db.SaveChanges();
+
                 MainWindow mainWindow = new MainWindow();
                 mainWindow.Show();
                 this.Close();
             }
         }
 
-        public bool Registration(string login, string password, string Fname, string Sname, string Mname, string email)
+        public bool RegistrationValidation(string login, string password, string Fname, string Sname, string Mname, string email, string roleName)
         {
-            if (Login.Text == "" || Password.Password == "" || FirstName.Text == "" || SecondName.Text == "" || Email.Text == "" || RoleBox.SelectedItem == null)
+            if (login == "" || password == "" || Fname == "" || Sname == "" || email == "" || roleName == "")
             {
                 ErrorWindow errorWindow = new ErrorWindow("пустые поля");
                 errorWindow.Show();
                 return false;
             }
-            if (Connection.db.Users.Select(item => item.Login).Contains(Login.Text))
+            if (UserLoginIsExist(login))
             {
                 ErrorWindow errorWindow = new ErrorWindow("такой пользователь уже существует");
                 errorWindow.Show();
                 return false;
             }
-            if (!IsValidEmail(Email.Text))
+            if (!IsValidEmail(email))
             {
                 ErrorWindow errorWindow = new ErrorWindow("неверный формат почты");
                 errorWindow.Show();
                 return false;
             }
 
-            string roleName = Convert.ToString(RoleBox.SelectedItem);
-            Roles role = Connection.db.Roles.Where(item => item.RoleName == roleName).FirstOrDefault();
-
-            Users user = new Users()
-            {
-                Login = Login.Text,
-                Password = Encrypt.Hash(Password.Password),
-                SecondName = SecondName.Text,
-                FirstName = FirstName.Text,
-                Email = Email.Text,
-                IDRole = role.ID,
-                IsFired = false
-            };
-            if (MiddleName.Text != "")
-            {
-                user.MiddleName = MiddleName.Text;
-            }
-
-            Connection.db.Users.Add(user);
-            Connection.db.SaveChanges();
-
             return true;
         }
 
-        private void BackButtonClick(object sender, RoutedEventArgs e)
+        public bool UserLoginIsExist(string login)
         {
-            MainWindow mainWindow = new MainWindow();
-            mainWindow.Show();
-            this.Close();
+            return Connection.db.Users.Select(item => item.Login).Contains(login);
         }
 
-        private bool IsValidEmail(string email)
+        public int GetRoleID(string roleName)
+        {
+            return Connection.db.Roles.Where(item => item.RoleName == roleName).Select(item => item.ID).FirstOrDefault();
+        }
+
+        public bool IsValidEmail(string email)
         {
             string regex = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
             if (Regex.IsMatch(email, regex))
@@ -88,6 +94,13 @@ namespace Cafe.AddWindows
                 return false;
         }
 
+        private void BackButtonClick(object sender, RoutedEventArgs e)
+        {
+            MainWindow mainWindow = new MainWindow();
+            mainWindow.Show();
+            this.Close();
+        }
+
         private void TextChanged(object sender, TextChangedEventArgs e)
         {
             if (Regex.IsMatch((((TextBox)sender).Text).ToString(), "[^А-я-:]"))

+ 84 - 41
Cafe2/AddWindows/AddExchangeWindow.xaml.cs

@@ -53,43 +53,85 @@ namespace Cafe.AddWindows
 
         private void SaveExchangeClick(object sender, RoutedEventArgs e)
         {
-            if (EmployeesList.Items == null)
+            List<Users> employees = new List<Users>();
+            foreach (var item in EmployeesList.Items)
+            {
+                employees.Add((Users)item);
+            }
+
+            if (!ExchangeValidation(employees, Date.Text, TimeOfBegin.Text, TimeOfEnd.Text))
+            {
+                return;
+            }
+
+            DateTime.TryParse(Date.Text, out DateTime dateResult);
+            TimeSpan.TryParse(TimeOfBegin.Text, out TimeSpan timeOfBeginResult);
+            TimeSpan.TryParse(TimeOfEnd.Text, out TimeSpan timeOfEndResult);
+
+            Exchange exchange = new Exchange()
+            {
+                Date = dateResult.Date,
+                TimeOfBegin = timeOfBeginResult,
+                TimeOfEnd = timeOfEndResult
+            };
+
+            Connection.db.Exchange.Add(exchange);
+            Connection.db.SaveChanges();
+
+            int idExchange = Connection.db.Exchange.Select(item => item.ID).ToList().Last();
+            foreach (var item in EmployeesList.Items)
+            {
+                EmployeesExchanges employeesExchanges = new EmployeesExchanges()
+                {
+                    IDEmployee = ((Users)item).ID,
+                    IDExchange = idExchange
+                };
+
+                Connection.db.EmployeesExchanges.Add(employeesExchanges);
+                Connection.db.SaveChanges();
+            }
+
+            MainWindow mainWindow = new MainWindow();
+            mainWindow.Show();
+            this.Close();
+        }
+
+        public bool ExchangeValidation(List<Users> employees, string date, string timeOfBegin, string timeOfEnd)
+        {
+            if (employees == null)
             {
                 ErrorWindow errorWindow = new ErrorWindow("не выбрано ни одного работника");
                 errorWindow.Show();
-                return;
+                return false;
             }
 
-            if (Date.Text == "" || TimeOfBegin.Text == "" || TimeOfEnd.Text == "")
+            if (date == "" || timeOfBegin == "" || timeOfEnd == "")
             {
                 ErrorWindow errorWindow = new ErrorWindow("не выбрано время");
                 errorWindow.Show();
-                return;
+                return false;
             }
 
-            TimeSpan timeOfBeginResult;
-            if (!TimeSpan.TryParse(TimeOfBegin.Text, out timeOfBeginResult) || TimeOfBegin.Text.Count(item => item == ':') != 1)
+            TimeValidation(timeOfBegin);
+            if (!TimeValidation(timeOfBegin))
             {
-                ErrorWindow errorWindow = new ErrorWindow("неверно указано время начала");
-                errorWindow.Show();
-                return;
+                return false;
             }
+            TimeSpan.TryParse(timeOfBegin, out TimeSpan timeOfBeginResult);
 
-            TimeSpan timeOfEndResult;
-            if (!TimeSpan.TryParse(TimeOfEnd.Text, out timeOfEndResult) || TimeOfEnd.Text.Count(item => item == ':') != 1)
+            TimeValidation(timeOfEnd);
+            if (!TimeValidation(timeOfEnd))
             {
-                ErrorWindow errorWindow = new ErrorWindow("неверно указано время окончания");
-                errorWindow.Show();
-                return;
+                return false;
             }
+            TimeSpan.TryParse(timeOfEnd, out TimeSpan timeOfEndResult);
 
-            DateTime dateResult;
-            if (!DateTime.TryParse(Date.Text, out dateResult) || Date.Text.Count(item => item == '.') != 2)
+            DateValidation(date);
+            if (!DateValidation(date))
             {
-                ErrorWindow errorWindow = new ErrorWindow("неверно указана дата");
-                errorWindow.Show();
-                return;
+                return false;
             }
+            DateTime.TryParse(date, out DateTime dateResult);
 
             List<Exchange> allExchangesOnDate = Connection.db.Exchange.Where(item => item.Date == dateResult).ToList();
 
@@ -98,42 +140,43 @@ namespace Cafe.AddWindows
             {
                 ErrorWindow errorWindow = new ErrorWindow("на это время уже запланирована смена");
                 errorWindow.Show();
-                return;
+                return false;
             }
 
             if (dateResult.Date - DateTime.Now.Date > new TimeSpan(5, 0, 0, 0))
             {
                 ErrorWindow errorWindow = new ErrorWindow("можно сформировать рассписание тольок на 5 дней вперёд");
                 errorWindow.Show();
-                return;
+                return false;
             }
 
-            Exchange exchange = new Exchange()
+            return true;
+        }
+
+        public bool TimeValidation(string time)
+        {
+            TimeSpan timeResult;
+            if (!TimeSpan.TryParse(time, out timeResult) || time.Count(item => item == ':') != 1)
             {
-                Date = dateResult.Date,
-                TimeOfBegin = timeOfBeginResult,
-                TimeOfEnd = timeOfEndResult
-            };
+                ErrorWindow errorWindow = new ErrorWindow("неверно указано время");
+                errorWindow.Show();
+                return false;
+            }
 
-            Connection.db.Exchange.Add(exchange);
-            Connection.db.SaveChanges();
+            return true;
+        }
 
-            int idExchange = Connection.db.Exchange.Select(item => item.ID).ToList().Last();
-            foreach (var item in EmployeesList.Items)
+        public bool DateValidation(string date)
+        {
+            DateTime dateResult;
+            if (!DateTime.TryParse(date, out dateResult) || date.Count(item => item == '.') != 2)
             {
-                EmployeesExchanges employeesExchanges = new EmployeesExchanges()
-                {
-                    IDEmployee = ((Users)item).ID,
-                    IDExchange = idExchange
-                };
-
-                Connection.db.EmployeesExchanges.Add(employeesExchanges);
-                Connection.db.SaveChanges();
+                ErrorWindow errorWindow = new ErrorWindow("неверно указана дата");
+                errorWindow.Show();
+                return false;
             }
 
-            MainWindow mainWindow = new MainWindow();
-            mainWindow.Show();
-            this.Close();
+            return true;
         }
 
         private void BackButtonClick(object sender, RoutedEventArgs e)

+ 2 - 4
Cafe2/AddWindows/AddOrderWindow.xaml.cs

@@ -60,7 +60,7 @@ namespace Cafe.AddWindows
                 return;
             }
 
-            Exchange exchange = GetExchange();
+            Exchange exchange = GetExchange(DateTime.Now);
 
             if (exchange is null)
             {
@@ -102,10 +102,8 @@ namespace Cafe.AddWindows
             this.Close();
         }
 
-        private Exchange GetExchange()
+        public Exchange GetExchange(DateTime now)
         {
-            DateTime now = DateTime.Now;
-
             return Connection.db.Exchange.Where(item => item.Date == now.Date && item.TimeOfBegin <= now.TimeOfDay && item.TimeOfEnd >= now.TimeOfDay).FirstOrDefault();
         }
 

+ 2 - 1
Cafe2/AuthorizationWindow.xaml.cs

@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
 using System.Windows;
 using Cafe.ListWindows;
 

+ 1 - 1
Cafe2/Connection.cs

@@ -1,6 +1,6 @@
 namespace Cafe
 {
-    internal class Connection
+    public class Connection
     {
         public static CafeEntities db = new CafeEntities();
     }

+ 1 - 1
Cafe2/Encrypt.cs

@@ -3,7 +3,7 @@ using System.Text;
 
 namespace Cafe
 {
-    internal class Encrypt
+    public class Encrypt
     {
         public static string Hash(string password)
         {

+ 0 - 1
Cafe2/MainWindow.xaml

@@ -12,7 +12,6 @@
                 <Grid Margin="-3,-22,-3,-2">
                     <Button x:Name="AddOrder" Content="Новый заказ" HorizontalAlignment="Center" Margin="0,302,0,0" VerticalAlignment="Top" Height="70" Width="530" FontSize="36" Click="AddOrderClick"/>
                     <Button x:Name="OrdersList" Content="История заказов" HorizontalAlignment="Center" Margin="0,394,0,0" VerticalAlignment="Top" Height="70" Width="530" FontSize="36" Click="OrdersListClick"/>
-                    <!--<Button x:Name="AddWaiterReport" Content="Отчет официанта" HorizontalAlignment="Center" Margin="0,486,0,0" VerticalAlignment="Top" Height="70" Width="530" FontSize="36" Click="AddWaiterReportClick"/>-->
                 </Grid>
             </TabItem>
             <TabItem Name="Administrator" Header="Администратор" Height="20" Width="100" Background="#FF4F5856">

+ 21 - 0
CafeTests/App.config

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <configSections>
+    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+  </configSections>
+  <connectionStrings>
+    <add name="CafeEntities" connectionString="metadata=res://*/Cafe.csdl|res://*/Cafe.ssdl|res://*/Cafe.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-5285QDG;initial catalog=Cafe;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
+  </connectionStrings>
+  <entityFramework>
+    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
+      <parameters>
+        <parameter value="mssqllocaldb" />
+      </parameters>
+    </defaultConnectionFactory>
+    <providers>
+      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
+    </providers>
+  </entityFramework>
+</configuration>

+ 90 - 0
CafeTests/CafeTests.csproj

@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" />
+  <Import Project="..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props')" />
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{F46E7A8F-B775-4437-BDF6-32B6C53CA461}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>CafeTests</RootNamespace>
+    <AssemblyName>CafeTests</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
+    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
+    <IsCodedUITest>False</IsCodedUITest>
+    <TestProjectType>UnitTest</TestProjectType>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.AspNet.Scaffolding.EntityFramework.12.0, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
+    </Reference>
+    <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
+    <Reference Include="System" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
+    <Reference Include="System.Core" />
+    <Reference Include="WindowsBase" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="UnitTest1.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+    <None Include="packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Cafe2\Cafe.csproj">
+      <Project>{3c1fdba5-ff5c-4343-8d21-dc14a25d653c}</Project>
+      <Name>Cafe</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их.  Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}.</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props'))" />
+    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets'))" />
+    <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
+    <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
+  </Target>
+  <Import Project="..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets')" />
+  <Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" />
+</Project>

+ 20 - 0
CafeTests/Properties/AssemblyInfo.cs

@@ -0,0 +1,20 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("CafeTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("CafeTests")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+[assembly: ComVisible(false)]
+
+[assembly: Guid("f46e7a8f-b775-4437-bdf6-32b6c53ca461")]
+
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 144 - 0
CafeTests/UnitTest1.cs

@@ -0,0 +1,144 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using Cafe;
+using Cafe.AddWindows;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows;
+
+namespace CafeTests
+{
+    [TestClass]
+    public class CafeTests
+    {
+        [TestMethod]
+        public void RegistrationValidationTest()
+        {
+            var window = new AddEmployeeWindow();
+
+            Assert.IsTrue(window.RegistrationValidation("TriPS", "123", "Карбышев", "Максим", "Евгеньевич", "kmacksim@yandex.ru", "администратор"));
+            Assert.IsTrue(window.RegistrationValidation("TriPS", "123", "Карбышев", "Максим", "", "kmacksim@yandex.ru", "администратор"));
+
+            Assert.IsFalse(window.RegistrationValidation("", "", "", "", "", "", ""));
+            Assert.IsFalse(window.RegistrationValidation("", "123", "Карбышев", "Максим", "Евгеньевич", "kmacksim@yandex.ru", "администратор"));
+            Assert.IsFalse(window.RegistrationValidation("TriPS", "", "Карбышев", "Максим", "Евгеньевич", "kmacksim@yandex.ru", "администратор"));
+            Assert.IsFalse(window.RegistrationValidation("TriPS", "123", "", "Максим", "Евгеньевич", "kmacksim@yandex.ru", "администратор"));
+            Assert.IsFalse(window.RegistrationValidation("TriPS", "123", "Карбышев", "", "Евгеньевич", "kmacksim@yandex.ru", "администратор"));
+            Assert.IsFalse(window.RegistrationValidation("TriPS", "123", "Карбышев", "Максим", "Евгеньевич", "", "администратор"));
+            Assert.IsFalse(window.RegistrationValidation("TriPS", "123", "Карбышев", "Максим", "Евгеньевич", "kmacksim@yandex.ru", ""));
+        }
+
+        [TestMethod]
+        public void GetRoleIDTest()
+        {
+            var window = new AddEmployeeWindow();
+
+            int expected1 = 1;
+            Assert.AreEqual(expected1, window.GetRoleID("администратор"));
+
+            int expected2 = 2;
+            Assert.AreEqual(expected2, window.GetRoleID("официант"));
+
+            int expected3 = 3;
+            Assert.AreEqual(expected3, window.GetRoleID("повар"));
+        }
+
+        [TestMethod]
+        public void UserLoginIsExistTest()
+        {
+            var window = new AddEmployeeWindow();
+
+            Assert.IsTrue(window.UserLoginIsExist("admin"));
+
+            Assert.IsFalse(window.UserLoginIsExist("TriPS"));
+        }
+
+        [TestMethod]
+        public void IsValidEmailTest()
+        {
+            var window = new AddEmployeeWindow();
+
+            Assert.IsTrue(window.IsValidEmail("kmacksim@yandex.ru"));
+            Assert.IsTrue(window.IsValidEmail("kmacksim@gmail.com"));
+
+            Assert.IsFalse(window.IsValidEmail("kmacksimyandexru"));
+            Assert.IsFalse(window.IsValidEmail("kmacksimyandex.ru"));
+            Assert.IsFalse(window.IsValidEmail("kmacksim-yandex.ru"));
+            Assert.IsFalse(window.IsValidEmail("kmac|ksim@yandex.ru"));
+        }
+
+        [TestMethod]
+        public void HashTest()
+        {
+            string password = "password123";
+            string expected = "f22ec811b8bf1cb6ac3aea13d3fcfebf";
+
+            Assert.AreEqual(expected, Encrypt.Hash(password));
+        }
+
+        [TestMethod]
+        public void ExchangeValidationTest()
+        {
+            Application.LoadComponent(new Uri("/Cafe2;component/App.xaml", UriKind.Relative));
+
+            var window = new AddExchangeWindow();
+
+            List<Users> employees = Connection.db.Users.Where(item => item.IDRole != 1).ToList();
+            List<Users> employeesNull = null;
+
+            Assert.IsTrue(window.ExchangeValidation(employees, "23.12.2022", "8:00", "17:00"));
+
+            Assert.IsFalse(window.ExchangeValidation(employeesNull, "23.12.2022", "8:00", "17:00"));
+            Assert.IsFalse(window.ExchangeValidation(employees, "", "8:00", "17:00"));
+            Assert.IsFalse(window.ExchangeValidation(employees, "23.12.2022", "", "17:00"));
+            Assert.IsFalse(window.ExchangeValidation(employees, "23.12.2022", "8:00", ""));
+            Assert.IsFalse(window.ExchangeValidation(employees, "01.01.2023", "8:00", "17:00"));
+            Assert.IsFalse(window.ExchangeValidation(employees, "23.12.2022", "25:00", "17:00"));
+            Assert.IsFalse(window.ExchangeValidation(employees, "23.12.2022", "8:00", "25:00"));
+            Assert.IsFalse(window.ExchangeValidation(employees, "23.12.2022", "8", "17:00"));
+            Assert.IsFalse(window.ExchangeValidation(employees, "23.12.2022", "8:00", "17"));
+        }
+
+        [TestMethod]
+        public void TimeValidationTest()
+        {
+            Application.LoadComponent(new Uri("/Cafe2;component/App.xaml", UriKind.Relative));
+
+            var window = new AddExchangeWindow();
+
+            Assert.IsTrue(window.TimeValidation("8:00"));
+
+            Assert.IsFalse(window.TimeValidation("25:00"));
+            Assert.IsFalse(window.TimeValidation("8"));
+            Assert.IsFalse(window.TimeValidation(""));
+        }
+
+        [TestMethod]
+        public void DateValidationTest()
+        {
+            Application.LoadComponent(new Uri("/Cafe2;component/App.xaml", UriKind.Relative));
+
+            var window = new AddExchangeWindow();
+
+            Assert.IsTrue(window.DateValidation("23.12.2022"));
+            Assert.IsTrue(window.DateValidation("2022.12.23"));
+
+            Assert.IsFalse(window.DateValidation("34.12.2022"));
+            Assert.IsFalse(window.DateValidation("23.13.2022"));
+            Assert.IsFalse(window.DateValidation("12.2022"));
+            Assert.IsFalse(window.DateValidation("23.2022"));
+            Assert.IsFalse(window.DateValidation("23.12"));
+        }
+
+        [TestMethod]
+        public void GetExchangeTest()
+        {
+            var window = new AddOrderWindow();
+
+            DateTime time = new DateTime(2022, 12, 22, 10, 0, 0);
+            Exchange expected = Connection.db.Exchange.Where(item => item.ID == 2).FirstOrDefault();
+
+            Assert.AreEqual(expected, window.GetExchange(time));
+        }
+    }
+}

+ 6 - 0
CafeTests/packages.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="EntityFramework" version="6.4.4" targetFramework="net472" />
+  <package id="MSTest.TestAdapter" version="2.2.7" targetFramework="net472" />
+  <package id="MSTest.TestFramework" version="2.2.7" targetFramework="net472" />
+</packages>