예제 #1
0
 public void IndexHasRouteAttributeWithRoute()
 {
     var sut = new MeApiController();
     var attribute = sut.GetAttributesOn(x => x.Index()).OfType<RouteAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "api/me");
 }
예제 #2
0
        public void IndexReturnsCorrectCookieString()
        {
            var sut = new MeApiController();
            var mockedHttpRequest = sut.GetMockHttpRequest();

            sut.Index();

            mockedHttpRequest.Verify(x => x.Cookies[".AspNet.ApplicationCookie"], Times.Once());
        }
        public void ControllerHasRouteAttributeWithRoute()
        {
            var mediator = new Mock<IMediator>();
            var userManager = MockHelper.CreateUserManagerMock();
            var signInManager = MockHelper.CreateSignInManagerMock(userManager);
            var sut = new MeApiController(userManager.Object, signInManager.Object, mediator.Object);

            var attribute = sut.GetAttributes().OfType<RouteAttribute>().SingleOrDefault();
            Assert.NotNull(attribute);
            Assert.Equal(attribute.Template, "api/me");
        }
        public void LoginMethodHasHttpPostAtttribute()
        {
            var mediator = new Mock<IMediator>();
            var userManager = MockHelper.CreateUserManagerMock();
            var signInManager = MockHelper.CreateSignInManagerMock(userManager);
            var sut = new MeApiController(userManager.Object, signInManager.Object, mediator.Object);

            var attribute =
                sut.GetAttributesOn(x => x.Login(new LoginViewModel())).OfType<HttpPostAttribute>().SingleOrDefault();
            Assert.NotNull(attribute);
        }
        public async Task LoginReturnsCorrectCookieString()
        {
            var model = new LoginViewModel()
            {
                Email = "*****@*****.**",
                Password = "******"
            };

            var mediator = new Mock<IMediator>();
            var userManager = MockHelper.CreateUserManagerMock();
            var signInManager = MockHelper.CreateSignInManagerMock(userManager);
            signInManager.Setup(
                    x =>
                        x.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(),
                            It.IsAny<bool>()))
                .ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Success);

            var sut = new MeApiController(userManager.Object, signInManager.Object, mediator.Object);
            var mockedHttpRequest = sut.GetMockHttpRequest();

            await sut.Login(model);

            mockedHttpRequest.Verify(x => x.Cookies[".AspNet.ApplicationCookie"], Times.Once());
        }
예제 #6
0
 public void ControllerHasRouteAtttributeWithTheCorrectRoute()
 {
     var sut = new MeApiController();
     var attribute = sut.GetAttributes().OfType<AuthorizeAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
 }