コード例 #1
0
 public CourseCategoryManagementService(ICategoryService categoryService, ICourseService courseService,
                                        IStudyMaterialService studyMaterialService, IErrorHandler errorHandler, OrhedgeContext orhedgeContext)
 {
     _courseService        = courseService;
     _categoryService      = categoryService;
     _studyMaterialService = studyMaterialService;
     _errorHandler         = errorHandler;
     _orhedgeContext       = orhedgeContext;
 }
コード例 #2
0
ファイル: Utilities.cs プロジェクト: milicavasic97/Orhedge
        /// <summary>
        /// Creates DBContext which refers to new empty database
        /// </summary>
        /// <returns>Created <see cref="OrhedgeContext"/></returns>
        public static OrhedgeContext CreateNewContext()
        {
            DbContextOptionsBuilder <OrhedgeContext> ctxOpts = new DbContextOptionsBuilder <OrhedgeContext>();

            ctxOpts.UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning));
            var context = new OrhedgeContext(ctxOpts.Options);

            DataGenerator.Initialize(context);
            return(context);
        }
コード例 #3
0
        public void Initialize()
        {
            var configMock = new Mock <IConfiguration>();

            _sharedConfigMock.SetupGet(config => config["BaseUrl"]).Returns(EMAIL_LINK_BASE_URL);
            _sharedConfigMock.SetupGet(config => config["RegisterEmail:From"])
            .Returns(EMAIL_FROM);
            _sharedConfigMock.SetupGet(config => config["RegisterEmail:LinkEndpoint"])
            .Returns(EMAIL_LINK_ENDPOINT);
            _context = Utilities.CreateNewContext();
        }
コード例 #4
0
 public StudyMaterialMenagementService(IErrorHandler errorHandler, ICourseService courseService, IStudyMaterialService studyMaterialService, IDocumentService documentService,
                                       ICategoryService categoryService, IStudentService studentService, OrhedgeContext context)
 {
     _errorHandler         = errorHandler;
     _courseService        = courseService;
     _studyMaterialService = studyMaterialService;
     _documentService      = documentService;
     _categoryService      = categoryService;
     _studentService       = studentService;
     _context = context;
 }
コード例 #5
0
        public async Task Count()
        {
            using (OrhedgeContext context = Utilities.CreateNewContext())
            {
                var errHandlerMock = new Mock <IErrorHandler>();

                IServicesExecutor <StudentDTO, Student> executor
                    = new ServiceExecutor <StudentDTO, Student>(context, errHandlerMock.Object);

                Assert.AreEqual(3, await executor.Count());
                Assert.AreEqual(1, await executor.Count(s => s.Username == "light"));
                errHandlerMock.Verify(err => err.Log(It.IsAny <Exception>()), Times.Never);
            }
        }
コード例 #6
0
        private static void InitializeStudents(OrhedgeContext context)
        {
            (string password, string salt) = Utilities.CreateHashAndSalt("lightPassword");
            Student student1 = new Student()
            {
                Index        = "1161/16",
                Name         = "Marija",
                LastName     = "Novakovic",
                Email        = "*****@*****.**",
                Privilege    = 0,
                PasswordHash = password,
                Username     = "******",
                Salt         = salt,
                Description  = "light description"
            };

            (password, salt) = Utilities.CreateHashAndSalt("darkPassword");
            Student student2 = new Student()
            {
                Index        = "1189/16",
                Name         = "Filip",
                LastName     = "Ivic",
                Email        = "*****@*****.**",
                Privilege    = 0,
                PasswordHash = password,
                Username     = "******",
                Salt         = salt,
                Description  = "dark description"
            };

            (password, salt) = Utilities.CreateHashAndSalt("bluePassword");
            Student student3 = new Student()
            {
                Index        = "1101/19",
                Name         = "Ivko",
                LastName     = "Lukic",
                Email        = "*****@*****.**",
                Privilege    = StudentPrivilege.Normal,
                PasswordHash = password,
                Username     = "******",
                Salt         = salt,
                Description  = "blue description"
            };

            context.Students.Add(student1);
            context.Students.Add(student2);
            context.Students.Add(student3);
            context.SaveChanges();
        }
