public static ControllerContext Setup(string buttonToAdd)
        {
            var user = MockedUser.Setup();

            var controllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };

            if (!string.IsNullOrEmpty(buttonToAdd))
            {
                var clarificationFileName = "file.pdf";
                var file = new FormFile(new MemoryStream(), 0, 0, clarificationFileName, clarificationFileName);
                var formFileCollection = new FormFileCollection {
                    file
                };
                var dictionary = new Dictionary <string, StringValues>();
                dictionary.Add(buttonToAdd, clarificationFileName);
                controllerContext.HttpContext.Request.Form = new FormCollection(dictionary, formFileCollection);
            }
            else
            {
                controllerContext.HttpContext.Request.Form = new FormCollection(new Dictionary <string, StringValues>());
            }

            return(controllerContext);
        }
Esempio n. 2
0
        public static Mock <IHttpContextAccessor> Setup()
        {
            var user = MockedUser.Setup();

            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var context = new DefaultHttpContext {
                User = user
            };

            mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);
            return(mockHttpContextAccessor);
        }