Esempio n. 1
0
        public async void AuthenticatorLoginShouldNotLoginWhenServiceReturnsNull()
        {
            User user = null;

            LoginAttempt attempt = new LoginAttempt(user);

            LoginModel model = new LoginModel();

            model.Login    = "******";
            model.Password = "******";

            ILoginService        service = MockRepository.GenerateStub <ILoginService>();
            ISessionHelper       session = MockRepository.GenerateStub <ISessionHelper>();
            IFormsAuthentication forms   = MockRepository.GenerateStub <IFormsAuthentication>();

            service.Stub(s => s.Login(model.Login, model.Password)).Return(Task <LoginAttempt> .FromResult(attempt));

            Authenticator authenticator = new Authenticator(service, session, forms);
            bool          result        = await authenticator.Login(model);

            Assert.IsFalse(result);
            service.AssertWasCalled(s => s.Login(model.Login, model.Password));
            session.AssertWasNotCalled(s => s.User.Id);
            forms.AssertWasNotCalled(f => f.SetAuthCookie(Arg <string> .Is.Anything, Arg <bool> .Is.Anything));
        }
Esempio n. 2
0
        public async void AuthenticatorLoginShouldLoginWhenServiceReturnsUser()
        {
            User user = new User();

            user.Id   = 1;
            user.Name = "a";

            LoginAttempt attempt = new LoginAttempt(user);

            LoginModel model = new LoginModel();

            model.Login    = "******";
            model.Password = "******";

            ILoginService        service = MockRepository.GenerateStub <ILoginService>();
            ISessionHelper       session = MockRepository.GenerateStub <ISessionHelper>();
            IFormsAuthentication forms   = MockRepository.GenerateStub <IFormsAuthentication>();

            service.Stub(s => s.Login(model.Login, model.Password)).Return(Task <LoginAttempt> .FromResult(attempt));

            Authenticator authenticator = new Authenticator(service, session, forms);
            bool          result        = await authenticator.Login(model);

            Assert.IsTrue(result);
            service.AssertWasCalled(s => s.Login(model.Login, model.Password));
            Assert.AreEqual(session.User.Id, user.Id);
            forms.AssertWasCalled(f => f.SetAuthCookie(model.Login, true));
        }