Lera před 5 měsíci
rodič
revize
bea2aa2fea

+ 7 - 1
FoodLogProject.sln

@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio Version 17
 VisualStudioVersion = 17.10.34916.146
 MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodLogProject", "FoodLogProject\FoodLogProject.csproj", "{640F69B6-A6B0-427B-A953-1C5F0844632B}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodLogProject", "FoodLogProject\FoodLogProject.csproj", "{640F69B6-A6B0-427B-A953-1C5F0844632B}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject2", "TestProject2\TestProject2.csproj", "{184AFB59-07EB-48CF-B126-6E5BC9B71562}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
 		{640F69B6-A6B0-427B-A953-1C5F0844632B}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{640F69B6-A6B0-427B-A953-1C5F0844632B}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{640F69B6-A6B0-427B-A953-1C5F0844632B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{184AFB59-07EB-48CF-B126-6E5BC9B71562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{184AFB59-07EB-48CF-B126-6E5BC9B71562}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{184AFB59-07EB-48CF-B126-6E5BC9B71562}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{184AFB59-07EB-48CF-B126-6E5BC9B71562}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 2 - 1
FoodLogProject/FoodLogProject.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <OutputType>WinExe</OutputType>
-    <TargetFramework>net8.0</TargetFramework>
+    <TargetFramework>net7.0</TargetFramework>
     <Nullable>enable</Nullable>
     <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
     <ApplicationManifest>app.manifest</ApplicationManifest>
@@ -22,6 +22,7 @@
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
     <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
     <PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

+ 59 - 0
FoodLogProject/GaruaevContext.cs

@@ -1,12 +1,71 @@
 using System;
 using System.Collections.Generic;
+using System.Text.RegularExpressions;
 using Microsoft.EntityFrameworkCore;
 
 namespace FoodLogProject;
 
 public partial class GaruaevContext : DbContext
 {
+    public bool CheckRegNumber(string numberInput)
+    {
+
+        Regex number = new Regex("^8\\(\\d{3}\\)\\d{3}-\\d{2}-\\d{2}$");
+        if (number.IsMatch(numberInput))
+        {
+            //ShowMessageNumber.Text = "Номер введен некоректно";
+            return true;
+        }
+        return false;
+    }
+
+    public bool CheckRegName(string numberInput)
+    {
 
+        Regex number = new Regex("^[А-Я]{1}[а-я]{1,}$");
+        if (number.IsMatch(numberInput))
+        {
+            //ShowMessageNumber.Text = "Номер введен некоректно";
+            return true;
+        }
+        return false;
+    }
+
+    public bool CheckRegHeight(string numberInput)
+    {
+
+        Regex number = new Regex("^\\d+$");
+        if (number.IsMatch(numberInput))
+        {
+            //ShowMessageNumber.Text = "Номер введен некоректно";
+            return true;
+        }
+        return false;
+    }
+
+    public bool CheckRegWeight(string numberInput)
+    {
+
+        Regex number = new Regex("^\\d+$");
+        if (number.IsMatch(numberInput))
+        {
+            //ShowMessageNumber.Text = "Номер введен некоректно";
+            return true;
+        }
+        return false;
+    }
+
+    public bool CheckRegPassword(string numberInput)
+    {
+
+        Regex number = new Regex("\\S");
+        if (number.IsMatch(numberInput))
+        {
+            //ShowMessageNumber.Text = "Номер введен некоректно";
+            return true;
+        }
+        return false;
+    }
     public GaruaevContext()
     {
     }

+ 7 - 0
FoodLogProject/Program.cs

@@ -1,6 +1,7 @@
 using Avalonia;
 using Avalonia.ReactiveUI;
 using System;
+using System.Text.RegularExpressions;
 
 namespace FoodLogProject
 {
@@ -9,6 +10,10 @@ namespace FoodLogProject
         // Initialization code. Don't use any Avalonia, third-party APIs or any
         // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
         // yet and stuff might break.
+
+
+        
+
         [STAThread]
         public static void Main(string[] args)
         {
@@ -24,5 +29,7 @@ namespace FoodLogProject
                 .LogToTrace()
                 .UseReactiveUI();
 
+        
+
     }
 }

+ 1 - 1
FoodLogProject/ViewModels/MainWindowViewModel.cs

@@ -47,7 +47,7 @@ namespace FoodLogProject.ViewModels
             Customer? currentUser = myConnection.Customers.FirstOrDefault(x => x.CustomerPhone == Page2VM.Phone && x.CustomerPassword == Page2VM.Password);
             if (currentUser == null)
             {
-                Page2VM.Message = "Нет такого пользователя";
+                Page2VM.Message = "Пользователь с таким номером не зарегистрирован";
             }
             else
             {

+ 3 - 1
FoodLogProject/Views/MainWindow.axaml.cs

@@ -9,5 +9,7 @@ namespace FoodLogProject.Views
         {
             InitializeComponent();
         }
-    }
+
+        
+        }
 }

+ 3 - 3
FoodLogProject/Views/Page3.axaml

@@ -36,7 +36,7 @@
 							Данные для вашего плана
 						</TextBlock>
 						<TextBlock>Никнейм</TextBlock>
-						<TextBox Text="{Binding Page3VM.CurrentUser.CustomerNickname}" Watermark="Введите никнейм"></TextBox>
+						<TextBox Name="Name" Text="{Binding Page3VM.CurrentUser.CustomerNickname}" Watermark="Введите никнейм"></TextBox>
 						<TextBlock Name="ShowMessageName" Foreground="Red"></TextBlock>
 
 					</StackPanel>
@@ -44,7 +44,7 @@
 					<StackPanel >
 
 						<TextBlock>Номер телефона</TextBlock>
-						<TextBox Text="{Binding Page3VM.CurrentUser.CustomerPhone}" Watermark="+7***********"></TextBox>
+						<TextBox Name="Number" Text="{Binding Page3VM.CurrentUser.CustomerPhone}" Watermark="8***********"></TextBox>
 						<TextBlock Name="ShowMessageNumber" Foreground="Red"></TextBlock>
 							<TextBlock >Пароль:</TextBlock>
 							<TextBox Text="{Binding Page3VM.CurrentUser.CustomerPassword}" PasswordChar="*" Watermark="Введите пароль"/>
@@ -268,7 +268,7 @@
 
 				</StackPanel>
 			</Border>
-			<Button Foreground="White" Background="Green" HorizontalAlignment="Center" Margin="40" Content="Составить индивидуальный план питания" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).LoadPage2Create}"/>
+			<Button Foreground="White" Background="Green" HorizontalAlignment="Center" Margin="40" Content="Составить индивидуальный план питания" Click="CheckRegName"/>
 		</StackPanel>	
 	</StackPanel>
 		</ScrollViewer>