コード例 #7
0
        private const int REGISTRATION_CODE_SIZE = 16; // In bytes

        public StudentManagmentService(
            IEmailSenderService emailSender,
            IStudentService studentService,
            IRegistrationService registrationService,
            IConfiguration config,
            IProfileImageService imgService,
            IErrorHandler errorHandler,
            OrhedgeContext context)
        {
            (_emailSender, _studentService, _registrationService, _imgService, _context, _errorHandler) =
                (emailSender, studentService, registrationService, imgService, context, errorHandler);
            (_baseUrl, _fromEmailAddress) =
                (new Uri(config["BaseUrl"]), config["RegisterEmail:From"]);
            _emailLinkEndpoint  = config["RegisterEmail:LinkEndpoint"];
            _regEmailTemplateId = config["RegisterEmail:TemplateId"];
        }
コード例 #8
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);
            }
        }
コード例 #9
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);
            }
        }
コード例 #10
0
        public async Task Add()
        {
            StudentDTO correctStudent = new StudentDTO()
            {
                Index        = "1109/18",
                Name         = "Ilija",
                LastName     = "Ilic",
                Email        = "*****@*****.**",
                Privilege    = 0,
                PasswordHash = "sa99d...10043",
                Username     = "******",
                Salt         = "90"
            };

            using (OrhedgeContext context = Utilities.CreateNewContext())
            {
                var errHandlerMock = new Mock <IErrorHandler>();
                var executor       = new ServiceExecutor <StudentDTO, Student>(context, errHandlerMock.Object);
                ResultMessage <StudentDTO> addedStudentResult = await executor.Add(correctStudent, s => s.Email == correctStudent.Email &&
                                                                                   s.Index == correctStudent.Index && s.Username == correctStudent.Username);

                // Check status of operation
                Assert.AreEqual(addedStudentResult.Status, OperationStatus.Success);

                // Check if inserted record exists with valid data
                StudentDTO student = await executor.GetSingleOrDefault((StudentDTO x) => x.Email == correctStudent.Email);

                Assert.IsNotNull(student);
                Assert.AreEqual(student.Index, correctStudent.Index, "Wrong index");
                Assert.AreEqual(student.Username, correctStudent.Username, "Wrong username");
                Assert.AreEqual(student.Privilege, correctStudent.Privilege, "Wrong privlege");
                Assert.AreEqual(student.Name, correctStudent.Name, "Wrong name");
                Assert.AreEqual(student.LastName, correctStudent.LastName, "Wrong last name");

                // Make sure ErrorHandler.Handle method was not called
                errHandlerMock.Verify(err => err.Log(It.IsAny <Exception>()), Times.Never);
            }
        }
コード例 #11
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);
            }
        }
コード例 #12
0
 public static void Initialize(OrhedgeContext context)
 {
     InitializeStudents(context);
 }
コード例 #13
0
 public ServiceExecutor(OrhedgeContext context, IErrorHandler errorHandler)
 {
     _context      = context;
     _errorHandler = errorHandler;
 }
コード例 #14
0
 public CategoryService(IServicesExecutor <CategoryDTO, Category> servicesExecutor, IStudyMaterialService studyMaterialService, IErrorHandler errorHandler, OrhedgeContext context)
     : base(servicesExecutor) => (_context, _studyMaterialService, _errorHandler) = (context, studyMaterialService, errorHandler);
コード例 #15
0
 public ChatMessageService(IServicesExecutor <ChatMessageDTO, ChatMessage> servicesExecutor, IStudentService studentService, OrhedgeContext orhedgeContext) :
     base(servicesExecutor)
 {
     _context        = orhedgeContext;
     _studentService = studentService;
 }