private void buttonOK_Click(object sender, EventArgs e) { int duration = 0; decimal cost = 0; if (!Validator.Cost(costBox.Text) || !Validator.Duration(durationBox.Text) || !int.TryParse(durationBox.Text, out duration) || !decimal.TryParse(costBox.Text, out cost)) { MessageBox.Show("Неверный формат данных", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { if (CoursesRequests.AddCourse((int)subjectBox.SelectedValue, duration, cost) == null) { MessageBox.Show("Такой курс уже есть", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Close(); } } catch (Exception) { MessageBox.Show("Шото сломалось", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public async Task WhenIAddCourse_ThenICanRetrieveIt() { var newCourse = new Course { Name = "Course 1" }; int newId = await CoursesRequests.AddCourse(newCourse); var course = await CoursesRequests.GetCourse(newId); Assert.Equal(newCourse.Name, course.Name); }
public async Task WhenIEnrollNonExistingUserToACourse_ThenIGetAProperErrorMessage() { var nonExistingUserId = 100000; var newCourse = new Course { Name = "Course 1" }; int newId = await CoursesRequests.AddCourse(newCourse); var enrollmentResponse = await CoursesRequests.EnrollUserToACourse(nonExistingUserId, newId); Assert.False(enrollmentResponse.Item1); Assert.Equal($"User with Id: {nonExistingUserId} does not exist!", enrollmentResponse.Item2); }
public async Task WhenIDeleteACourse_ThenICantRetrieveItAnymore() { var newCourse = new Course { Name = "Course 1" }; int newId = await CoursesRequests.AddCourse(newCourse); var course = await CoursesRequests.GetCourse(newId); Assert.NotNull(course); Assert.True(await CoursesRequests.DeleteCourse(newId)); Assert.Null(await CoursesRequests.GetCourse(newId)); }
public async Task WhenIEnrollUsersToCourses_ThenICanRetrieveTheListOfCoursesWithEnrollments() { var newUser1 = new User { Email = "*****@*****.**" }; var newUser2 = new User { Email = "*****@*****.**" }; var newUser3 = new User { Email = "*****@*****.**" }; var course1 = new Course { Name = "Course 1" }; var course2 = new Course { Name = "Course 2" }; var course3 = new Course { Name = "Course 3" }; int newId1 = await UsersRequests.AddUser(newUser1); int newId2 = await UsersRequests.AddUser(newUser2); int newId3 = await UsersRequests.AddUser(newUser3); int course1Id = await CoursesRequests.AddCourse(course1); int course2Id = await CoursesRequests.AddCourse(course2); int course3Id = await CoursesRequests.AddCourse(course3); Assert.True((await CoursesRequests.EnrollUserToACourse(newId1, course1Id)).Item1); Assert.True((await CoursesRequests.EnrollUserToACourse(newId1, course2Id)).Item1); Assert.True((await CoursesRequests.EnrollUserToACourse(newId2, course2Id)).Item1); Assert.True((await CoursesRequests.EnrollUserToACourse(newId2, course3Id)).Item1); Assert.True((await CoursesRequests.EnrollUserToACourse(newId3, course1Id)).Item1); Assert.True((await CoursesRequests.EnrollUserToACourse(newId3, course2Id)).Item1); var coursesWithEnrollments = await CoursesRequests.GetCoursesWithEnrollments(); Assert.Equal(2, coursesWithEnrollments.Single(x => x.Id.Equals(course1Id)).NumberOfEnrollments); Assert.Equal(3, coursesWithEnrollments.Single(x => x.Id.Equals(course2Id)).NumberOfEnrollments); Assert.Equal(1, coursesWithEnrollments.Single(x => x.Id.Equals(course3Id)).NumberOfEnrollments); }
public async Task WhenIWithdrawAUserFromACourseHeWasntEnrolledTo_ThenIGetAProperErrorMessage() { var newUser = new User { Email = "*****@*****.**" }; var course1 = new Course { Name = "Course 1" }; int user1Id = await UsersRequests.AddUser(newUser); int course1Id = await CoursesRequests.AddCourse(course1); var enrollmentResponse1 = await CoursesRequests.WithdrawUserFromACourse(user1Id, course1Id); Assert.False(enrollmentResponse1.Item1); Assert.Equal("User was not enrolled to that course!", enrollmentResponse1.Item2); }
public async Task WhenIEnrollUserToThreeCourses_ThenICanRetrieveTheListOfThem() { var newUser = new User { Email = "*****@*****.**" }; var course1 = new Course { Name = "Course 1" }; var course2 = new Course { Name = "Course 2" }; var course3 = new Course { Name = "Course 3" }; int newId = await UsersRequests.AddUser(newUser); int course1Id = await CoursesRequests.AddCourse(course1); int course2Id = await CoursesRequests.AddCourse(course2); int course3Id = await CoursesRequests.AddCourse(course3); var enrollmentResult1 = await CoursesRequests.EnrollUserToACourse(newId, course1Id); var enrollmentResult2 = await CoursesRequests.EnrollUserToACourse(newId, course2Id); var enrollmentResult3 = await CoursesRequests.EnrollUserToACourse(newId, course3Id); Assert.True(enrollmentResult1.Item1); Assert.True(enrollmentResult2.Item1); Assert.True(enrollmentResult3.Item1); var coursesForUser = await UsersRequests.GetUserCourses(newId); Assert.Collection(coursesForUser, item => Assert.Contains(course1.Name, item.Name), item => Assert.Contains(course2.Name, item.Name), item => Assert.Contains(course3.Name, item.Name)); }
public async Task WhenIEnrollAUserToACourseHeIsAlreadyEnrolledTo_ThenIGetAProperErrorMessage() { var newUser = new User { Email = "*****@*****.**" }; var course1 = new Course { Name = "Course 1" }; int user1Id = await UsersRequests.AddUser(newUser); int course1Id = await CoursesRequests.AddCourse(course1); var enrollmentResponse1 = await CoursesRequests.EnrollUserToACourse(user1Id, course1Id); Assert.True(enrollmentResponse1.Item1); Assert.Equal($"User: {user1Id} successfully enrolled to course: {course1Id}!", enrollmentResponse1.Item2); var enrollmentResponse2 = await CoursesRequests.EnrollUserToACourse(user1Id, course1Id); Assert.False(enrollmentResponse2.Item1); Assert.Equal("User already enrolled to that course!", enrollmentResponse2.Item2); }
public async Task WhenIWithdrawAUserFromACourse_ThenIGetASuccessMessage() { var newUser = new User { Email = "*****@*****.**" }; var course1 = new Course { Name = "Course 1" }; int user1Id = await UsersRequests.AddUser(newUser); int course1Id = await CoursesRequests.AddCourse(course1); var enrollmentResponse1 = await CoursesRequests.EnrollUserToACourse(user1Id, course1Id); Assert.True(enrollmentResponse1.Item1); Assert.Equal($"User: {user1Id} successfully enrolled to course: {course1Id}!", enrollmentResponse1.Item2); var enrollmentResponse2 = await CoursesRequests.WithdrawUserFromACourse(user1Id, course1Id); Assert.True(enrollmentResponse2.Item1); Assert.Equal($"User: {user1Id} successfully withdrawed from course: {course1Id}!", enrollmentResponse2.Item2); }