+ 26 - 0
FoodLogProject/Views/Page3.axaml.cs

@@ -1,6 +1,9 @@
 using Avalonia;
 using Avalonia.Controls;
+using Avalonia.Interactivity;
 using Avalonia.Markup.Xaml;
+using System;
+using System.Text.RegularExpressions;
 
 namespace FoodLogProject.Views;
 
@@ -9,5 +12,28 @@ public partial class Page3 : UserControl
     public Page3()
     {
         InitializeComponent();
+        
+    }
+
+    public void CheckRegNumber(object sender, RoutedEventArgs e)
+    {
+        bool check1;
+        Regex number = new Regex("^8\\(\\d{3}\\)\\d{3}-\\d{2}-\\d{2}$");
+        if (!number.IsMatch(Number.Text))
+        {
+            ShowMessageNumber.Text = "Íîìåð ââåäåí íåêîðåêòíî";
+            check1 = false;
+        }
+    }
+
+    public void CheckRegName(object sender, RoutedEventArgs e)
+    {
+        bool check2;
+        Regex number = new Regex("^[À-ß]{1}[à-ÿ]{1,}$");
+        if (!number.IsMatch(Name.Text))
+        {
+            ShowMessageName.Text = "Íèêíåéì ââåäåí íåêîðåêòíî";
+            check2 = false;
+        }
     }
 }

+ 23 - 0
FoodLogTesting/FoodLogTesting.csproj

@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net7.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+
+    <IsPackable>false</IsPackable>
+    <IsTestProject>true</IsTestProject>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
+    <PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
+    <PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
+    <PackageReference Include="coverlet.collector" Version="3.2.0" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\FoodLogProject\FoodLogProject.csproj" />
+  </ItemGroup>
+
+</Project>

+ 2 - 0
FoodLogTesting/GlobalUsings.cs

@@ -0,0 +1,2 @@
+global using Microsoft.VisualStudio.TestTools.UnitTesting;
+using FoodLogProject;

+ 91 - 0
FoodLogTesting/UnitTest1.cs

@@ -0,0 +1,91 @@
+
+namespace FoodLogTesting
+{
+    [TestClass]
+    public class UnitTest1
+    {
+        
+            [TestMethod]
+            public void UserNumber_AreEqual()
+            {
+            
+            
+            
+            }
+
+        [TestMethod]
+        public void UserNumber_AreNotEqual()
+        {
+
+
+
+        }
+
+        [TestMethod]
+        public void UserPassword_AreEqual()
+        {
+
+
+
+        }
+
+        [TestMethod]
+        public void UserPassword_AreNotEqual()
+        {
+
+
+
+        }
+
+        [TestMethod]
+        public void UserNick_AreEqual()
+        {
+
+
+
+        }
+
+        [TestMethod]
+        public void UserNick_AreNotEqual()
+        {
+
+
+
+        }
+
+
+        [TestMethod]
+        public void UserHeight_AreEqual()
+        {
+
+
+
+        }
+
+        [TestMethod]
+        public void UserHeight_AreNotEqual()
+        {
+
+
+
+        }
+
+
+        [TestMethod]
+        public void UserWeight_AreEqual()
+        {
+
+
+
+        }
+
+        [TestMethod]
+        public void UserWeight_AreNotEqual()
+        {
+
+
+
+        }
+
+    }
+}

