예제 #1
0
        public async Task GetSingleOrDefault()
        {
            using (OrhedgeContext context = Utilities.CreateNewContext())
            {
                var errHandlerMock         = new Mock <IErrorHandler>();
                var executor               = new ServiceExecutor <StudentDTO, Student>(context, errHandlerMock.Object);
                List <StudentDTO> students = await executor.GetAll <int>(dtoCondition : s => true);

                StudentDTO student = await executor.GetSingleOrDefault((StudentDTO x) => x.Username == "light");

                Assert.AreNotEqual(student, null);

                StudentDTO noStudent = await executor.GetSingleOrDefault((StudentDTO x) => x.Username == "nonexistent");

                Assert.AreEqual(noStudent, null);

                // Make sure ErrorHandler.Handle method was not called
                errHandlerMock.Verify(err => err.Log(It.IsAny <Exception>()), Times.Never);
            }
        }
예제 #2
0
        public async Task GetAll()
        {
            int numberOfElements = 3;

            using (OrhedgeContext context = Utilities.CreateNewContext())
            {
                var errHandlerMock = new Mock <IErrorHandler>();
                var executor       = new ServiceExecutor <StudentDTO, Student>(context, errHandlerMock.Object);

                List <StudentDTO> list = await executor.GetAll <int>(dtoCondition : x => x.Deleted == false);

                Assert.AreEqual(list.Count, numberOfElements);

                string     existingUsername = "******";
                StudentDTO student          = await executor.GetSingleOrDefault((StudentDTO x) => x.Username == existingUsername);

                Assert.IsTrue(list.Contains(student));

                // Make sure ErrorHandler.Handle method was not called
                errHandlerMock.Verify(err => err.Log(It.IsAny <Exception>()), Times.Never);
            }
        }
예제 #3
0
        public async Task Update()
        {
            using (OrhedgeContext context = Utilities.CreateNewContext())
            {
                var        errHandlerMock        = new Mock <IErrorHandler>();
                var        executor              = new ServiceExecutor <StudentDTO, Student>(context, errHandlerMock.Object);
                StudentDTO correctUpdatedStudent = await executor.GetSingleOrDefault((StudentDTO x) => x.Username == "light");

                correctUpdatedStudent.Name        = "Milica";
                correctUpdatedStudent.Rating      = 3;
                correctUpdatedStudent.Username    = "******";
                correctUpdatedStudent.Privilege   = StudentPrivilege.JuniorAdmin;
                correctUpdatedStudent.Description = "Pesimist";
                Assert.IsNotNull(correctUpdatedStudent, "Student to update not found");

                ResultMessage <StudentDTO> status = await executor.Update(correctUpdatedStudent, x => x.Username == "light");

                // Check status of operation
                Assert.AreEqual(status.Status, OperationStatus.Success);
                List <StudentDTO> students = await executor.GetAll <int>(dtoCondition : x => true);

                ResultMessage <StudentDTO> updatedStudent = await executor.GetSingleOrDefault((StudentDTO x) => x.Username == "mica");

                Assert.IsNotNull(updatedStudent.Result);

                // Check if inserted record exists with valid data
                Assert.AreEqual(updatedStudent.Result.Rating, correctUpdatedStudent.Rating, "Wrong rating");
                Assert.AreEqual(updatedStudent.Result.Name, correctUpdatedStudent.Name, "Wrong name");
                Assert.AreEqual(updatedStudent.Result.Username, correctUpdatedStudent.Username, "Wrong username");
                Assert.AreEqual(updatedStudent.Result.Privilege, correctUpdatedStudent.Privilege, "Wrong privilege");
                Assert.AreEqual(updatedStudent.Result.Description, correctUpdatedStudent.Description, "Wrong description");

                // Make sure ErrorHandler.Handle method was not called
                errHandlerMock.Verify(err => err.Log(It.IsAny <Exception>()), Times.Never);
            }
        }