コード例 #1
0
        public void Login_fails_with_empty_inputs()
        {
            var store = new Mock<IUserRegistrationStore>();
            var svc = new UserRegistrationService(store.Object);

            Assert.Throws<ArgumentNullException>(() => svc.Login("*****@*****.**", null));
            Assert.Throws<ArgumentNullException>(() => svc.Login(null, "password"));
        }
コード例 #2
0
        public void End_to_end_failed_login()
        {
            var store = new UserRegistrationStore();
            var svc = new UserRegistrationService(store);

            svc.Register("*****@*****.**", "password");

            Assert.Equal(Guid.Empty, svc.Login("*****@*****.**", "wrong"));
            Assert.Equal(Guid.Empty, svc.Login("*****@*****.**", "password"));
        }
コード例 #3
0
        public void Service_can_verify_credentials()
        {
            var reg = new UserRegistration("*****@*****.**", "password");
            var store = new Mock<IUserRegistrationStore>();
            store.Setup(x => x.Load("*****@*****.**")).Returns(reg);
            var svc = new UserRegistrationService(store.Object);

            var result = svc.Login("*****@*****.**", "password");

            store.VerifyAll();
            Assert.Equal(reg.Id, result);
        }
コード例 #4
0
        public void Login_fails_with_wrong_password()
        {
            var reg = new UserRegistration("*****@*****.**", "password");
            var store = new Mock<IUserRegistrationStore>();
            store.Setup(x => x.Load("*****@*****.**")).Returns(reg);
            var svc = new UserRegistrationService(store.Object);

            var result = svc.Login("*****@*****.**", "wrong");

            store.VerifyAll();
            Assert.NotEqual(reg.Id, result);
            Assert.Equal(new Guid(), result);
        }
コード例 #5
0
        public void End_to_end_success()
        {
            var store = new UserRegistrationStore();
            var svc = new UserRegistrationService(store);

            svc.Register("*****@*****.**", "password");

            var id = svc.Login("*****@*****.**", "password");
            Assert.NotEqual(Guid.Empty, id);

            var user = store.Users.FirstOrDefault(x => x.Id == id);
            Assert.Equal("*****@*****.**", user.Email);
        }