Example #1
0
        /// <summary>
        /// 执行代码自动服务内容
        /// </summary>
        protected void OnExecutingServiceItem()
        {
            var delegateService = GetDelegateService();
            var serviceList     = this.EventActivity.ServiceList;

            ServiceExecutor.ExecteServiceList(serviceList, delegateService as IDelegateService);
        }
Example #2
0
        public ResultBody <GetHotelResult> GetHotel(GetHotelRequest request)
        {
            Func <GetHotelResult> x = () =>
            {
                return(new GetHotelResult());
            };

            return(ServiceExecutor.Execute(x, "HotelService/GetHotel"));
        }
Example #3
0
        public async ValueTask <IList <Starship> > ExecuteAsync()
        {
            if (!_cache.TryGetValue <List <Starship> >(_startshipsCacheKey, out var starships))
            {
                var apiResponse = await ServiceExecutor.ExecuteAsync <ApiResponse>(
                    _logger, () => _starShipsServiceClient.GetStarshipsAsync(1));

                starships = apiResponse?.Data?.Starships as List <Starship>;

                var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(DateTimeOffset.Now.AddDays(1));
                _cache.Set(_startshipsCacheKey, starships, cacheEntryOptions);
            }
            return(starships);
        }
        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);
            }
        }
Example #5
0
        public async Task UpdateStudentProfile()
        {
            byte[] mockImgData = Enumerable.Range(0, 10)
                                 .Select(n => (byte)n)
                                 .ToArray();
            Mock <IUploadedFile> fileMock = new Mock <IUploadedFile>();

            fileMock
            .Setup(file => file.GetFileDataAsync())
            .ReturnsAsync(mockImgData);

            IUploadedFile mockedFile = fileMock.Object;

            _imgMock
            .Setup(imgService => imgService.SaveProfileImage(mockedFile))
            .ReturnsAsync(new ResultMessage <string>("testpath"));

            IServicesExecutor <StudentDTO, Student> executor
                = new ServiceExecutor <StudentDTO, Student>(_context, _handlerMock.Object);
            IStudentService          studentService = new StudentService(executor);
            Mock <IErrorHandler>     handlerMock    = new Mock <IErrorHandler>();
            IStudentManagmentService studMngService
                = new StudentManagmentService(
                      _emailMock.Object,
                      studentService,
                      _regMock.Object,
                      _sharedConfigMock.Object,
                      _imgMock.Object,
                      handlerMock.Object,
                      _context);

            Student stud = await _context.Students.FirstOrDefaultAsync();

            string newUsername    = "******";
            string newDescription = "New description";

            await studMngService.EditStudentProfile(stud.StudentId, new ProfileUpdateDTO
            {
                Username    = "******",
                Description = "New description",
                Photo       = fileMock.Object
            });

            stud = await _context.Students.FirstOrDefaultAsync(s => s.StudentId == stud.StudentId);

            Assert.AreEqual(newUsername, stud.Username);
            Assert.AreEqual(newDescription, stud.Description);
            _imgMock.Verify(imgService => imgService.SaveProfileImage(mockedFile), Times.Once);
        }
Example #6
0
        public async Task ChangePassword(string oldPassword, string newPassword, string confirmPassword)
        {
            Mock <IEmailSenderService>  mockEmail   = new Mock <IEmailSenderService>();
            Mock <IRegistrationService> mockReg     = new Mock <IRegistrationService>();
            Mock <IErrorHandler>        handlerMock = new Mock <IErrorHandler>();

            IServicesExecutor <StudentDTO, Student> executor
                = new ServiceExecutor <StudentDTO, Student>(_context, handlerMock.Object);
            IStudentService          studentService = new StudentService(executor);
            IStudentManagmentService studMngService
                = new StudentManagmentService(
                      mockEmail.Object,
                      studentService,
                      mockReg.Object,
                      _sharedConfigMock.Object,
                      _imgMock.Object,
                      handlerMock.Object,
                      _context);

            Student stud = await _context.Students.FirstOrDefaultAsync(s => s.Username == "light");

            const string studOldPassword = "******";

            PassChangeStatus status = await studMngService.UpdateStudentPassword(
                stud.StudentId, new UpdatePasswordDTO
            {
                OldPassword     = oldPassword,
                NewPassword     = newPassword,
                ConfirmPassword = confirmPassword
            });

            if (studOldPassword != oldPassword)
            {
                Assert.AreEqual(PassChangeStatus.InvalidOldPass, status);
            }
            else if (newPassword != confirmPassword)
            {
                Assert.AreEqual(PassChangeStatus.PassNoMatch, status);
            }
            else
            {
                Assert.AreEqual(PassChangeStatus.Success, status);
            }
        }
        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);
            }
        }
        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);
            }
        }
Example #9
0
        public async ValueTask <IList <Starship> > ExecuteAsync()
        {
            if (!_cache.TryGetValue <List <Starship> >(_startshipsCacheKey, out var starships))
            {
                starships = new List <Starship>();
                ServiceResponse <ApiResponse> apiResponse;
                var pageNumber = 1;
                do
                {
                    apiResponse = await ServiceExecutor.ExecuteAsync <ApiResponse>(
                        _logger, () => _starShipsServiceClient.GetStarshipsAsync(pageNumber));

                    var collection = apiResponse?.Data?.Starships;
                    starships.AddRange(collection.Select(starship => starship));
                    pageNumber++;
                } while (!string.IsNullOrWhiteSpace(apiResponse?.Data.NextPageUrl));

                var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(DateTimeOffset.Now.AddDays(1));
                _cache.Set(_startshipsCacheKey, starships, cacheEntryOptions);
            }
            return(starships);
        }
        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);
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            ServiceExecutor serviceExecutor = new ServiceExecutor();

            serviceExecutor.statusChanged += DisplayStatus;
            Task.Factory.StartNew(serviceExecutor.Start);
            Thread.Sleep(1000);
            // for (int i = 0; i < 100; i++)
            //{
            //    Console.WriteLine(i);
            //    Thread.Sleep(1000);
            //}

            ClientExecutor clientExecutor = new ClientExecutor();
            VisitorDTO     v = new VisitorDTO {
                Column1 = "Первая колонка"
            };
            VisitorDTO v1 = new VisitorDTO {
                Column1 = "Вторая лолонка", Column2 = "Вторая колонка"
            };

            clientExecutor.GetClient().AddOrUpdateVisitor(v);
            clientExecutor.GetClient().AddOrUpdateVisitor(v);
            clientExecutor.GetClient().AddOrUpdateVisitor(v1);
            Thread.Sleep(1000);
            var cv = clientExecutor.GetClient().GetAllVisitors();

            foreach (var c in cv)
            {
                Console.WriteLine(c.Column1 + " - " + (c.Column2 == null?"n":c.Column2));
            }

            for (int i = 1; i < 200; i++)
            {
                Thread.Sleep(1000); Console.WriteLine(i);
            }
        }
        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);
            }
        }
Example #13
0
 private async Task MessageListener_Received(IMessageSender sender, TransportMessage message)
 {
     await ServiceExecutor.ExecuteAsync(sender, message);
 }
Example #14
0
 static void Main(string[] args)
 {
     ServiceExecutor.ConnectAndDeploy();
     Console.ReadLine();
 }
 public DealParameters()
 {
     services = new ServiceExecutor();
     BuildDealCommand = new RelayCommand(OnBuildCommand);
 }
Example #16
0
 public void ProcessRequest(HttpContext context)
 {
     ServiceExecutor.ProcessRequest(context, Info);
 }