public void TestAddCorrectSchool()
        {
            bool isItemAdded = false;
            var  repository  = Mock.Create <IRepository <School> >();

            var schoolModel = new SchoolModel()
            {
                Name     = "PMG",
                Location = "Sofia"
            };
            var schoolEntity = new School()
            {
                Id       = 1,
                Name     = schoolModel.Name,
                Location = schoolModel.Location
            };

            Mock.Arrange(() => repository.Add(Arg.IsAny <School>()))
            .DoInstead(() => isItemAdded = true)
            .Returns(schoolEntity);

            var controller = new SchoolController(repository);

            SetupController.Create(controller, "post", "school");

            var result = controller.PostSchool(schoolEntity);

            Assert.IsTrue(result.IsSuccessStatusCode);
            Assert.IsTrue(isItemAdded);
        }
        public void TestGetByIdSchool()
        {
            var repository = Mock.Create <IRepository <School> >();
            var school     = new School()
            {
                Id       = 1,
                Name     = "PMG",
                Location = "Sofia"
            };

            Mock.Arrange <School>(
                () => repository.Get(school.Id))
            .IgnoreArguments()
            .Returns(school)
            .MustBeCalled();

            var controller = new SchoolController(repository);

            SetupController.Create(controller, "get", "school");
            var result = controller.GetSchool(school.Id);

            Assert.AreEqual(result.Id, school.Id);
            Assert.AreEqual(result.Name, school.Name);
            Assert.AreEqual(result.Location, school.Location);
        }
Esempio n. 3
0
        public void TestGetByIdMark()
        {
            var repository = Mock.Create <IRepository <Mark> >();
            var mark       = new Mark()
            {
                Id      = 1,
                Subject = "Psycho",
                Value   = 3
            };

            Mock.Arrange <Mark>(
                () => repository.Get(mark.Id))
            .IgnoreArguments()
            .Returns(mark)
            .MustBeCalled();

            var controller = new MarkController(repository);

            SetupController.Create(controller, "get", "mark");
            var result = controller.GetById(mark.Id);

            Assert.AreEqual(result.Id, mark.Id);
            Assert.AreEqual(result.Subject, mark.Subject);
            Assert.AreEqual(result.Value, mark.Value);
        }
