Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UnitTesting.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTesting", "UnitTesting\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestingLib", "TestingLib\TestingLib.csproj", "{E2FF35D4-3B82-45E0-BAB8-DE39777C4D53}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RealizationApp", "RealizationApp\RealizationApp.csproj", "{6301EAB5-B771-4477-9242-84D8C2944114}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RealizationApp", "RealizationApp\RealizationApp.csproj", "{6301EAB5-B771-4477-9242-84D8C2944114}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 3 additions & 1 deletion UnitTesting/BasicCalcTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.VisualStudio.TestPlatform.TestHost;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -34,5 +35,6 @@ public void Add_Theory(int a, int b, int expectedResult)
int result = _calculator.Add(a, b);
Assert.Equal(expectedResult, result);
}

}
}
95 changes: 95 additions & 0 deletions UnitTesting/GSEvgenievich/MoqTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using Moq;
using TestingLib.Shop;
using TestingLib.Weather;

namespace UnitTesting.GSEvgenievich
{
public class MoqTests
{
private readonly Mock<ICustomerRepository> mockCustomerRepository;
private readonly Mock<IOrderRepository> mockOrderRepository;
private readonly Mock<INotificationService> mockNotificationService;
private readonly Mock<IWeatherForecastSource> mockWeatherForecastSource;
public MoqTests()
{
mockCustomerRepository = new Mock<ICustomerRepository>();
mockOrderRepository = new Mock<IOrderRepository>();
mockNotificationService = new Mock<INotificationService>();
mockWeatherForecastSource = new Mock<IWeatherForecastSource>();
}

[Fact]
public void GetCustomerInfo_ShouldReturnCorrectInfo()
{
// Arrange
var customer = new Customer { Id = 1, Name = "Petya", Email = "[email protected]" };

mockCustomerRepository.Setup(repo => repo.GetCustomerById(1)).Returns(customer);
mockOrderRepository.Setup(repo => repo.GetOrders()).Returns(new List<Order> { new Order() { Customer = customer }, new Order() { Customer = customer } });

var service = new ShopService(mockCustomerRepository.Object, mockOrderRepository.Object, mockNotificationService.Object);

// Act
var result = service.GetCustomerInfo(1);

// Assert
Assert.Equal("Customer " + customer.Name + " has 2 orders", result);
mockOrderRepository.Verify(repo => repo.GetOrders(), Times.Once);
mockCustomerRepository.Verify(repo => repo.GetCustomerById(It.IsAny<int>()), Times.Once);
}

[Fact]
public void CreateOrder_ShouldAddOrder()
{
// Arrange
var customer = new Customer { Id = 1, Name = "Petya", Email = "[email protected]" };
var order = new Order { Id = 2, Date = DateTime.Now, Customer = customer, Amount = 3 };
mockOrderRepository.Setup(repo => repo.GetOrderById(1)).Returns(order);

var service = new ShopService(mockCustomerRepository.Object, mockOrderRepository.Object, mockNotificationService.Object);

// Act
service.CreateOrder(order);

// Act и Assert
mockOrderRepository.Verify(repo => repo.GetOrderById(It.IsAny<int>()), Times.Once);
mockOrderRepository.Verify(repo => repo.AddOrder(It.IsAny<Order>()), Times.Once);
}

[Fact]
public void CreateOrder_ShouldSendNotification()
{
// Arrange
var customer = new Customer { Id = 1, Name = "Petya", Email = "[email protected]" };
var order = new Order { Id = 2, Date = DateTime.Now, Customer = customer, Amount = 3 };
mockOrderRepository.Setup(repo => repo.GetOrderById(1)).Returns(order);

var service = new ShopService(mockCustomerRepository.Object, mockOrderRepository.Object, mockNotificationService.Object);

// Act
service.CreateOrder(order);

// Act и Assert
mockNotificationService.Verify(repo => repo.SendNotification(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}

[Fact]
public void GetWeatherForecast_ShouldReturnCorrectInfo()
{
var weatherForecast = new WeatherForecast { Summary = "Yasno", TemperatureC = 23 };
var currentTime = DateTime.Now;
mockWeatherForecastSource.Setup(repo => repo.GetForecast(currentTime)).Returns(weatherForecast);

var service = new WeatherForecastService(mockWeatherForecastSource.Object);

//Act
var result = service.GetWeatherForecast(currentTime);

//Assert
Assert.NotNull(result);
mockWeatherForecastSource.Verify(repo => repo.GetForecast(It.IsAny<DateTime>()), Times.Once);
}
}
}


2 changes: 2 additions & 0 deletions UnitTesting/GSEvgenievich/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
����������� �. �.
������� �. �.
1 change: 1 addition & 0 deletions UnitTesting/GSEvgenievich/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ИСПП-35: Волков Н. и Пожидаев Г.
67 changes: 67 additions & 0 deletions UnitTesting/GSEvgenievich/Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestingLib.Math;

namespace UnitTesting.GSEvgenievich
{
public class Tests
{
private readonly BasicCalc _calculator;

public Tests()
{
_calculator = new BasicCalc();
}

[Fact]
public void LCM_ShouldReturnCorrectLargestMultipleNumber()
{
int result = _calculator.LCM(18, 24);
Assert.Equal(72, result);
}


[Theory]
[InlineData(10000, 100, 10000)]
[InlineData(1, 2, 2)]
[InlineData(5, 9, 45)]
public void LCM_Theory(int a, int b, int expectedResult)
{
int result = _calculator.LCM(a, b);
Assert.Equal(expectedResult, result);
}

[Fact]
public void LCM_ShouldThrowArgumentOutOfRangeException()
{
Assert.Throws<ArgumentOutOfRangeException>(() => _calculator.LCM(-10, 10));
}

[Fact]
public void IsPerfectNumber_ShouldReturnTrue()
{
bool result = _calculator.IsPerfectNumber(6);
Assert.Equal(true, result);
}


[Theory]
[InlineData(19, false)]
[InlineData(28, true)]
[InlineData(496, true)]
public void IsPerfectNumber_Theory(int a, bool expectedResult)
{
bool result = _calculator.IsPerfectNumber(a);
Assert.Equal(expectedResult, result);
}

[Fact]
public void IsPerfectNumber_ShouldThrowArgumentOutOfRangeException()
{
Assert.Throws<ArgumentOutOfRangeException>(() => _calculator.IsPerfectNumber(-10));
}
}
}
74 changes: 74 additions & 0 deletions UnitTesting/GSEvgenievich/UnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Microsoft.VisualStudio.TestPlatform.TestHost;
using TestingLib.Math;

namespace UnitTesting.GSEvgenievich
{
public class UnitTest
{
private readonly BasicCalc _calculator;

public UnitTest()
{
_calculator = new BasicCalc();
}

// Задание 1
[Fact]
public void LCM_PositiveNumbers_ReturnsCorrectLCM()
{
int a = 12;
int b = 15;
int expectedResult = 60;

int result = _calculator.LCM(a, b);

Assert.Equal(expectedResult, result);
}

[Theory]
[InlineData(2, 3)]
[InlineData(4, 6)]
[InlineData(7, 11)]
public void LCM_MultipleInputs_ReturnsCorrectLCM(int a, int b)
{
int result = _calculator.LCM(a, b);

Assert.True(result % a == 0 && result % b == 0);
}

[Fact]
public void LCM_NegativeNumbers_ThrowsException()
{
Assert.Throws<ArgumentOutOfRangeException>(() => _calculator.LCM(-13, 16));
}

// Задание 2
[Fact]
public void IsPrime_ValidInput_ReturnsCorrectResult()
{
int n = 7;

bool result = _calculator.IsPrime(n);

Assert.True(result);
}

[Theory]
[InlineData(1,true)]
[InlineData(3, true)]
[InlineData(5, true)]
[InlineData(11, true)]
public void IsPrime_MultipleInputs_ReturnsExpectedResults(int n,bool expectedResult)
{
bool result = _calculator.IsPrime(n);

Assert.Equal(expectedResult, result);
}

[Fact]
public void IsPrime_InvalidInput_ThrowsArgumentOutOfRangeException()
{
Assert.Throws<ArgumentOutOfRangeException>(() => _calculator.IsPrime(-1));
}
}
}