private Command AddCourse(string textCommandLine) { Regex regex = new Regex("\"(.*?)\""); var matches = regex.Matches(textCommandLine); var args = new string[matches.Count]; for (int i = 0; i < args.Length; i++) { args[i] = matches[i].Value.Replace("\"", ""); } var course = new Course { Name = args[0], Section = args[1], Room = args[2], PrimaryTeacher = new Teacher { Email = args[3] } }; return(new Command(() => { var createCourseCommand = new CreateCourseCommand(_courseService, course); createCourseCommand.Execute(); _course = createCourseCommand.Result; return _course; }, CommandType.AddCourse)); }
public void ThrowExceptionMessage_WhenGivenInvalidInput() { //Arrange var seasonMock = new Mock <ISeason>(); var databaseMock = new Mock <IDatabase>(); var factoryMock = new Mock <IAcademyFactory>(); var seasonId = "0"; var name = "Javascript"; var lecturesPerWeek = "3"; var startingDate = "2017/07/12"; var course = new Course(name, int.Parse(lecturesPerWeek), DateTime.Parse(startingDate), DateTime.Parse(startingDate).AddDays(15)); var databaseSeasons = new List <ISeason>() { seasonMock.Object }; var seasonCourses = new List <ICourse>(); var parametersList = new List <string>() { seasonId, name, lecturesPerWeek, startingDate }; seasonMock.SetupGet(s => s.Courses) .Returns(seasonCourses); databaseMock.SetupGet(d => d.Seasons) .Returns(databaseSeasons); factoryMock.Setup(f => f.CreateCourse(name, lecturesPerWeek, startingDate)) .Returns(course); var createCourseCommand = new CreateCourseCommand(factoryMock.Object, databaseMock.Object); string expectedsuccessMessage = "Course with ID 0 was created in Season 0."; // Act string successMessage = createCourseCommand.Execute(parametersList); // Assert Assert.AreEqual(course, seasonMock.Object.Courses.Single()); Assert.AreEqual(expectedsuccessMessage, successMessage); }
public void ShouldThrowArgumentOutOfRangeException_WhenParametersListIsNotFull() { var databaseMock = new Mock <IDatabase>(); var factoryMock = new Mock <IAcademyFactory>(); var parametersList = new List <string>() { "just name" }; var createCourseCommand = new CreateCourseCommand(factoryMock.Object, databaseMock.Object); Assert.ThrowsException <ArgumentOutOfRangeException>(() => createCourseCommand.Execute(parametersList)); }
public void ReturnText_WhenParametersAreCorrect() { // Arrange var factoryMock = new Mock <IAcademyFactory>(); var databaseMock = new Mock <IDatabase>(); var firstSeasonMock = new Mock <ISeason>(); var secondSeasonMock = new Mock <ISeason>(); var courseMock = new Mock <ICourse>(); var firstCourseMock = new Mock <ICourse>(); List <ISeason> seasons = new List <ISeason>() { firstSeasonMock.Object, secondSeasonMock.Object }; List <ICourse> courses = new List <ICourse>(); courses.Add(firstCourseMock.Object); string seasonId = "1"; string courseName = "JavaScriptOOP"; string lecturesPerWeek = "2"; string startingDate = "2017-01-24"; string expectedResult = $"Course with ID 1 was created in Season {seasonId}."; databaseMock.SetupGet(m => m.Seasons).Returns(seasons); factoryMock .Setup(m => m.CreateCourse(courseName, lecturesPerWeek, startingDate)) .Returns(courseMock.Object); secondSeasonMock.SetupGet(m => m.Courses).Returns(courses); List <string> parameters = new List <string>() { seasonId, courseName, lecturesPerWeek, startingDate }; CreateCourseCommand command = new CreateCourseCommand(factoryMock.Object, databaseMock.Object); // Act var result = command.Execute(parameters); // Assert Assert.AreEqual(expectedResult, result); }
public void ShouldCreateAddCourseToDatabaseAndReturnSuccessMessage_WhenParametersAreValid() { // Arrange var seasonMock = new Mock <ISeason>(); var databaseMock = new Mock <IDatabase>(); var factoryMock = new Mock <IAcademyFactory>(); var seasonId = "0"; var name = "some course"; var lecturesPerWeek = "5"; var startingDate = "2017/03/15"; var course = new Course(name, int.Parse(lecturesPerWeek), DateTime.Parse(startingDate), DateTime.Parse(startingDate).AddDays(30)); var databaseSeasons = new List <ISeason>() { seasonMock.Object }; var seasonCourses = new List <ICourse>(); var parametersList = new List <string>() { seasonId, name, lecturesPerWeek, startingDate }; seasonMock.SetupGet(s => s.Courses) .Returns(seasonCourses); databaseMock.SetupGet(d => d.Seasons) .Returns(databaseSeasons); factoryMock.Setup(f => f.CreateCourse(name, lecturesPerWeek, startingDate)) .Returns(course); var createCourseCommand = new CreateCourseCommand(factoryMock.Object, databaseMock.Object); string expectedsuccessMessage = "Course with ID 0 was created in Season 0."; // Act string successMessage = createCourseCommand.Execute(parametersList); // Assert Assert.AreEqual(course, seasonMock.Object.Courses.Single()); Assert.AreEqual(expectedsuccessMessage, successMessage); }
public void CreateCourseAndAddItToSeason_WhenParametersAreCorrect() { // Arrange var factoryMock = new Mock <IAcademyFactory>(); var databaseMock = new Mock <IDatabase>(); var firstSeasonMock = new Mock <ISeason>(); var secondSeasonMock = new Mock <ISeason>(); var courseMock = new Mock <ICourse>(); List <ISeason> seasons = new List <ISeason>() { firstSeasonMock.Object, secondSeasonMock.Object }; List <ICourse> courses = new List <ICourse>(); string courseName = "JavaScriptOOP"; string lecturesPerWeek = "2"; string startingDate = "2017-01-24"; databaseMock.SetupGet(m => m.Seasons).Returns(seasons); factoryMock .Setup(m => m.CreateCourse(courseName, lecturesPerWeek, startingDate)) .Returns(courseMock.Object); secondSeasonMock.SetupGet(m => m.Courses).Returns(courses); List <string> parameters = new List <string>() { "1", courseName, lecturesPerWeek, startingDate }; CreateCourseCommand command = new CreateCourseCommand(factoryMock.Object, databaseMock.Object); // Act command.Execute(parameters); // Assert Assert.AreEqual(1, secondSeasonMock.Object.Courses.Count); Assert.AreSame(courseMock.Object, secondSeasonMock.Object.Courses.Single()); }
public void ReturnsTheCorrectString_WhenParamsAreCorrect() { // Arange var courseMock = new Mock <ICourse>(); var factoryMock = new Mock <IAcademyFactory>(); factoryMock.Setup(m => m.CreateCourse(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(courseMock.Object); seasonMock.Setup(x => x.Courses).Returns(new List <ICourse>()); var command = new CreateCourseCommand(factoryMock.Object, engine); string expectedMessage = $"Course with ID 0 was created in Season {databaseMock.Object.Seasons.Count - 1}."; // Act && Assert Assert.AreEqual(expectedMessage, command.Execute(commandLine)); }
protected void Reg_Mat(object sender, EventArgs e) { grades = new Grade(); grades.Id = Int32.Parse(list_grades.SelectedValue); grades.Name = list_grades.DataTextField; course = new Course(); course.Id = name.Value.Substring(0, 4) + list_grades.SelectedValue + DateTime.Now.Year.ToString(); course.Name = name.Value; course.Description = desc.Value; course.Grade = grades; CreateCourseCommand cmd = new CreateCourseCommand(course); cmd.Execute(); if (course.Code == 200) { ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme_succ()", true); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true); } }
public void CreateCourseAndAddItToDatabase_WhenParametersAreCorrect() { //Arange var courseMock = new Mock <ICourse>(); var factoryMock = new Mock <IAcademyFactory>(); factoryMock.Setup(m => m.CreateCourse(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(courseMock.Object); seasonMock.Setup(m => m.Courses).Returns(new List <ICourse>()); var command = new CreateCourseCommand(factoryMock.Object, engine); //Act command.Execute(commandLine); //Assert Assert.AreEqual(courseMock.Object, databaseMock.Object.Seasons[0].Courses.Single()); }