123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- using EducationDepartament.Views;
- using EducationDepartment.Models;
- using EducationDepartment.ViewModels;
- using Microsoft.EntityFrameworkCore;
- using Moq;
- using UnitTestHelpers;
- namespace EducationDepartment.test
- {
- [TestClass]
- public class UnitTest
- {
- [TestMethod]
- public void TestOnPropertyChanged_UpdatesValues()
- {
- // Arrange
- 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) =>
- {
- if (e.PropertyName == nameof(viewModel.Values))
- {
- eventRaised = true;
- }
- };
- // Act
- viewModel.SecondSelectedOption = "SomeGroup"; // Triggering a property change
- // Assert
- Assert.IsTrue(eventRaised); // Verifying that the PropertyChanged event was raised for the 'Values' property
- }
- [TestMethod]
- public void TestAuthorizationViewModel_LoginPropertyChange()
- {
- // Arrange
- 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) =>
- {
- if (e.PropertyName == nameof(viewModel.Login))
- {
- eventRaised = true;
- }
- };
- // Act
- viewModel.Login = "newlogin@example.com"; // Triggering a property change
- // Assert
- Assert.IsTrue(eventRaised); // Verifying that the PropertyChanged event was raised for the 'Login' property
- }
- [TestMethod]
- public void AttendanceViewModel_GetNewAttendance_SetsCorrectParameterForDisciplineFilter()
- {
- // Arrange
- 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
- attendanceViewModel.GetNewAttendance(); // Invoking the GetNewAttendance method
- // Assert
- Assert.AreEqual("Ãðóïïû íà äèñöèïëèíå ", attendanceViewModel.ParameterName); // Verifying that the ParameterName is set correctly
- }
- [TestMethod]
- public void AttendanceViewModel_NewOption_ReturnsCorrectOptionsForGroupFilter()
- {
- // Arrange
- 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
- var options = attendanceViewModel.NewOption(); // Invoking the NewOption method
- // Assert
- 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]
- public void TimetableViewModel_NewValues_ForGroup_ReturnsExpectedValues()
- {
- // Arrange
- 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
- var values = timetableViewModel.NewValues("Ãðóïïà"); // Invoking the NewValues method with a specific group
- // Assert
- Assert.AreEqual(expectedValuesCount, values.Count); // Verifying that the count of values matches the expected count
- }
- [TestMethod]
- public void TimetableViewModel_NewTimetable_ForTeacher_ReturnsExpectedTimetable()
- {
- // 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);
- // Set the SelectedOption to "Teacher" (Ïðåïîäàâàòåëü in Russian)
- timetableViewModel.SelectedOption = "Ïðåïîäàâàòåëü";
- // 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();
- // Assert: Verify that the count of timetable entries matches the expected count
- Assert.AreEqual(expectedTimetableCount, timetableViewModel.Timetable?.Count);
- }
- [TestMethod]
- public void DisciplineViewModel_NewValues_ForGroup_ReturnsExpectedValues()
- {
- // 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);
- // Set the SelectedOption to "Group" (Ãðóïïà in Russian)
- disciplineViewModel.SelectedOption = "Ãðóïïà";
- // 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("Ãðóïïà");
- // Assert: Verify that the count of values matches the expected count
- Assert.AreEqual(expectedValuesCount, disciplineViewModel.Values.Count);
- }
- [TestMethod]
- public void DisciplineViewModel_NewDisciplines_ForTeacher_ReturnsExpectedDisciplines()
- {
- // 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);
- // Set the SelectedOption to "Teacher" (Ïðåïîäàâàòåëü in Russian)
- disciplineViewModel.SelectedOption = "Ïðåïîäàâàòåëü";
- // 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();
- // Assert: Verify that the count of disciplines matches the expected count
- Assert.AreEqual(expectedDisciplinesCount, disciplineViewModel.Disciplines?.Count);
- }
- [TestMethod]
- public void UserProfileViewModel_GetDisciplines_ReturnsExpectedDisciplines()
- {
- // 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);
- // Get the list of disciplines
- var disciplines = userProfileViewModel.Disciplines;
- // Assert: Verify that the count of disciplines matches the expected count
- Assert.AreEqual(expectedDisciplinesCount, disciplines.Count);
- }
- [TestMethod]
- public void UserProfileViewModel_Initialization_UserIsNotNull()
- {
- // 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);
- // Assert: Verify that the User property is not null
- Assert.IsNotNull(userProfileViewModel.User);
- }
- }
- }
|