Пример #1
0
        public async Task CreateStudent_ReturnsCreatedStudent()
        {
            var student = new StudentInputViewModel
            {
                FirstName = "Stu",
                LastName  = "Steiner"
            };

            var service = new Mock <IStudentService>();

            service.Setup(x => x.AddStudent(It.Is <Student>(g => g.FirstName == student.FirstName)))
            .Returns(Task.FromResult(new Student
            {
                Id        = 2,
                FirstName = student.FirstName,
                LastName  = student.LastName
            }))
            .Verifiable();

            var controller = new StudentsController(service.Object, Mapper.Instance);

            var     result      = (await controller.AddStudent(student)).Result as OkObjectResult;
            Student resultValue = (Student)result.Value;

            Assert.IsNotNull(resultValue);
            Assert.AreEqual(2, resultValue.Id);
            Assert.AreEqual("Stu", resultValue.FirstName);
            Assert.AreEqual("Steiner", resultValue.LastName);
            service.VerifyAll();
        }
Пример #2
0
        private void btnAddStudent_Click(object sender, EventArgs e)
        {
            try
            {
                var studentInfo = new StudentInfoViewModel
                {
                    Course        = (byte)this.numCourse.Value,
                    Faculty       = this.textBoxFaculty.Text,
                    FacultyNumber = this.textBoxFacultyNumber.Text,
                    FirstName     = this.textBoxFirstName.Text,
                    SecondName    = this.textBoxSecondName.Text,
                    LastName      = this.textBoxLastName.Text,
                    Status        = (StudentStatus)this.comboStatus.SelectedValue,
                    Group         = byte.Parse(this.textBoxGroup.Text),
                    Degree        = (Degree)this.comboOks.SelectedValue,
                    Potok         = this.textBoxPotok.Text,
                    Speciality    = this.textBoxSpeciality.Text
                };

                var studentsContoller = new StudentsController(new StudentInfoSystemData());

                studentsContoller.AddStudent(studentInfo);
                MessageBox.Show(
                    "Успешно добавихте нов студент!",
                    "Успешно добавен студент",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Грешки", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        public static void Main(string[] args)
        {
            var ctrl = new StudentsController();

            AddStudentPostModel studentModel = new AddStudentPostModel()
            {
                FirstName = "Петя",
                Lastname  = "Пупкин",
                Age       = 34,
                Payments  = new List <PaymentPost>()
                {
                    new PaymentPost()
                    {
                        Date  = Convert.ToDateTime("2019-02-20"),
                        Value = 60
                    }
                }
            };

            ctrl.AddStudent(studentModel);
            var student = ctrl.GetById(1);

            var studentList = ctrl.GetStudents(80);

            foreach (var stud in studentList)
            {
                Console.WriteLine($"{stud.FullName} {stud.Sum}");
            }
        }
        public async Task Add_New_Student()
        {
            //Given
            StudentDTO student = new StudentDTO()
            {
                forename = "test",
                surname  = "test",
                status   = "test",
                age      = 1
            };

            var mockStudentReposiotory = new Mock <IStudentRepository>();

            mockStudentReposiotory.Setup(x => x.Add(It.IsAny <Student>())).ReturnsAsync(true);

            //When
            StudentsController studentsController = new StudentsController(mockStudentReposiotory.Object);
            var result = await studentsController.AddStudent(student) as ObjectResult;

            var objectResult = (Student)result.Value;

            //Then
            Assert.AreEqual((int)HttpStatusCode.Created, result.StatusCode);
            Assert.AreEqual(student.forename, objectResult.forename);
            Assert.AreEqual(student.surname, objectResult.surname);
            Assert.AreEqual(student.age, objectResult.age);
            Assert.AreEqual(student.status, objectResult.status);
        }
Пример #5
0
        public async Task CreateStudent_RequiresStudent()
        {
            var service    = new Mock <IStudentService>();
            var controller = new StudentsController(service.Object, Mapper.Instance);

            var result = (await controller.AddStudent(null)).Result as BadRequestResult;

            Assert.IsNotNull(result);
        }
Пример #6
0
        public static void Main(string[] args)
        {
            var ctrl = new StudentsController();

            DateTime date1 = new DateTime(2017, 7, 20);
            DateTime date2 = new DateTime(2018, 8, 22);
            DateTime date3 = new DateTime(2019, 2, 12);
            DateTime date4 = new DateTime(2015, 5, 9);

            PaymentPostModel payment1 = new PaymentPostModel()
            {
                Date = date1, Value = 100
            };
            PaymentPostModel payment2 = new PaymentPostModel()
            {
                Date = date2, Value = 120
            };
            PaymentPostModel payment3 = new PaymentPostModel()
            {
                Date = date3, Value = 110
            };
            PaymentPostModel payment4 = new PaymentPostModel()
            {
                Date = date4, Value = 90
            };

            List <PaymentPostModel> paymentList1 = new List <PaymentPostModel>()
            {
                payment1, payment2
            };
            List <PaymentPostModel> paymentList2 = new List <PaymentPostModel>()
            {
                payment3, payment4
            };
            List <PaymentPostModel> paymentList3 = new List <PaymentPostModel>()
            {
                payment1
            };
            List <PaymentPostModel> paymentList4 = new List <PaymentPostModel>()
            {
                payment4
            };

            StudentPostModel stToAdd_1 = new StudentPostModel()
            {
                FirstName = "Ivan", Lastname = "Ivanov", Age = 20, Payments = paymentList1
            };
            StudentPostModel stToAdd_2 = new StudentPostModel()
            {
                FirstName = "Petr", Lastname = "Petrov", Age = 20, Payments = paymentList2
            };
            StudentPostModel stToAdd_3 = new StudentPostModel()
            {
                FirstName = "Homer", Lastname = "Simson", Age = 45, Payments = paymentList3
            };
            StudentPostModel stToAdd_4 = new StudentPostModel()
            {
                FirstName = "Burt", Lastname = "Simson", Age = 20, Payments = paymentList4
            };

            ctrl.AddStudent(stToAdd_1);
            ctrl.AddStudent(stToAdd_2);
            ctrl.AddStudent(stToAdd_3);
            ctrl.AddStudent(stToAdd_4);

            int minimumTotal  = 150;
            var stPayLessThan = ctrl.GetStudentWhichPayLessThan(minimumTotal);

            if (stPayLessThan != null)
            {
                Console.WriteLine($"Student(s), who paid less, than {minimumTotal}");
                foreach (var item in stPayLessThan)
                {
                    Console.WriteLine($"Student {item.FullName} paid in total {item.Total}");
                }
            }

            Console.WriteLine("Finish work");


            Console.ReadKey();

            //var student = ctrl.GetById(1);
        }