first commit

This commit is contained in:
1billy17 2025-06-05 11:22:50 +03:00
commit 341b5dc221
544 changed files with 21016 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

13
.idea/.idea.Magazin/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.Magazin.iml
/modules.xml
/projectSettingsUpdater.xml
/contentModel.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1 @@
Magazin

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AvaloniaProject">
<option name="projectPerEditor">
<map>
<entry key="TovarV2/AddTovar.axaml" value="TovarV2/TovarV2.csproj" />
<entry key="TovarV2/EditTovar.axaml" value="TovarV2/TovarV2.csproj" />
<entry key="TovarV2/Korzina.axaml" value="TovarV2/TovarV2.csproj" />
<entry key="TovarV2/MainWindow.axaml" value="TovarV2/TovarV2.csproj" />
<entry key="TovarV2/Productedit.axaml" value="TovarV2/TovarV2.csproj" />
</map>
</option>
</component>
</project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
</project>

22
Magazin.sln Normal file
View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TovarV2", "TovarV2\TovarV2.csproj", "{71493A8F-89A0-44CC-9092-7A9D316BC4E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTovarV2", "TestTovarV2\TestTovarV2.csproj", "{4E7C34E9-6599-4522-A05B-68030CC98B26}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{71493A8F-89A0-44CC-9092-7A9D316BC4E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71493A8F-89A0-44CC-9092-7A9D316BC4E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71493A8F-89A0-44CC-9092-7A9D316BC4E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71493A8F-89A0-44CC-9092-7A9D316BC4E3}.Release|Any CPU.Build.0 = Release|Any CPU
{4E7C34E9-6599-4522-A05B-68030CC98B26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E7C34E9-6599-4522-A05B-68030CC98B26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E7C34E9-6599-4522-A05B-68030CC98B26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E7C34E9-6599-4522-A05B-68030CC98B26}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,29 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=7f4b40ab_002D736b_002D49ae_002Db402_002Ddec0ca9d6341/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="EditTovarTests" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;TestAncestor&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestProject1.EditTovarTests&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.MainWindowTests&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.ProductEditTests&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.AddTovarTests&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.EditTovarTests&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestProject1.KorzinaTests.IsOpenWindow_ShouldReturnTrue_WhenItOpened&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.IsOpenWindow_ShouldReturnTrue_WhenItOpened&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.IsOpenWindow_ShouldReturnFalse_WhenItClosed&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.NextPageOnClick_ShouldReturnLastTwoProducts_WhenFiveProductsInList&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.PrevPageOnClick_ShouldReturnLastTwoProducts_WhenFiveProductsInList&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.DelBtnOnClick_ShouldRemoveProduct_WhenFirstProductIsSelected&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.DelBtnOnClick_ShouldRemoveProduct_WhenSecondProductIsSelected&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.DelBtnOnClick_ShouldThrowArgumentOutOfRangeException_WhenFourthProductIsSelected&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.ReturnProdEditClick_ShouldOpenProductEditWindow_WhenItPressed&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.PodschetOrderBtnClick_ShouldCalculateTotalPriceCorrectly_WhenDataIsCorrect&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.PodschetOrderBtnClick_ShouldCalculateTotalPriceCorrectly_WhenDataIsNotCorrect&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.ExitClick_ShouldOpenMainWindow_WhenItPressed&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.UvelBtnOnClick_ShouldIncreaseQuantitySelect_WithinLimits&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.UvelBtnOnClick_ShouldIncreaseQuantity_WhenItPressedOnce&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.UmenBtnOnClick_ShouldDecreaseQuantity_WhenItPressedOnce&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.CheckQuantity_ShouldCapAtMax_WhenQuantityExceedsStock&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.CheckQuantity_ShouldRaiseToMin_WhenQuantityBelowOne&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests.CheckQuantity_ShouldReturnSame_WhenWithinRange&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::4E7C34E9-6599-4522-A05B-68030CC98B26::net8.0::TestTovarV2.KorzinaTests&lt;/TestId&gt;
&lt;/TestAncestor&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

156
TestTovarV2/AddTovar.cs Normal file
View File

@ -0,0 +1,156 @@
using Avalonia;
using Avalonia.Headless;
using Avalonia.Controls;
using TovarV2;
using Avalonia.Media.Imaging;
using System.IO;
using System.Linq;
namespace TestTovarV2
{
[TestFixture]
public class AddTovarTests
{
private AddTovar _addTovar;
[OneTimeSetUp]
public void OneTimeSetup()
{
AppBuilder.Configure<App>()
.UseHeadless(new AvaloniaHeadlessPlatformOptions())
.SetupWithoutStarting();
}
[SetUp]
public void Setup()
{
ListPr.ListProd.Clear();
ListPr.b = 0;
_addTovar = new AddTovar();
_addTovar.Show();
}
[TearDown]
public void TearDown()
{
_addTovar.Close();
ListPr.ListProd.Clear();
}
[Test]
public void AddTovarOkClick_ShouldAddProduct_WhenFieldsIsValid()
{
_addTovar.GetNameTov.Text = "New Product";
_addTovar.GetPriceTov.Text = "100";
_addTovar.GetQuantityTov.Text = "10";
_addTovar.bitmapToBind = new Bitmap(Path.Combine("Assets", "test_image.png"));
_addTovar.AddTovarOk_Click(null, null);
Assert.That(ListPr.ListProd.Count, Is.EqualTo(1));
Assert.That(ListPr.ListProd[0].nameProd, Is.EqualTo("New Product"));
Assert.That(ListPr.ListProd[0].priceProd, Is.EqualTo(100));
Assert.That(ListPr.ListProd[0].quantityProd, Is.EqualTo(10));
Assert.That(ListPr.ListProd[0].bitmapProd, Is.Not.Null);
Assert.That(ProductEdit.IsOpen, Is.True);
}
[Test]
public void AddTovarOkClick_ShouldShowError_WhenProductNameExists()
{
ListPr.ListProd.Add(new Product { nameProd = "Existing Product" });
_addTovar.GetNameTov.Text = "Existing Product";
_addTovar.AddTovarOk_Click(null, null);
Assert.That(ListPr.ListProd.Count, Is.EqualTo(1));
Assert.That(_addTovar.GetErrorMsg.Text, Is.EqualTo("Товар с таким именем уже имеется в каталоге"));
}
[Test]
public void AddTovarOkClick_ShouldAddProduct_WhenImageNotSelected()
{
_addTovar.GetNameTov.Text = "Product Without Image";
_addTovar.GetPriceTov.Text = "200";
_addTovar.GetQuantityTov.Text = "20";
_addTovar.bitmapToBind = null;
_addTovar.AddTovarOk_Click(null, null);
Assert.That(ListPr.ListProd[0].nameProd, Is.EqualTo("Product Without Image"));
Assert.That(ListPr.ListProd[0].bitmapProd, Is.Null);
}
[Test]
public void AddTovarOkClick_ShouldHandleInvalidNumberFormat_WhenFieldsIsInvalid()
{
_addTovar.GetNameTov.Text = "Invalid Input Product";
_addTovar.GetPriceTov.Text = "invalid";
_addTovar.GetQuantityTov.Text = "invalid";
Assert.DoesNotThrow(() => _addTovar.AddTovarOk_Click(null, null));
}
[Test]
public void AddTovarImgClick_ShouldUpdateImage_WhenFileSelected()
{
var testBitmap = new Bitmap(Path.Combine("Assets", "test_image.png"));
_addTovar.bitmapToBind = testBitmap;
_addTovar.AddTovarImg_Click(null, null);
Assert.That(_addTovar.GetImagePath.Source, Is.EqualTo(testBitmap));
}
[Test]
public void AddTovarOkClick_ShouldIncrementIdCounter_WhenFieldsIsValid()
{
var initialCounter = ListPr.b;
_addTovar.GetNameTov.Text = "Product 1";
_addTovar.GetPriceTov.Text = "100";
_addTovar.GetQuantityTov.Text = "10";
_addTovar.AddTovarOk_Click(null, null);
_addTovar.GetNameTov.Text = "Product 2";
_addTovar.AddTovarOk_Click(null, null);
Assert.That(ListPr.ListProd[0].Id, Is.EqualTo(initialCounter));
Assert.That(ListPr.ListProd[1].Id, Is.EqualTo(initialCounter + 1));
}
[Test]
public void AddTovarOkClick_ShouldHandleEmptyFields_WhenFieldsIsEmpty()
{
_addTovar.GetNameTov.Text = "";
_addTovar.GetPriceTov.Text = "";
_addTovar.GetQuantityTov.Text = "";
Assert.DoesNotThrow(() => _addTovar.AddTovarOk_Click(null, null));
}
[Test]
public void AddTovarOkClick_ShouldCloseWindow_WhenSuccessful()
{
_addTovar.GetNameTov.Text = "Test Close";
_addTovar.GetPriceTov.Text = "100";
_addTovar.GetQuantityTov.Text = "10";
_addTovar.AddTovarOk_Click(null, null);
Assert.That(AddTovar.IsOpen, Is.False);
}
[Test]
public void AddTovarOkClick_ShouldOpenProductEdit_WhenSuccessful()
{
_addTovar.GetNameTov.Text = "Test Open Edit";
_addTovar.GetPriceTov.Text = "100";
_addTovar.GetQuantityTov.Text = "10";
_addTovar.AddTovarOk_Click(null, null);
Assert.That(ProductEdit.IsOpen, Is.True);
}
}
}

154
TestTovarV2/EditTovar.cs Normal file
View File

@ -0,0 +1,154 @@
using Avalonia;
using Avalonia.Headless;
using Avalonia.Controls;
using TovarV2;
using Avalonia.Media.Imaging;
using System.IO;
namespace TestTovarV2
{
[TestFixture]
public class EditTovarTests
{
private EditTovar _editTovar;
[OneTimeSetUp]
public void OneTimeSetup()
{
AppBuilder.Configure<App>()
.UseHeadless(new AvaloniaHeadlessPlatformOptions())
.SetupWithoutStarting();
}
[SetUp]
public void Setup()
{
ListPr.ListProd = new List<Product>
{
new Product
{
Id = 0,
nameProd = "Test Product",
priceProd = 100,
quantityProd = 10,
bitmapProd = new Bitmap(Path.Combine("Assets", "test_image.png"))
}
};
ListPr.productForEdit = 0;
_editTovar = new EditTovar();
_editTovar.Show();
}
[TearDown]
public void TearDown()
{
_editTovar.Close();
ListPr.ListProd.Clear();
}
[Test]
public void EditOkClick_ShouldUpdateProductInfo_WhenFieldsAreValid()
{
_editTovar.GetNameTov.Text = "Updated Product";
_editTovar.GetPriceTov.Text = "200";
_editTovar.GetQuantityTov.Text = "20";
var testBitmap = new Bitmap(Path.Combine("Assets", "test_image_updated.png"));
_editTovar.bitmapToBind = testBitmap;
_editTovar.EditOk_Click(null, null);
Assert.That(ListPr.ListProd[0].nameProd, Is.EqualTo("Updated Product"));
Assert.That(ListPr.ListProd[0].priceProd, Is.EqualTo(200));
Assert.That(ListPr.ListProd[0].quantityProd, Is.EqualTo(20));
Assert.That(ListPr.ListProd[0].bitmapProd, Is.EqualTo(testBitmap));
Assert.That(ProductEdit.IsOpen, Is.True);
}
[Test]
public void EditOkClick_ShouldNotCrash_WhenImageNotChanged()
{
_editTovar.GetNameTov.Text = "Updated Product";
_editTovar.GetPriceTov.Text = "200";
_editTovar.GetQuantityTov.Text = "20";
_editTovar.bitmapToBind = null;
_editTovar.EditOk_Click(null, null);
Assert.That(ListPr.ListProd[0].bitmapProd, Is.Not.Null);
}
[Test]
public void AddTovarImgClick_ShouldUpdateImage_WhenFileSelected()
{
var testBitmap = new Bitmap(Path.Combine("Assets", "test_image_updated.png"));
_editTovar.bitmapToBind = testBitmap;
_editTovar.AddTovarImg_Click(null, null);
Assert.That(_editTovar.GetImagePath.Source, Is.EqualTo(testBitmap));
}
[Test]
public void EditOk_Click_ShouldUpdateOnlyName_WhenOneFieldIsFilled()
{
var originalPrice = ListPr.ListProd[0].priceProd;
_editTovar.GetNameTov.Text = "New Name Only";
_editTovar.EditOk_Click(null, null);
Assert.That(ListPr.ListProd[0].nameProd, Is.EqualTo("New Name Only"));
Assert.That(ListPr.ListProd[0].priceProd, Is.EqualTo(originalPrice));
}
[Test]
public void EditOkClick_ShouldCorrectlyUpdateMultipleProducts_WhenAddSecondProduct()
{
ListPr.ListProd.Add(new Product
{
Id = 1,
nameProd = "Second Product",
priceProd = 200,
quantityProd = 20,
bitmapProd = new Bitmap(Path.Combine("Assets", "test_image2.png"))
});
ListPr.productForEdit = 1;
var secondEdit = new EditTovar();
secondEdit.GetNameTov.Text = "Updated Second";
secondEdit.GetPriceTov.Text = "300";
secondEdit.GetQuantityTov.Text = "30";
secondEdit.EditOk_Click(null, null);
Assert.That(ListPr.ListProd[1].nameProd, Is.EqualTo("Updated Second"));
Assert.That(ListPr.ListProd[0].nameProd, Is.EqualTo("Test Product"));
}
[Test]
public void EditOkClick_ShouldHandleNegativePrice_WhenPriceIsNegative()
{
_editTovar.GetPriceTov.Text = "-100";
_editTovar.EditOk_Click(null, null);
Assert.That(ListPr.ListProd[0].priceProd, Is.EqualTo(-100));
}
[Test]
public void EditOkClick_ShouldHandleEmptyFields_WhenFieldsIsEmpty()
{
_editTovar.GetNameTov.Text = "";
_editTovar.GetPriceTov.Text = "";
_editTovar.GetQuantityTov.Text = "";
Assert.DoesNotThrow(() => _editTovar.EditOk_Click(null, null));
Assert.That(ListPr.ListProd[0].nameProd, Is.Not.EqualTo(""));
Assert.That(ListPr.ListProd[0].priceProd, Is.Not.EqualTo(0));
Assert.That(ListPr.ListProd[0].quantityProd, Is.Not.EqualTo(0));
}
}
}

209
TestTovarV2/Korzina.cs Normal file
View File

@ -0,0 +1,209 @@
using Avalonia;
using Avalonia.Headless;
using Avalonia.Controls;
using TovarV2;
namespace TestTovarV2
{
[TestFixture]
public class KorzinaTests
{
private Korzina _korzina;
[OneTimeSetUp]
public void OneTimeSetup()
{
AppBuilder.Configure<App>()
.UseHeadless(new AvaloniaHeadlessPlatformOptions())
.SetupWithoutStarting();
}
[SetUp]
public void Setup()
{
ListPr.productSelects.Clear();
ListPr.productSelects.AddRange(new List<ProductSelect>
{
new ProductSelect { Id = 0, nameProdKorz = "Test 1", priceProdKorz = 100, quantityProdKorz = 1, quantitySelect = 1 },
new ProductSelect { Id = 1, nameProdKorz = "Test 2", priceProdKorz = 200, quantityProdKorz = 2, quantitySelect = 1 },
new ProductSelect { Id = 2, nameProdKorz = "Test 3", priceProdKorz = 300, quantityProdKorz = 3, quantitySelect = 1 }
});
_korzina = new Korzina();
_korzina.Show();
}
[TearDown]
public void TearDown()
{
_korzina.Close();
ListPr.productSelects.Clear();
}
[Test]
public void DelBtnOnClick_ShouldRemoveProduct_WhenFirstProductIsSelected()
{
int initialCount = ListPr.productSelects.Count;
var delButton = new Button { Tag = 0 };
_korzina.DelBtn_Click(delButton, null);
Assert.That(initialCount - 1 == ListPr.productSelects.Count);
}
[Test]
public void DelBtnOnClick_ShouldRemoveProduct_WhenSecondProductIsSelected()
{
int initialCount = ListPr.productSelects.Count;
var delButton = new Button { Tag = 1 };
_korzina.DelBtn_Click(delButton, null);
Assert.That(initialCount - 1 == ListPr.productSelects.Count);
}
[Test]
public void CheckQuantity_ShouldCapAtMax_WhenQuantityExceedsStock()
{
var result = _korzina.CheckQuantity(10, 5);
Assert.That(5 == result);
}
[Test]
public void CheckQuantity_ShouldRaiseToMin_WhenQuantityBelowOne()
{
var result = _korzina.CheckQuantity(0, 5);
Assert.That(1 == result);
}
[Test]
public void CheckQuantity_ShouldReturnSame_WhenWithinRange()
{
var result = _korzina.CheckQuantity(3, 5);
Assert.That(3 == result);
}
[Test]
public void NextPageOnClick_ShouldReturnLastTwoProducts_WhenThreeProductsInList()
{
_korzina.PagesConfig();
_korzina.NextPage_OnClick(null, null);
Assert.That("Test 3" == _korzina.currentProdSel[0].nameProdKorz);
}
[Test]
public void PrevPageOnClick_ShouldReturnLastTwoProducts_WhenThreeProductsInList()
{
_korzina.PagesConfig();
_korzina.NextPage_OnClick(null, null);
_korzina.PrevPage_OnClick(null, null);
Assert.That("Test 1" == _korzina.currentProdSel[0].nameProdKorz);
}
[Test]
public void ReturnProdEditClick_ShouldOpenProductEditWindow_WhenItPressed()
{
_korzina.ReturnProdEdit_Click(null, null);
Assert.That(ProductEdit.IsOpen);
}
[Test]
public void PodschetOrderBtnClick_ShouldCalculateTotalPriceCorrectly_WhenDataIsCorrect()
{
var korzina = new Korzina();
korzina.GetPodschetstoimosti = new TextBlock();
ListPr.productSelects = new List<ProductSelect>()
{
new ProductSelect { priceProdKorz = 100, quantitySelect = 2 },
new ProductSelect { priceProdKorz = 150, quantitySelect = 1 }
};
korzina.PodschetOrderBtn_Click(null, null);
Assert.That("Общая стоимость составляет: 350 руб." == korzina.GetPodschetstoimosti.Text);
}
[Test]
public void PodschetOrderBtnClick_ShouldCalculateTotalPriceCorrectly_WhenDataIsNotCorrect()
{
var korzina = new Korzina();
korzina.GetPodschetstoimosti = new TextBlock();
ListPr.productSelects = new List<ProductSelect>()
{
new ProductSelect { priceProdKorz = 100, quantitySelect = 0 },
new ProductSelect { priceProdKorz = -150, quantitySelect = 1 }
};
korzina.PodschetOrderBtn_Click(null, null);
Assert.That("Общая стоимость составляет: -150 руб." == korzina.GetPodschetstoimosti.Text);
}
[Test]
public void ExitClick_ShouldOpenMainWindow_WhenItPressed()
{
_korzina.Exit_Click(null, null);
Assert.That(MainWindow.IsOpen);
}
[Test]
public void UvelBtnOnClick_ShouldIncreaseQuantity_WhenItPressedOnce()
{
var testProduct = ListPr.productSelects[0];
testProduct.quantitySelect = 2;
testProduct.quantityProdKorz = 10;
var button = new Button { Tag = testProduct.Id };
_korzina.UvelBtn_OnClick(button, null);
Assert.That(testProduct.quantitySelect, Is.EqualTo(3));
}
[Test]
public void UvelBtnOnClick_ShouldNotIncreaseAboveMaxQuantity_WhenItPressedOnce()
{
var testProduct = ListPr.productSelects[0];
testProduct.quantitySelect = 10;
testProduct.quantityProdKorz = 10;
var button = new Button { Tag = testProduct.Id };
_korzina.UvelBtn_OnClick(button, null);
Assert.That(testProduct.quantitySelect, Is.EqualTo(10));
Assert.That(_korzina.GetPodschetstoimosti.Text, Does.Contain("Ошибка"));
}
[Test]
public void UmenBtnOnClick_ShouldDecreaseQuantity_WhenItPressedOnce()
{
var testProduct = ListPr.productSelects[0];
testProduct.quantitySelect = 2;
var button = new Button { Tag = testProduct.Id };
_korzina.UmenBtn_OnClick(button, null);
Assert.That(testProduct.quantitySelect, Is.EqualTo(1));
}
[Test]
public void UmenBtnOnClick_ShouldNotDecreaseBelowOne_WhenItPressedOnce()
{
var testProduct = ListPr.productSelects[0];
testProduct.quantitySelect = 1;
var button = new Button { Tag = testProduct.Id };
_korzina.UmenBtn_OnClick(button, null);
Assert.That(testProduct.quantitySelect, Is.EqualTo(1));
}
}
}

90
TestTovarV2/MainWindow.cs Normal file
View File

@ -0,0 +1,90 @@
using TovarV2;
using Avalonia;
using Avalonia.Headless;
namespace TestTovarV2
{
[TestFixture]
public class MainWindowTests
{
private MainWindow _mainWindow;
[OneTimeSetUp]
public void OneTimeSetup()
{
AppBuilder.Configure<App>()
.UseHeadless(new AvaloniaHeadlessPlatformOptions())
.SetupWithoutStarting();
}
[SetUp]
public void Setup()
{
_mainWindow = new MainWindow();
ProductEdit.ResetState();
}
[Test]
public void BtnVhod_ShouldOpenProductEditWindow_WhenCodeInputTextIsZero()
{
_mainWindow.CodeInputBox.Text = "0";
_mainWindow.BtnVhod_OnClick(null, null);
Assert.That(0 == ListPr.codeUser);
Assert.IsTrue(ProductEdit.IsOpen);
}
[Test]
public void BtnVhod_ShouldOpenProductEditWindow_WhenCodeInputTextIsOne()
{
_mainWindow.CodeInputBox.Text = "1";
_mainWindow.BtnVhod_OnClick(null, null);
Assert.That(1 == ListPr.codeUser);
Assert.IsTrue(ProductEdit.IsOpen);
}
[Test]
public void BtnVhod_ShouldNotChangeCode_WhenCodeInputIsInvalidWithDigits()
{
_mainWindow.CodeInputBox.Text = "331";
ListPr.codeUser = -1;
_mainWindow.BtnVhod_OnClick(null, null);
Assert.That(0 != ListPr.codeUser);
Assert.That(1 != ListPr.codeUser);
Assert.IsFalse(MainWindow.IsOpen);
}
[Test]
public void BtnVhod_ShouldNotChangeCode_WhenCodeInputIsInvalidWithLetters()
{
_mainWindow.CodeInputBox.Text = "vefve";
ListPr.codeUser = -1;
_mainWindow.BtnVhod_OnClick(null, null);
Assert.That(0 != ListPr.codeUser);
Assert.That(1 != ListPr.codeUser);
Assert.IsFalse(MainWindow.IsOpen);
}
[Test]
public void BtnVhod_ShouldNotChangeCode_WhenCodeInputIsBlank()
{
_mainWindow.CodeInputBox.Text = "";
ListPr.codeUser = -1;
_mainWindow.BtnVhod_OnClick(null, null);
Assert.That(0 != ListPr.codeUser);
Assert.That(1 != ListPr.codeUser);
Assert.IsFalse(MainWindow.IsOpen);
}
}
}

162
TestTovarV2/Productedit.cs Normal file
View File

@ -0,0 +1,162 @@
using Avalonia.Controls;
using TovarV2;
using Avalonia;
using Avalonia.Headless;
using Avalonia.Input;
using Avalonia.Media.Imaging;
namespace TestTovarV2
{
[TestFixture]
public class ProductEditTests
{
private ProductEdit _productEditWindow;
public Bitmap _testBitmap;
[OneTimeSetUp]
public void OneTimeSetup()
{
AppBuilder.Configure<App>()
.UseHeadless(new AvaloniaHeadlessPlatformOptions())
.SetupWithoutStarting();
}
[SetUp]
public void Setup()
{
ListPr.ListProd.Clear();
ListPr.productSelects.Clear();
for (int i = 0; i < 4; i++)
{
ListPr.ListProd.Add(new Product
{
Id = i,
nameProd = $"Test {i}",
priceProd = 1 + i,
quantityProd = 4,
bitmapProd = _testBitmap
});
}
ListPr.codeUser = 0;
_productEditWindow = new ProductEdit();
}
[Test]
public void AddToKorzBtnOnClick_ShouldNotAddDuplicate_WhenProductInCart()
{
ListPr.productSelects.Add(new ProductSelect
{
nameProdKorz = "Test 0"
});
var btn = new Button { Tag = 0 };
_productEditWindow.AddToKorzBtn_OnClick(btn, null);
Assert.That(1 == ListPr.productSelects.Count);
}
[Test]
public void AddToKorzBtnOnClick_ShouldAddProduct_WhenProductNotInCart()
{
var btn = new Button { Tag = 0 };
_productEditWindow.AddToKorzBtn_OnClick(btn, null);
Assert.That(1 == ListPr.productSelects.Count);
Assert.That("Test 0" == ListPr.productSelects[0].nameProdKorz);
}
[Test]
public void BtnKorzinaOnClick_ShouldOpenKorzinaWindow_WhenKorzinaEmpty()
{
_productEditWindow.BtnKorzina_OnClick(null, null);
Assert.That(Korzina.IsOpen);
}
[Test]
public void NextPageOnClick_ShouldReturnLastProducts_WhenProductsInList()
{
_productEditWindow.PagesConfig(ListPr.ListProd);
_productEditWindow.NextPage_OnClick(null, null);
Assert.That("Test 2" == _productEditWindow.currentProd[0].nameProd);
Assert.That("Test 3" == _productEditWindow.currentProd[1].nameProd);
}
[Test]
public void PrevPageOnClick_ShouldReturnLastProducts_WhenProductsInList()
{
_productEditWindow.PagesConfig(ListPr.ListProd);
_productEditWindow.NextPage_OnClick(null, null);
_productEditWindow.PrevPage_OnClick(null, null);
Assert.That("Test 0" == _productEditWindow.currentProd[0].nameProd);
Assert.That("Test 1" == _productEditWindow.currentProd[1].nameProd);
}
[Test]
public void BtnEditTovarOnClick_ShouldOpenEditTovarWindow_WhenProductIsSelected()
{
var selectedProduct = ListPr.ListProd[0];
_productEditWindow.ProdListPublic.SelectedItem = selectedProduct;
ListPr.productSelects.Clear();
_productEditWindow.BtnEditTovar_OnClick(null, null);
Assert.That(EditTovar.IsOpen);
}
[Test]
public void BtnEditTovarOnClick_ShouldThrowArgumentOutOfRangeException_WhenProductIsNotSelected()
{
_productEditWindow.ProdListPublic.SelectedItem = null;
ListPr.productSelects.Clear();
var ex = Assert.Throws<ArgumentOutOfRangeException>(() =>
{
_productEditWindow.BtnEditTovar_OnClick(null, null);
});
Assert.That(ex.Message, Does.Contain("Index was out of range"));
}
[Test]
public void DelBtnOnClick_ShouldDeleteProduct_WhenFirstProductIsSelected()
{
int initialCount = ListPr.ListProd.Count;
var delButton = new Button { Tag = 0 };
_productEditWindow.DelBtn_Click(delButton, null);
Assert.That(initialCount - 1 == ListPr.ListProd.Count);
}
[Test]
public void DelBtnOnClick_ShouldDeleteProduct_WhenSecondProductIsSelected()
{
int initialCount = ListPr.ListProd.Count;
var delButton = new Button { Tag = 1 };
_productEditWindow.DelBtn_Click(delButton, null);
Assert.That(initialCount - 1 == ListPr.ListProd.Count);
}
[Test]
public void BtnInsertOnClick_ShouldOpenAddTovarWindow_WhenButtonIsPressed()
{
_productEditWindow.BtnInsert_OnClick(null, null);
Assert.That(AddTovar.IsOpen);
}
[Test]
public void BtnVyhodOnClick_ShouldOpenMainWindow_WhenButtonIsPressed()
{
_productEditWindow.BtnVyhod_OnClick(null, null);
Assert.That(MainWindow.IsOpen);
}
}
}

View File

@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Headless" Version="11.2.5" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TovarV2\TovarV2.csproj" />
</ItemGroup>
</Project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net8.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "8.0.0"
},
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,13 @@
{
"runtimeOptions": {
"tfm": "net8.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "8.0.0"
},
"configProperties": {
"System.Runtime.InteropServices.BuiltInComInterop.IsSupported": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

Some files were not shown because too many files have changed in this diff Show More