|
@@ -1,6 +1,7 @@
|
|
using EducationDepartament.Views;
|
|
using EducationDepartament.Views;
|
|
using EducationDepartment.Models;
|
|
using EducationDepartment.Models;
|
|
using EducationDepartment.ViewModels;
|
|
using EducationDepartment.ViewModels;
|
|
|
|
+using Microsoft.EntityFrameworkCore;
|
|
using Moq;
|
|
using Moq;
|
|
using UnitTestHelpers;
|
|
using UnitTestHelpers;
|
|
|
|
|
|
@@ -9,16 +10,14 @@ namespace EducationDepartment.test
|
|
[TestClass]
|
|
[TestClass]
|
|
public class UnitTest
|
|
public class UnitTest
|
|
{
|
|
{
|
|
-
|
|
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void TestOnPropertyChanged_UpdatesValues()
|
|
public void TestOnPropertyChanged_UpdatesValues()
|
|
{
|
|
{
|
|
// Arrange
|
|
// Arrange
|
|
- var dbContextMock = new Mock<Schekaleva31pContext>();
|
|
|
|
- var viewModel = new AttendanceViewModel(dbContextMock.Object);
|
|
|
|
- bool eventRaised = false;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ var dbContextMock = new Mock<Schekaleva31pContext>(); // Creating a mock of the database context
|
|
|
|
+ var viewModel = new AttendanceViewModel(dbContextMock.Object); // Creating an instance of the AttendanceViewModel
|
|
|
|
+ bool eventRaised = false; // Flag to track if the PropertyChanged event was raised
|
|
|
|
+ // Subscribing to the PropertyChanged event to check for changes in the 'Values' property
|
|
viewModel.PropertyChanged += (sender, e) =>
|
|
viewModel.PropertyChanged += (sender, e) =>
|
|
{
|
|
{
|
|
if (e.PropertyName == nameof(viewModel.Values))
|
|
if (e.PropertyName == nameof(viewModel.Values))
|
|
@@ -26,21 +25,18 @@ namespace EducationDepartment.test
|
|
eventRaised = true;
|
|
eventRaised = true;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
-
|
|
|
|
// Act
|
|
// Act
|
|
- viewModel.SecondSelectedOption = "SomeGroup";
|
|
|
|
-
|
|
|
|
|
|
+ viewModel.SecondSelectedOption = "SomeGroup"; // Triggering a property change
|
|
// Assert
|
|
// Assert
|
|
- Assert.IsTrue(eventRaised);
|
|
|
|
|
|
+ Assert.IsTrue(eventRaised); // Verifying that the PropertyChanged event was raised for the 'Values' property
|
|
}
|
|
}
|
|
-
|
|
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void TestAuthorizationViewModel_LoginPropertyChange()
|
|
public void TestAuthorizationViewModel_LoginPropertyChange()
|
|
{
|
|
{
|
|
// Arrange
|
|
// Arrange
|
|
- var viewModel = new AuthorizationViewModel();
|
|
|
|
- bool eventRaised = false;
|
|
|
|
-
|
|
|
|
|
|
+ var viewModel = new AuthorizationViewModel(); // Creating an instance of the AuthorizationViewModel
|
|
|
|
+ bool eventRaised = false; // Flag to track if the PropertyChanged event was raised
|
|
|
|
+ // Subscribing to the PropertyChanged event to check for changes in the 'Login' property
|
|
viewModel.PropertyChanged += (sender, e) =>
|
|
viewModel.PropertyChanged += (sender, e) =>
|
|
{
|
|
{
|
|
if (e.PropertyName == nameof(viewModel.Login))
|
|
if (e.PropertyName == nameof(viewModel.Login))
|
|
@@ -48,132 +44,128 @@ namespace EducationDepartment.test
|
|
eventRaised = true;
|
|
eventRaised = true;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
-
|
|
|
|
// Act
|
|
// Act
|
|
- viewModel.Login = "newlogin@example.com";
|
|
|
|
-
|
|
|
|
|
|
+ viewModel.Login = "newlogin@example.com"; // Triggering a property change
|
|
// Assert
|
|
// Assert
|
|
- Assert.IsTrue(eventRaised);
|
|
|
|
|
|
+ Assert.IsTrue(eventRaised); // Verifying that the PropertyChanged event was raised for the 'Login' property
|
|
}
|
|
}
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void AttendanceViewModel_GetNewAttendance_SetsCorrectParameterForDisciplineFilter()
|
|
public void AttendanceViewModel_GetNewAttendance_SetsCorrectParameterForDisciplineFilter()
|
|
{
|
|
{
|
|
// Arrange
|
|
// Arrange
|
|
- var dbConnect = new Schekaleva31pContext(); // Ñîçäàíèå ôåéêîâîãî êîíòåêñòà áàçû äàííûõ
|
|
|
|
- var attendanceViewModel = new AttendanceViewModel(dbConnect);
|
|
|
|
- attendanceViewModel.SelectedOption = "Äèñöèïëèíà";
|
|
|
|
- attendanceViewModel.OptionValue = "Âñå ãðóïïû";
|
|
|
|
-
|
|
|
|
|
|
+ var dbConnect = new Schekaleva31pContext(); // Creating a mock of the database context
|
|
|
|
+ var attendanceViewModel = new AttendanceViewModel(dbConnect); // Creating an instance of the AttendanceViewModel
|
|
|
|
+ attendanceViewModel.SelectedOption = "Äèñöèïëèíà"; // Setting the SelectedOption
|
|
|
|
+ attendanceViewModel.OptionValue = "Âñå ãðóïïû"; // Setting the OptionValue
|
|
// Act
|
|
// Act
|
|
- attendanceViewModel.GetNewAttendance();
|
|
|
|
-
|
|
|
|
|
|
+ attendanceViewModel.GetNewAttendance(); // Invoking the GetNewAttendance method
|
|
// Assert
|
|
// Assert
|
|
- Assert.AreEqual("Ãðóïïû íà äèñöèïëèíå ", attendanceViewModel.ParameterName); // Ïðîâåðÿåì, ÷òî ïàðàìåòð óñòàíîâëåí êàê "Ãðóïïà" äëÿ âûáðàííîé äèñöèïëèíû è âñåõ ãðóïï
|
|
|
|
|
|
+ Assert.AreEqual("Ãðóïïû íà äèñöèïëèíå ", attendanceViewModel.ParameterName); // Verifying that the ParameterName is set correctly
|
|
}
|
|
}
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void AttendanceViewModel_NewOption_ReturnsCorrectOptionsForGroupFilter()
|
|
public void AttendanceViewModel_NewOption_ReturnsCorrectOptionsForGroupFilter()
|
|
{
|
|
{
|
|
// Arrange
|
|
// Arrange
|
|
- var dbConnect = new Schekaleva31pContext(); // Ñîçäàíèå ôåéêîâîãî êîíòåêñòà áàçû äàííûõ
|
|
|
|
- var attendanceViewModel = new AttendanceViewModel(dbConnect);
|
|
|
|
- attendanceViewModel.SelectedOption = "Ãðóïïà";
|
|
|
|
-
|
|
|
|
|
|
+ var dbConnect = new Schekaleva31pContext(); // Creating a mock of the database context
|
|
|
|
+ var attendanceViewModel = new AttendanceViewModel(dbConnect); // Creating an instance of the AttendanceViewModel
|
|
|
|
+ attendanceViewModel.SelectedOption = "Ãðóïïà";// Setting the SelectedOption
|
|
// Act
|
|
// Act
|
|
- var options = attendanceViewModel.NewOption();
|
|
|
|
-
|
|
|
|
|
|
+ var options = attendanceViewModel.NewOption(); // Invoking the NewOption method
|
|
// Assert
|
|
// Assert
|
|
- Assert.IsNotNull(options);
|
|
|
|
- Assert.IsTrue(options.Count > 0); // Ïðîâåðÿåì, ÷òî ñïèñîê îïöèé íå ïóñòîé
|
|
|
|
|
|
+ Assert.IsNotNull(options); // Verifying that the options are not null
|
|
|
|
+ Assert.IsTrue(options.Count > 0); // Verifying that the options list has at least one item
|
|
}
|
|
}
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void TimetableViewModel_NewValues_ForGroup_ReturnsExpectedValues()
|
|
public void TimetableViewModel_NewValues_ForGroup_ReturnsExpectedValues()
|
|
{
|
|
{
|
|
// Arrange
|
|
// Arrange
|
|
- var dbContext = new Schekaleva31pContext(); // Ñîçäàíèå ôåéêîâîãî êîíòåêñòà áàçû äàííûõ
|
|
|
|
- var timetableViewModel = new TimetableViewModel(dbContext);
|
|
|
|
- timetableViewModel.SelectedOption = "Ãðóïïà";
|
|
|
|
- var expectedValuesCount = 40; // Çàìåíèòå íà îæèäàåìîå êîëè÷åñòâî çíà÷åíèé äëÿ âûáîðà ãðóïïû
|
|
|
|
-
|
|
|
|
|
|
+ var dbContext = new Schekaleva31pContext(); // Creating a mock of the database context
|
|
|
|
+ var timetableViewModel = new TimetableViewModel(dbContext); // Creating an instance of the TimetableViewModel
|
|
|
|
+ timetableViewModel.SelectedOption = "Ãðóïïà"; // Setting the SelectedOption
|
|
|
|
+ var expectedValuesCount = 40; // Defining the expected number of values
|
|
// Act
|
|
// Act
|
|
- var values = timetableViewModel.NewValues("Ãðóïïà");
|
|
|
|
-
|
|
|
|
|
|
+ var values = timetableViewModel.NewValues("Ãðóïïà"); // Invoking the NewValues method with a specific group
|
|
// Assert
|
|
// Assert
|
|
- Assert.AreEqual(expectedValuesCount, values.Count);
|
|
|
|
|
|
+ Assert.AreEqual(expectedValuesCount, values.Count); // Verifying that the count of values matches the expected count
|
|
}
|
|
}
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void TimetableViewModel_NewTimetable_ForTeacher_ReturnsExpectedTimetable()
|
|
public void TimetableViewModel_NewTimetable_ForTeacher_ReturnsExpectedTimetable()
|
|
{
|
|
{
|
|
- // Arrange
|
|
|
|
- var dbContext = new Schekaleva31pContext(); // Ñîçäàíèå ôåéêîâîãî êîíòåêñòà áàçû äàííûõ
|
|
|
|
|
|
+ // Arrange: Create a mock object for Schekaleva31pContext
|
|
|
|
+ var dbContext = new Schekaleva31pContext();
|
|
|
|
+ // Create an instance of TimetableViewModel with the mock context
|
|
var timetableViewModel = new TimetableViewModel(dbContext);
|
|
var timetableViewModel = new TimetableViewModel(dbContext);
|
|
|
|
+ // Set the SelectedOption to "Teacher" (Ïðåïîäàâàòåëü in Russian)
|
|
timetableViewModel.SelectedOption = "Ïðåïîäàâàòåëü";
|
|
timetableViewModel.SelectedOption = "Ïðåïîäàâàòåëü";
|
|
- var expectedTimetableCount = 0; // Çàìåíèòå íà îæèäàåìîå êîëè÷åñòâî çàíÿòèé äëÿ âûáðàííîãî ïðåïîäàâàòåëÿ
|
|
|
|
- timetableViewModel.OptionValue = "John Doe"; // Çàìåíèòå íà èìÿ ïðåïîäàâàòåëÿ â âàøåé òåñòîâîé áàçå äàííûõ
|
|
|
|
-
|
|
|
|
- // Act
|
|
|
|
|
|
+ // Define the expected count of timetable entries
|
|
|
|
+ var expectedTimetableCount = 0;
|
|
|
|
+ // Set the OptionValue to a specific teacher's name
|
|
|
|
+ timetableViewModel.OptionValue = "John Doe";
|
|
|
|
+ // Act: Call the NewTimetable method to populate the Timetable property
|
|
timetableViewModel.NewTimetable();
|
|
timetableViewModel.NewTimetable();
|
|
-
|
|
|
|
- // Assert
|
|
|
|
|
|
+ // Assert: Verify that the count of timetable entries matches the expected count
|
|
Assert.AreEqual(expectedTimetableCount, timetableViewModel.Timetable?.Count);
|
|
Assert.AreEqual(expectedTimetableCount, timetableViewModel.Timetable?.Count);
|
|
}
|
|
}
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void DisciplineViewModel_NewValues_ForGroup_ReturnsExpectedValues()
|
|
public void DisciplineViewModel_NewValues_ForGroup_ReturnsExpectedValues()
|
|
{
|
|
{
|
|
- // Arrange
|
|
|
|
- var dbContext = new Schekaleva31pContext(); // Ñîçäàíèå ôåéêîâîãî êîíòåêñòà áàçû äàííûõ
|
|
|
|
|
|
+ // Arrange: Create a mock object for Schekaleva31pContext
|
|
|
|
+ var dbContext = new Schekaleva31pContext();
|
|
|
|
+ // Create an instance of DisciplineViewModel with the mock context
|
|
var disciplineViewModel = new DisciplineViewModel(dbContext);
|
|
var disciplineViewModel = new DisciplineViewModel(dbContext);
|
|
|
|
+ // Set the SelectedOption to "Group" (Ãðóïïà in Russian)
|
|
disciplineViewModel.SelectedOption = "Ãðóïïà";
|
|
disciplineViewModel.SelectedOption = "Ãðóïïà";
|
|
- var expectedValuesCount = 40; // Çàìåíèòå íà îæèäàåìîå êîëè÷åñòâî çíà÷åíèé äëÿ âûáîðà ãðóïïû
|
|
|
|
-
|
|
|
|
- // Act
|
|
|
|
|
|
+ // Define the expected count of values
|
|
|
|
+ var expectedValuesCount = 40;
|
|
|
|
+ // Act: Call the NewValues method with the "Group" parameter and set the Values property
|
|
disciplineViewModel.Values = disciplineViewModel.NewValues("Ãðóïïà");
|
|
disciplineViewModel.Values = disciplineViewModel.NewValues("Ãðóïïà");
|
|
-
|
|
|
|
- // Assert
|
|
|
|
|
|
+ // Assert: Verify that the count of values matches the expected count
|
|
Assert.AreEqual(expectedValuesCount, disciplineViewModel.Values.Count);
|
|
Assert.AreEqual(expectedValuesCount, disciplineViewModel.Values.Count);
|
|
}
|
|
}
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void DisciplineViewModel_NewDisciplines_ForTeacher_ReturnsExpectedDisciplines()
|
|
public void DisciplineViewModel_NewDisciplines_ForTeacher_ReturnsExpectedDisciplines()
|
|
{
|
|
{
|
|
- // Arrange
|
|
|
|
- var dbContext = new Schekaleva31pContext(); // Ñîçäàíèå ôåéêîâîãî êîíòåêñòà áàçû äàííûõ
|
|
|
|
|
|
+ // Arrange: Create a mock object for Schekaleva31pContext
|
|
|
|
+ var dbContext = new Schekaleva31pContext();
|
|
|
|
+ // Create an instance of DisciplineViewModel with the mock context
|
|
var disciplineViewModel = new DisciplineViewModel(dbContext);
|
|
var disciplineViewModel = new DisciplineViewModel(dbContext);
|
|
|
|
+ // Set the SelectedOption to "Teacher" (Ïðåïîäàâàòåëü in Russian)
|
|
disciplineViewModel.SelectedOption = "Ïðåïîäàâàòåëü";
|
|
disciplineViewModel.SelectedOption = "Ïðåïîäàâàòåëü";
|
|
- var expectedDisciplinesCount = 0; // Çàìåíèòå íà îæèäàåìîå êîëè÷åñòâî äèñöèïëèí äëÿ âûáðàííîãî ïðåïîäàâàòåëÿ
|
|
|
|
- disciplineViewModel.OptionValue = "John Doe"; // Çàìåíèòå íà èìÿ ïðåïîäàâàòåëÿ â âàøåé òåñòîâîé áàçå äàííûõ
|
|
|
|
-
|
|
|
|
- // Act
|
|
|
|
|
|
+ // Define the expected count of disciplines
|
|
|
|
+ var expectedDisciplinesCount = 0;
|
|
|
|
+ // Set the OptionValue to a specific teacher's name
|
|
|
|
+ disciplineViewModel.OptionValue = "John Doe";
|
|
|
|
+ // Act: Call the NewDisciplines method to populate the Disciplines property
|
|
disciplineViewModel.NewDisciplines();
|
|
disciplineViewModel.NewDisciplines();
|
|
-
|
|
|
|
- // Assert
|
|
|
|
|
|
+ // Assert: Verify that the count of disciplines matches the expected count
|
|
Assert.AreEqual(expectedDisciplinesCount, disciplineViewModel.Disciplines?.Count);
|
|
Assert.AreEqual(expectedDisciplinesCount, disciplineViewModel.Disciplines?.Count);
|
|
}
|
|
}
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void UserProfileViewModel_GetDisciplines_ReturnsExpectedDisciplines()
|
|
public void UserProfileViewModel_GetDisciplines_ReturnsExpectedDisciplines()
|
|
{
|
|
{
|
|
- // Arrange
|
|
|
|
- var dbContext = new Schekaleva31pContext(); // Ñîçäàíèå ôåéêîâîãî êîíòåêñòà áàçû äàííûõ
|
|
|
|
- var userEmail = "alex.ivanov@example.com"; // Çàìåíèòå íà ñóùåñòâóþùèé àäðåñ ýëåêòðîííîé ïî÷òû â âàøåé òåñòîâîé áàçå äàííûõ
|
|
|
|
- var expectedDisciplinesCount = 4; // Çàìåíèòå íà îæèäàåìîå êîëè÷åñòâî äèñöèïëèí äëÿ äàííîãî ïîëüçîâàòåëÿ
|
|
|
|
-
|
|
|
|
- // Act
|
|
|
|
|
|
+ // Arrange: Create a mock object for Schekaleva31pContext
|
|
|
|
+ var dbContext = new Schekaleva31pContext();
|
|
|
|
+ // Define the email of the user
|
|
|
|
+ var userEmail = "alex.ivanov@example.com";
|
|
|
|
+ // Define the expected count of disciplines
|
|
|
|
+ var expectedDisciplinesCount = 4;
|
|
|
|
+ // Act: Create an instance of UserProfileViewModel with the mock context and user email
|
|
var userProfileViewModel = new UserProfileViewModel(dbContext, userEmail);
|
|
var userProfileViewModel = new UserProfileViewModel(dbContext, userEmail);
|
|
|
|
+ // Get the list of disciplines
|
|
var disciplines = userProfileViewModel.Disciplines;
|
|
var disciplines = userProfileViewModel.Disciplines;
|
|
-
|
|
|
|
- // Assert
|
|
|
|
|
|
+ // Assert: Verify that the count of disciplines matches the expected count
|
|
Assert.AreEqual(expectedDisciplinesCount, disciplines.Count);
|
|
Assert.AreEqual(expectedDisciplinesCount, disciplines.Count);
|
|
}
|
|
}
|
|
-
|
|
|
|
[TestMethod]
|
|
[TestMethod]
|
|
public void UserProfileViewModel_Initialization_UserIsNotNull()
|
|
public void UserProfileViewModel_Initialization_UserIsNotNull()
|
|
{
|
|
{
|
|
- // Arrange
|
|
|
|
- var dbContext = new Schekaleva31pContext(); // Ñîçäàíèå ôåéêîâîãî êîíòåêñòà áàçû äàííûõ
|
|
|
|
- var userEmail = "alex.ivanov@example.com"; // Çàìåíèòå íà ñóùåñòâóþùèé àäðåñ ýëåêòðîííîé ïî÷òû â âàøåé òåñòîâîé áàçå äàííûõ
|
|
|
|
-
|
|
|
|
- // Act
|
|
|
|
|
|
+ // Arrange: Create a mock object for Schekaleva31pContext
|
|
|
|
+ var dbContext = new Schekaleva31pContext();
|
|
|
|
+ // Define the email of the user
|
|
|
|
+ var userEmail = "alex.ivanov@example.com";
|
|
|
|
+ // Act: Create an instance of UserProfileViewModel with the mock context and user email
|
|
var userProfileViewModel = new UserProfileViewModel(dbContext, userEmail);
|
|
var userProfileViewModel = new UserProfileViewModel(dbContext, userEmail);
|
|
-
|
|
|
|
- // Assert
|
|
|
|
|
|
+ // Assert: Verify that the User property is not null
|
|
Assert.IsNotNull(userProfileViewModel.User);
|
|
Assert.IsNotNull(userProfileViewModel.User);
|
|
}
|
|
}
|
|
}
|
|
}
|