+ 24 - 0
FoodLogTests/FoodLogTests.csproj

@@ -0,0 +1,24 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net7.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+
+    <IsPackable>false</IsPackable>
+    <IsTestProject>true</IsTestProject>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
+    <PackageReference Include="NUnit" Version="3.13.3" />
+    <PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
+    <PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
+    <PackageReference Include="coverlet.collector" Version="3.2.0" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\FoodLogProject\FoodLogProject.csproj" />
+  </ItemGroup>
+
+</Project>

+ 1 - 0
FoodLogTests/GlobalUsings.cs

@@ -0,0 +1 @@
+global using NUnit.Framework;

+ 16 - 0
FoodLogTests/UnitTest1.cs

@@ -0,0 +1,16 @@
+namespace FoodLogTests
+{
+    public class Tests
+    {
+        [SetUp]
+        public void Setup()
+        {
+        }
+
+        [Test]
+        public void Test1()
+        {
+            Assert.Pass();
+        }
+    }
+}

+ 1 - 0
TestProject1/GlobalUsings.cs

@@ -0,0 +1 @@
+global using Xunit;

+ 29 - 0
TestProject1/TestProject1.csproj

@@ -0,0 +1,29 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net7.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+
+    <IsPackable>false</IsPackable>
+    <IsTestProject>true</IsTestProject>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
+    <PackageReference Include="xunit" Version="2.4.2" />
+    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+      <PrivateAssets>all</PrivateAssets>
+    </PackageReference>
+    <PackageReference Include="coverlet.collector" Version="3.2.0">
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+      <PrivateAssets>all</PrivateAssets>
+    </PackageReference>
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\FoodLogProject\FoodLogProject.csproj" />
+  </ItemGroup>
+
+</Project>

+ 11 - 0
TestProject1/UnitTest1.cs

@@ -0,0 +1,11 @@
+namespace TestProject1
+{
+    public class UnitTest1
+    {
+        [Fact]
+        public void Test1()
+        {
+            
+        }
+    }
+}

+ 1 - 0
TestProject2/GlobalUsings.cs

@@ -0,0 +1 @@
+global using Microsoft.VisualStudio.TestTools.UnitTesting;

+ 24 - 0
TestProject2/TestProject2.csproj

@@ -0,0 +1,24 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net7.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+
+    <IsPackable>false</IsPackable>
+    <IsTestProject>true</IsTestProject>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
+    <PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
+    <PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
+    <PackageReference Include="coverlet.collector" Version="3.2.0" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\FoodLogProject\FoodLogProject.csproj" />
+  </ItemGroup>
+
+</Project>

+ 99 - 0
TestProject2/UnitTest1.cs

@@ -0,0 +1,99 @@
+
+using FoodLogProject;
+namespace TestProject2
+{
+    [TestClass]
+    public class UnitTest1
+    {
+        [TestMethod]
+        public void UserNumber_AreNotEqual()
+        {
+            bool except = true;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegNumber("89524544428");
+            Assert.AreNotEqual(except,actual);
+        }
+
+        [TestMethod]
+        public void UserNumber_AreEqual()
+        {
+            bool except = false;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegNumber("+79524544428");
+            Assert.AreEqual(except, actual);
+        }
+
+        [TestMethod]
+        public void UserName_AreEqual()
+        {
+            bool except = true;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegName("Ñåìåí");
+            Assert.AreEqual(except, actual);
+        }
+
+        [TestMethod]
+        public void UserName_AreNotEqual()
+        {
+            bool except = true;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegName("ui12");
+            Assert.AreNotEqual(except, actual);
+        }
+
+        [TestMethod]
+        public void UserHeight_AreEqual()
+        {
+            bool except = true;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegHeight("80");
+            Assert.AreEqual(except, actual);
+        }
+
+        [TestMethod]
+        public void UserHeight_AreNotEqual()
+        {
+            bool except = true;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegHeight("ui12");
+            Assert.AreNotEqual(except, actual);
+        }
+
+
+        [TestMethod]
+        public void UserWeight_AreEqual()
+        {
+            bool except = true;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegWeight("80");
+            Assert.AreEqual(except, actual);
+        }
+
+        [TestMethod]
+        public void UserWeight_AreNotEqual()
+        {
+            bool except = true;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegWeight("Simon");
+            Assert.AreNotEqual(except, actual);
+        }
+
+        [TestMethod]
+        public void UserPassword_AreEqual()
+        {
+            bool except = true;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegPassword("1010");
+            Assert.AreEqual(except, actual);
+        }
+
+        [TestMethod]
+        public void UserPassword_AreNotEqual()
+        {
+            bool except = true;
+            GaruaevContext garuaevContext = new GaruaevContext();
+            bool actual = garuaevContext.CheckRegPassword(" ");
+            Assert.AreNotEqual(except, actual);
+        }
+    }
+}