Esempio n. 4
0
        public void TestAddCorrectMark()
        {
            bool isItemAdded = false;
            var  repository  = Mock.Create <IRepository <Mark> >();

            var markModel = new MarkModel()
            {
                Value   = 5,
                Subject = "Math"
            };
            var markEntity = new Mark()
            {
                Id      = 1,
                Value   = markModel.Value,
                Subject = markModel.Subject
            };

            Mock.Arrange(() => repository.Add(Arg.IsAny <Mark>()))
            .DoInstead(() => isItemAdded = true)
            .Returns(markEntity);

            var controller = new MarkController(repository);

            SetupController.Create(controller, "post", "mark");

            var result = controller.Post(markEntity);

            Assert.IsTrue(result.IsSuccessStatusCode);
            Assert.IsTrue(isItemAdded);
        }
        public void TestGetByIdStudent()
        {
            var repository = Mock.Create <IRepository <Student> >();
            var student    = new Student()
            {
                Id        = 1,
                FirstName = "Pesho",
                LastName  = "Peshov",
                Grade     = 3
            };

            Mock.Arrange <Student>(
                () => repository.Get(student.Id))
            .IgnoreArguments()
            .Returns(student)
            .MustBeCalled();

            var controller = new StudentController(repository);

            SetupController.Create(controller, "get", "student");
            var result = controller.GetById(student.Id);

            Assert.AreEqual(result.Id, student.Id);
            Assert.AreEqual(result.FirstName, student.FirstName);
            Assert.AreEqual(result.LastName, student.LastName);
            Assert.AreEqual(result.Grade, student.Grade);
        }
        public void TestAddCorrectStudent()
        {
            bool isItemAdded = false;
            var  repository  = Mock.Create <IRepository <Student> >();

            var studentModel = new StudentModel()
            {
                FirstName = "Pesho",
                LastName  = "Peshov",
                Grade     = 3
            };
            var studentEntity = new Student()
            {
                Id        = 1,
                FirstName = studentModel.FirstName,
                LastName  = studentModel.LastName,
                Grade     = studentModel.Grade
            };

            Mock.Arrange(() => repository.Add(Arg.IsAny <Student>()))
            .DoInstead(() => isItemAdded = true)
            .Returns(studentEntity);

            var controller = new StudentController(repository);

            SetupController.Create(controller, "post", "student");

            var result = controller.Post(studentEntity);

            Assert.IsTrue(result.IsSuccessStatusCode);
            Assert.IsTrue(isItemAdded);
        }
        public void TestDeleteStudent()
        {
            bool isItemDeleted = false;
            bool isItemAdded   = false;
            var  repository    = Mock.Create <IRepository <Student> >();

            var studentModel = new StudentModel()
            {
                FirstName = "Pesho",
                LastName  = "Peshov",
                Grade     = 3
            };
            var studentEntity = new Student()
            {
                Id        = 1,
                FirstName = studentModel.FirstName,
                LastName  = studentModel.LastName,
                Grade     = studentModel.Grade
            };

            Mock.Arrange(() => repository.Add(Arg.IsAny <Student>()))
            .DoInstead(() => isItemAdded = true)
            .Returns(studentEntity);

            var controller = new StudentController(repository);

            SetupController.Create(controller, "post", "student");

            controller.Post(studentEntity);

            Mock.Arrange(() => repository.Delete(Arg.IsAny <Student>()))
            .DoInstead(() => isItemDeleted = true);


            SetupController.Create(controller, "delete", "student");

            controller.Delete(studentEntity.Id);

            Assert.IsFalse(isItemDeleted);
        }
        public void TestDeleteSchool()
        {
            bool isItemDeleted = false;
            bool isItemAdded   = false;
            var  repository    = Mock.Create <IRepository <School> >();

            var schoolModel = new SchoolModel()
            {
                Location = "sofia",
                Name     = "HMG"
            };
            var schoolEntity = new School()
            {
                Id       = 1,
                Location = schoolModel.Location,
                Name     = schoolModel.Name
            };

            Mock.Arrange(() => repository.Add(Arg.IsAny <School>()))
            .DoInstead(() => isItemAdded = true)
            .Returns(schoolEntity);

            var controller = new SchoolController(repository);

            SetupController.Create(controller, "post", "school");

            controller.PostSchool(schoolEntity);

            Mock.Arrange(() => repository.Delete(Arg.IsAny <School>()))
            .DoInstead(() => isItemDeleted = true);


            SetupController.Create(controller, "delete", "school");

            controller.DeleteSchool(schoolEntity.Id);

            Assert.IsFalse(isItemDeleted);
        }
Esempio n. 9
0
        public void TestDeleteMark()
        {
            bool isItemDeleted = false;
            bool isItemAdded   = false;
            var  repository    = Mock.Create <IRepository <Mark> >();

            var markModel = new MarkModel()
            {
                Value   = 5,
                Subject = "Math"
            };
            var markEntity = new Mark()
            {
                Id      = 1,
                Value   = markModel.Value,
                Subject = markModel.Subject
            };

            Mock.Arrange(() => repository.Add(Arg.IsAny <Mark>()))
            .DoInstead(() => isItemAdded = true)
            .Returns(markEntity);

            var controller = new MarkController(repository);

            SetupController.Create(controller, "post", "mark");

            controller.Post(markEntity);

            Mock.Arrange(() => repository.Delete(Arg.IsAny <Mark>()))
            .DoInstead(() => isItemDeleted = true);


            SetupController.Create(controller, "delete", "mark");

            controller.Delete(markEntity.Id);

            Assert.IsFalse(isItemDeleted);
        }