Exemplo n.º 1
0
        public async Task PostUser_ValidInput_Failed()
        {
            _context.Functions.AddRange(new List <Function>()
            {
                new Function()
                {
                    Id        = "PostUser_ValidInput_Failed",
                    ParentId  = null,
                    Name      = "PostUser_ValidInput_Failed",
                    SortOrder = 1,
                    Url       = "/PostUser_ValidInput_Failed"
                }
            });
            await _context.SaveChangesAsync();

            var functionsController = new FunctionsController(_context);

            var result = await functionsController.PostFunction(new FunctionCreateRequest()
            {
                Id        = "PostUser_ValidInput_Failed",
                ParentId  = null,
                Name      = "PostUser_ValidInput_Failed",
                SortOrder = 5,
                Url       = "/PostUser_ValidInput_Failed"
            });

            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemplo n.º 2
0
        private static FunctionsController SetUpFunctionsController(string testFunctionName, bool isFileSystemReadOnly, bool functionCreatedSuccess = true)
        {
            var scriptPath             = Path.GetTempPath();
            var applicationHostOptions = new ScriptApplicationHostOptions
            {
                ScriptPath           = scriptPath,
                IsFileSystemReadOnly = isFileSystemReadOnly
            };

            var functionsMetadataMock = new Mock <FunctionMetadataResponse>();
            var functionsManagerMock  = new Mock <IWebFunctionsManager>();

            functionsManagerMock.Setup(p => p.CreateOrUpdate(It.IsAny <string>(), It.IsAny <FunctionMetadataResponse>(), It.IsAny <HttpRequest>()))
            .Callback <string, FunctionMetadataResponse, HttpRequest>((name, functionMetadata, request) =>
            {
                // verify the correct arguments were passed to the method
                Assert.Equal(testFunctionName, name);
                Assert.Equal(request.Method, "Put");
            })
            .Returns(Task.FromResult((functionCreatedSuccess, true, functionsMetadataMock.Object)));

            var mockRouter     = new Mock <IWebJobsRouter>();
            var optionsWrapper = new OptionsWrapper <ScriptApplicationHostOptions>(applicationHostOptions);
            var testController = new FunctionsController(functionsManagerMock.Object, mockRouter.Object, new LoggerFactory(), optionsWrapper);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Host   = new HostString("local");
            httpContext.Request.Method = "Put";
            httpContext.Request.Path   = $"/admin/functions/{testFunctionName}";
            testController.ControllerContext.HttpContext = httpContext;

            return(testController);
        }
Exemplo n.º 3
0
        public static void LoadFunctionUsers()
        {
            try
            {
                FunctionsController _FunctionsController = new FunctionsController();
                ArrayList           _arr = _FunctionsController.Function_GetAll();
                c_hashFunctionList.Clear();
                foreach (FunctionsInfo _FuncInfo in _arr)
                {
                    if (_FuncInfo.objname != null && _FuncInfo.objname != "")
                    {
                        c_hashFunctionList[_FuncInfo.objname] = _FuncInfo;
                    }
                }

                User_Controller _UserControler = new User_Controller();
                c_arrQuyen = _UserControler.Send_Users_Get_MenuItem(CommonData.c_Urser_Info.User_Name);
                c_hash_Quyen.Clear();
                foreach (User_FunctionsInfo item in c_arrQuyen)
                {
                    if (item.name != null)
                    {
                        c_hash_Quyen[item.name] = item;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
            }
        }
Exemplo n.º 4
0
        public ActionResult History()
        {
            var coo = new FunctionsController();
            var id  = coo.CookieID();

            return(View(db.Bills.Where(n => n.user_id == id.user_id).ToList()));
        }
Exemplo n.º 5
0
        public static void WriteOutput(FeatureContext featureContext)
        {
            ILogger <FunctionsController> logger = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <ILogger <FunctionsController> >();
            FunctionsController           functionsController = FunctionsBindings.GetFunctionsController(featureContext);

            logger.LogAllAndClear(functionsController.GetFunctionsOutput());
        }
Exemplo n.º 6
0
        public ActionResult PayMoMo(int?id)
        {
            var coo  = new FunctionsController();
            var idus = coo.CookieID();

            Pakage pakage = db.Pakages.Find(id);

            var money = pakage.pakage_coin * 1000;

            //request params need to request to MoMo system
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string partnerCode = "MOMO5RGX20191128";
            string accessKey   = "M8brj9K6E22vXoDB";
            string serectkey   = "nqQiVSgDMy809JoPF6OzP5OdBUB550Y4";
            string orderInfo   = "Nạp " + pakage.pakage_coin + " vào tài khoản " + idus.user_email;
            string returnUrl   = "https://localhost:44327/Pays/ReturnUrl";
            string notifyurl   = "https://localhost:44327/Pays/ReturnUrl";

            string amount    = money.ToString();
            string orderid   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //Before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;

            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, serectkey);
            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };

            string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
            JObject jmessage         = JObject.Parse(responseFromMomo);

            Session["idpake"] = id;

            return(Redirect(jmessage.GetValue("payUrl").ToString()));
        }
Exemplo n.º 7
0
        //Yêu thích code
        public JsonResult FaCode(int?id)
        {
            var co   = new FunctionsController();
            var idus = co.CookieID();

            Group group = new Group()
            {
                user_id     = idus.user_id,
                language_id = id,
                group_item  = Common.Common.ITEM_LANGUAGE_USER
            };

            db.Groups.Add(group);
            db.SaveChanges();

            var list = from item in db.Groups
                       where item.group_item == Common.Common.ITEM_LANGUAGE_USER && item.user_id == idus.user_id
                       select new
            {
                id   = item.language_id,
                idus = item.user_id,
                item = item.group_item,
                name = item.Language.language_name
            };

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 8
0
        public async Task PostFunction_ValidInput_Failed()
        {
            _context.Functions.Add(
                new Function
            {
                Id        = "PostUser_ValidInput_Failed",
                ParentId  = null,
                NameTemp  = "PostUser_ValidInput_Failed",
                SortOrder = 1,
                Url       = "/PostUser_ValidInput_Failed",
            }
                );
            await _context.SaveChangesAsync();

            _localizer    = MockLocalizer();
            _returnString = MockString();
            var controller = new FunctionsController(_context, _mockLogger.Object, _mapper, _localizer, _returnString);

            var result = await controller.PostFunction(new FunctionCreateRequest()
            {
                Id        = "PostUser_ValidInput_Failed",
                ParentId  = null,
                NameTemp  = "PostUser_ValidInput_Failed",
                SortOrder = 5,
                Url       = "/PostUser_ValidInput_Failed",
                Icon      = "test"
            });

            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemplo n.º 9
0
        public async Task PutFunction_ValidInput_Success()
        {
            _localizer    = MockLocalizer();
            _returnString = MockString();
            _context.Functions.AddRange(new List <Function>()
            {
                new Function()
                {
                    Id        = "PutUser_ValidInput_Success",
                    ParentId  = null,
                    NameTemp  = "PutUser_ValidInput_Success",
                    SortOrder = 1,
                    Url       = "/PutUser_ValidInput_Success"
                }
            });
            await _context.SaveChangesAsync();

            var controller = new FunctionsController(_context, _mockLogger.Object, _mapper, _localizer, _returnString);
            var result     = await controller.PutFunction("PutUser_ValidInput_Success", new FunctionCreateRequest()
            {
                ParentId  = null,
                NameTemp  = "PutUser_ValidInput_Success updated",
                SortOrder = 6,
                Url       = "/PutUser_ValidInput_Success"
            });

            Assert.IsType <NoContentResult>(result);
        }
Exemplo n.º 10
0
        public async Task GetById_HasData_ReturnSuccess()
        {
            _localizer = MockLocalizer();
            _context.Functions.AddRange(new List <Function>()
            {
                new Function()
                {
                    Id        = "GetById_HasData_ReturnSuccess",
                    ParentId  = null,
                    NameTemp  = "GetById_HasData_ReturnSuccess",
                    SortOrder = 1,
                    Url       = "/GetById_HasData_ReturnSuccess"
                }
            });
            await _context.SaveChangesAsync();

            var controller = new FunctionsController(_context, _mockLogger.Object, _mapper, _localizer, _returnString);
            var result     = await controller.GetById("GetById_HasData_ReturnSuccess");

            var okResult = result as OkObjectResult;

            Assert.NotNull(okResult);

            var userVm = okResult.Value as FunctionVm;

            Assert.Equal("GetById_HasData_ReturnSuccess", userVm.Id);
        }
Exemplo n.º 11
0
        public async Task GetUsersPaging_HasFilter_ReturnSuccess()
        {
            _localizer = MockLocalizer();
            _context.Functions.AddRange(new List <Function>()
            {
                new Function()
                {
                    Id        = "GetUsersPaging_HasFilter_ReturnSuccess",
                    ParentId  = null,
                    NameTemp  = "GetUsersPaging_HasFilter_ReturnSuccess",
                    SortOrder = 3,
                    Url       = "/GetUsersPaging_HasFilter_ReturnSuccess"
                }
            });
            await _context.SaveChangesAsync();

            var controller = new FunctionsController(_context, _mockLogger.Object, _mapper, _localizer, _returnString);
            var result     = await controller.GetFunctionsPaging("GetUsersPaging_HasFilter_ReturnSuccess", 1, 2);

            var okResult = result as OkObjectResult;
            var UserVms  = okResult.Value as Pagination <FunctionVm>;

            Assert.Equal(1, UserVms.TotalRecords);
            Assert.Single(UserVms.Items);
        }
Exemplo n.º 12
0
        public async Task Invoke_CallsFunction()
        {
            var    testFunctions        = new Collection <FunctionDescriptor>();
            string testFunctionName     = "TestFunction";
            string triggerParameterName = "testTrigger";
            string testInput            = Guid.NewGuid().ToString();
            bool   functionInvoked      = false;

            var scriptHostMock = new Mock <IScriptJobHost>();

            scriptHostMock.Setup(p => p.CallAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, object> >(), CancellationToken.None))
            .Callback <string, IDictionary <string, object>, CancellationToken>((name, args, token) =>
            {
                // verify the correct arguments were passed to the invoke
                Assert.Equal(testFunctionName, name);
                Assert.Equal(1, args.Count);
                Assert.Equal(testInput, (string)args[triggerParameterName]);

                functionInvoked = true;
            })
            .Returns(Task.CompletedTask);

            scriptHostMock.Setup(p => p.Functions).Returns(testFunctions);

            // Add a few parameters, with the trigger parameter last
            // to verify parameter order handling
            Collection <ParameterDescriptor> parameters = new Collection <ParameterDescriptor>
            {
                new ParameterDescriptor("context", typeof(ExecutionContext)),
                new ParameterDescriptor("log", typeof(TraceWriter)),
                new ParameterDescriptor(triggerParameterName, typeof(string))
                {
                    IsTrigger = true
                }
            };

            testFunctions.Add(new FunctionDescriptor(testFunctionName, null, null, parameters, null, null, null));

            FunctionInvocation invocation = new FunctionInvocation
            {
                Input = testInput
            };

            var scriptPath             = Path.GetTempPath();
            var applicationHostOptions = new ScriptApplicationHostOptions();

            applicationHostOptions.ScriptPath = scriptPath;
            var           optionsWrapper       = new OptionsWrapper <ScriptApplicationHostOptions>(applicationHostOptions);
            var           functionsManagerMock = new Mock <IWebFunctionsManager>();
            var           mockRouter           = new Mock <IWebJobsRouter>();
            var           testController       = new FunctionsController(functionsManagerMock.Object, mockRouter.Object, new LoggerFactory(), optionsWrapper);
            IActionResult response             = testController.Invoke(testFunctionName, invocation, scriptHostMock.Object);

            Assert.IsType <AcceptedResult>(response);

            // The call is fire-and-forget, so watch for functionInvoked to be set.
            await TestHelpers.Await(() => functionInvoked, timeout : 3000, pollingInterval : 100);

            Assert.True(functionInvoked);
        }
Exemplo n.º 13
0
        public void UpdateCustomer(BookRepair_CustomerModel model)
        {
            // method for customer update
            var user  = new UserService(_dataContext);
            var store = new StoreService(_dataContext);
            var cust  = new CustomerService(_dataContext);
            var func  = new FunctionsController();

            model.Forename = func.UppercaseFirst(model.Forename);
            model.Surname  = func.UppercaseFirst(model.Surname);

            // Save in database
            var customerId = _reporsitory.UpdateCustomer(model, cust.GetCustomerIdFromSession(), store.GetStoreId(), user.GetUserId());

            // Fill class by info
            cust.SetGeneralCustomerInfoIntoSession(new Customer_InfoModel
            {
                Address1      = model.HouseNumber + " " + model.Addr1 + "," + model.Organization,
                Address2      = model.Addr2,
                Address3      = model.Addr3,
                CustomerName  = model.Forename + " " + model.Surname,
                PostCode      = model.Postcode,
                CustomerId    = customerId,
                ContactMethod = model.ContactMethod
            });
            // Update session holder
            //_bookStateHolder.UpdateFrom(_bookState);
        }
Exemplo n.º 14
0
        public async Task DeleteUser_ValidInput_Failed()
        {
            var functionsController = new FunctionsController(_context);
            var result = await functionsController.DeleteFunction("DeleteUser_ValidInput_Failed");

            Assert.IsType <NotFoundObjectResult>(result);
        }
        //Danh sách code
        public JsonResult Codes()
        {
            var           co    = new FunctionsController();
            var           id    = co.CookieID();
            List <Code>   codes = db.Codes.Where(n => n.user_id == id.user_id).ToList();
            List <jCodes> list  = codes.Select(n => new jCodes
            {
                active     = (int)n.code_active,
                code       = n.code_code,
                coin       = (int)n.code_coin,
                datecreate = n.code_datecreate.ToString(),
                dateupdate = n.code_dateupdate.ToString(),
                del        = n.code_del,
                des        = n.code_des,
                disk       = (int)(n.code_disk == null ? 0 : n.code_disk),
                id         = n.code_id,
                id_cate    = (int)n.category_id,
                id_us      = (int)n.user_id,
                info       = n.code_info,
                linkdemo   = n.code_linkdemo,
                linkdown   = n.code_linkdown,
                option     = n.code_option,
                pass       = n.code_pass,
                setting    = n.code_setting,
                title      = n.code_title,
                view       = (int)n.code_view,
                viewdown   = (int)n.code_viewdown,
                img        = n.code_img,
                cate_name  = n.Category.category_name
            }).ToList();

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 16
0
        public async Task GetById_HasData_ReturnSuccess()
        {
            _context.Functions.AddRange(new List <Function>()
            {
                new Function()
                {
                    Id        = "GetById_HasData_ReturnSuccess",
                    ParentId  = null,
                    Name      = "GetById_HasData_ReturnSuccess",
                    SortOrder = 1,
                    Url       = "/GetById_HasData_ReturnSuccess"
                }
            });
            await _context.SaveChangesAsync();

            var functionsController = new FunctionsController(_context);
            var result = await functionsController.GetById("GetById_HasData_ReturnSuccess");

            var okResult = result as OkObjectResult;

            Assert.NotNull(okResult);

            var userVm = okResult.Value as FunctionVm;

            Assert.Equal("GetById_HasData_ReturnSuccess", userVm.Id);
        }
Exemplo n.º 17
0
        public async Task PutUser_ValidInput_Success()
        {
            _context.Functions.AddRange(new List <Function>()
            {
                new Function()
                {
                    Id        = "PutUser_ValidInput_Success",
                    ParentId  = null,
                    Name      = "PutUser_ValidInput_Success",
                    SortOrder = 1,
                    Url       = "/PutUser_ValidInput_Success"
                }
            });
            await _context.SaveChangesAsync();

            var functionsController = new FunctionsController(_context);
            var result = await functionsController.PutFunction("PutUser_ValidInput_Success", new FunctionCreateRequest()
            {
                ParentId  = null,
                Name      = "PutUser_ValidInput_Success updated",
                SortOrder = 6,
                Url       = "/PutUser_ValidInput_Success"
            });

            Assert.IsType <NoContentResult>(result);
        }
Exemplo n.º 18
0
        public ActionResult Create(Code codes, string[] language, string[] tags, HttpPostedFileBase img)
        {
            var coo  = new FunctionsController();
            var id   = coo.Cookie();
            var idus = coo.CookieID();

            if (id == null)
            {
                return(Redirect("/Users/Login"));
            }
            else
            {
                //var tag = "";
                //foreach (var item in tags)
                //{
                //    tag += item + ";";
                //}
                //codes.code_tag = tag;
                codes.user_id  = idus.user_id;
                codes.code_img = images.UpLoadImages(img, null, "Codes");


                History history = new History()
                {
                    user_id        = idus.user_id,
                    his_datecreate = DateTime.Now,
                    his_content    = idus.user_name + " đã thêm code " + codes.code_title + " thành công!"
                };
                db.Historys.Add(history);

                codesDAO.Create(codes, language);

                return(RedirectToAction("MyCodes"));
            }
        }
        //Tra ve nguoi dung
        public JsonResult Users()
        {
            var           co    = new FunctionsController();
            var           id    = co.CookieID();
            List <Users>  users = db.Users.Where(n => n.user_id == id.user_id).ToList();
            List <jUsers> list  = users.Select(n => new jUsers
            {
                active       = n.user_active,
                bin          = n.user_bin,
                code         = n.user_code,
                coin         = n.user_coin,
                datelogin    = n.user_datelogin.ToString(),
                datecreate   = n.user_datecreate.ToString(),
                email        = n.user_email,
                id           = n.user_id,
                img          = n.user_img,
                name         = n.user_name,
                option       = n.user_option,
                pass         = n.user_pass,
                token        = n.user_token,
                update       = n.user_update.ToString(),
                sex          = n.user_sex,
                phone        = n.user_phone,
                favorite     = n.user_favorite,
                codefavorite = n.user_codefavorite,
                dateofbirth  = n.user_dateofbirth.Value.ToShortDateString()
            }).ToList();

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 20
0
        //Bình luận
        public JsonResult Comment(string content, int?id)
        {
            var coo  = new FunctionsController();
            var idus = coo.CookieID();

            Comment comment = new Comment
            {
                code_id            = id,
                comment_content    = content,
                comment_datecreate = DateTime.Now,
                user_id            = idus.user_id
            };

            db.Comments.Add(comment);
            db.SaveChanges();


            var list = from item in db.Comments
                       where item.code_id == id
                       orderby item.comment_dateupdate descending
                       select new
            {
                id      = item.comment_id,
                idcode  = item.code_id,
                idus    = item.user_id,
                date    = item.comment_datecreate.ToString(),
                update  = item.comment_dateupdate,
                content = item.comment_content,
                nameid  = item.User.user_name,
                imgid   = item.User.user_img
            };

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 21
0
        public static void WriteOutput(FeatureContext featureContext)
        {
            ILogger             logger = featureContext.Get <ILogger>();
            FunctionsController functionsController = FunctionsBindings.GetFunctionsController(featureContext);

            logger.LogAllAndClear(functionsController.GetFunctionsOutput());
        }
        public void Setup()
        {
            _request = _fixture.Create <ApplicationApprovedRequest>();

            _mediator = new Mock <IMediator>();

            _controller = new FunctionsController(_mediator.Object, Mock.Of <Microsoft.Extensions.Logging.ILogger <FunctionsController> >());
        }
Exemplo n.º 23
0
        public void Setup()
        {
            _mediator = new Mock <IMediator>();

            _request = _fixture.Create <SendEmailsRequest>();

            _controller = new FunctionsController(_mediator.Object, Mock.Of <ILogger <FunctionsController> >());
        }
        public void Setup()
        {
            _mediator = new Mock <IMediator>();

            _request = _fixture.Create <ApplicationWithdrawnAfterAcceptanceRequest>();

            _controller = new FunctionsController(_mediator.Object, Mock.Of <ILogger <FunctionsController> >());
        }
Exemplo n.º 25
0
        public async Task DeleteUser_ValidInput_Failed()
        {
            _localizer    = MockLocalizer();
            _returnString = MockString();
            var controller = new FunctionsController(_context, _mockLogger.Object, _mapper, _localizer, _returnString);
            var result     = await controller.DeleteFunction("DeleteUser_ValidInput_Failed");

            Assert.IsType <NotFoundObjectResult>(result);
        }
Exemplo n.º 26
0
 public static void StopManagementApi(FeatureContext featureContext)
 {
     featureContext.RunAndStoreExceptions(
         () =>
     {
         FunctionsController functionsController = FunctionsBindings.GetFunctionsController(featureContext);
         functionsController.TeardownFunctions();
     });
 }
        //Quản lý rút tiền
        public JsonResult HistoryTakePrice()
        {
            var coo     = new FunctionsController();
            var idus    = coo.CookieID();
            var history = from tp in db.TakePrices
                          where tp.user_id == idus.user_id
                          select new { id = tp.tp_id, user_id = tp.user_id, tp_coin = tp.tp_coin, tp_note = tp.tp_note, tp_active = tp.tp_active, tp_accountnumber = tp.tp_accountnumber, tp_customer = tp.tp_customer };

            return(Json(history, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Retrieves the current functions controller from the supplied context.
        /// </summary>
        /// <param name="context">The SpecFlow context to retrieve from.</param>
        /// <returns>The FunctionsController.</returns>
        /// <remarks>
        /// If the controller hasn't already been added to the context, this method will create
        /// and add a new instance.
        /// </remarks>
        public static FunctionsController GetFunctionsController(SpecFlowContext context)
        {
            if (!context.TryGetValue(out FunctionsController controller))
            {
                controller = new FunctionsController();
                context.Set(controller);
            }

            return(controller);
        }
Exemplo n.º 29
0
        public JsonResult ChangeOption()
        {
            var co   = new FunctionsController();
            var idus = co.CookieID();

            User us = db.Users.Find(idus.user_id);

            us.user_option = !us.user_option;
            db.SaveChanges();
            return(Json(""));
        }
Exemplo n.º 30
0
        //Danh sách yêu thích theo người dùng và code
        public JsonResult JsonFavourite(int?idcode)
        {
            var cookie = new FunctionsController();
            var idus   = cookie.CookieID();
            var fa     = db.Groups.Where(n => n.group_item == Common.Common.ITEM_CODE_USER && n.user_id == idus.user_id && n.code_id == idcode).OrderByDescending(n => n.group_datecreate).Select(n => new
            {
                id = n.group_id
            }).ToList();

            return(Json(fa, JsonRequestBehavior.AllowGet));
        }