Esempio n. 1
0
        public void CreatePostRouting(string currentUserType, string resultViewName, string resultControllerName, bool fileExist)
        {
            //------------Preparation

            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.NameIdentifier,
                          // You can assign current user to ApplicationUser.id, which is refering to dessired UserType
                          context.ApplicationUser.First(ap => ap.Name == currentUserType).Id)
            };
            var identity         = new ClaimsIdentity(claims, "Test");
            var claimsPrinicipal = new ClaimsPrincipal(identity);
            var httpContextMock  = new Mock <HttpContext>();

            httpContextMock.Setup(hc => hc.User).Returns(claimsPrinicipal);
            var paperFileMock = new Mock <IFormFile>();
            var paperMock     = new PaperPaperKeyworsViewModel
            {
                Abstract      = "test",
                Authors       = "test",
                LanguageId    = 47,
                OrgName       = "test",
                PaperKeywords = "test",
                TitleENG      = "test",
                TitleORG      = "test"
            };

            // Transfer HttpContext to new PaperController
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContextMock.Object
            };
            var controller = new PapersController(context, userManager)
            {
                ControllerContext = controllerContext
            };

            //------------Action
            var result = controller.Create(
                paperMock,
                fileExist ? paperFileMock.Object : null)
                         .Result;

            //------------Assertion
            if (currentUserType != "Author" || fileExist)
            {
                Assert.AreEqual(resultControllerName, ((RedirectToActionResult)result).ControllerName);
                Assert.AreEqual(resultViewName, ((RedirectToActionResult)result).ActionName);
                return;
            }
            Assert.AreEqual(resultViewName, ((ViewResult)result).ViewName);
        }
Esempio n. 2
0
        public void DatailRouting(string currentUserType, string resultViewName, int?id)
        {
            //------------Preparation

            // HttpContext mockup -> ApplictionUser with Name = "Author"
            // assigned as current user in HttpContext
            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.NameIdentifier,
                          // You can assign current user to ApplicationUser.id, which is refering to dessired UserType
                          context.ApplicationUser.First(ap => ap.Name == currentUserType).Id)
            };
            var identity         = new ClaimsIdentity(claims, "Test");
            var claimsPrinicipal = new ClaimsPrincipal(identity);
            var httpContextMock  = new Mock <HttpContext>();

            httpContextMock.Setup(hc => hc.User).Returns(claimsPrinicipal);

            // Transfer HttpContext to new PaperController
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContextMock.Object
            };
            var controller = new PapersController(context, userManager)
            {
                ControllerContext = controllerContext
            };

            //------------Action
            var result = controller.Details(id).Result;

            //------------Assertion
            if (currentUserType == "Author2" || currentUserType == "Reviewer2")
            {
                Assert.AreEqual(resultViewName, ((RedirectToActionResult)result).ActionName);
                return;
            }
            Assert.AreEqual(resultViewName, ((ViewResult)result).ViewName);
        }