Ejemplo n.º 1
0
        public void CreateGetUpdateDelete()
        {
            IQuoteServices qs = ServicesFactory.GetQuoteServices();
            IUserServices  us = ServicesFactory.GetUserServices();

            var user = us.GetUserByEmail("*****@*****.**");

            if (user == null)
            {
                us.Register("*****@*****.**", "123456", "Test User");
                user = us.GetUserByEmail("*****@*****.**");
            }

            //Create quote
            var quote = new QuoteEntity()
            {
                Text = "Test", UserId = user.Id
            };
            var quoteId = qs.CreateQuote(quote);

            Assert.AreNotEqual(quoteId, 0);

            //Get quote
            var newQuote = qs.GetQuoteById(quoteId);

            Assert.IsNotNull(newQuote);

            Assert.AreEqual(newQuote.Text, quote.Text);

            Assert.AreEqual(newQuote.UserId, quote.UserId);

            //Update quote
            newQuote.Text = "Test1";

            qs.UpdateQuote(newQuote.Id, newQuote);

            newQuote = qs.GetQuoteById(quoteId);

            Assert.IsNotNull(newQuote);

            Assert.AreEqual(newQuote.Text, "Test1");

            Assert.AreEqual(newQuote.UserId, quote.UserId);

            //Delete quote
            qs.DeleteQuote(newQuote.Id);

            newQuote = qs.GetQuoteById(quoteId);

            Assert.IsNull(newQuote);
        }
Ejemplo n.º 2
0
        public void RegisterGet()
        {
            IUserServices us = ServicesFactory.GetUserServices();

            var user = us.GetUserByEmail("*****@*****.**");

            if (user == null)
            {
                us.Register("*****@*****.**", "123456", "Test User");
                user = us.GetUserByEmail("*****@*****.**");
            }

            Assert.IsNotNull(user);
        }
Ejemplo n.º 3
0
        public void Authenticate()
        {
            IUserServices us = ServicesFactory.GetUserServices();

            var user = us.GetUserByEmail("*****@*****.**");

            if (user == null)
            {
                us.Register("*****@*****.**", "123456", "Test User");
                user = us.GetUserByEmail("*****@*****.**");
            }

            Assert.IsNotNull(user);

            int userId = us.Authenticate(user.Email, user.Password);

            Assert.AreNotEqual(userId, 0);
        }
        /// <summary>
        /// Protected overriden method for authorizing user
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="actionContext"></param>
        /// <returns></returns>
        protected override bool OnAuthorizeUser(string username, string password, HttpActionContext actionContext)
        {
            var provider = ServicesFactory.GetUserServices();

            if (provider != null)
            {
                var userId = provider.Authenticate(username, password);
                if (userId > 0)
                {
                    var basicAuthenticationIdentity = Thread.CurrentPrincipal.Identity as BasicAuthenticationIdentity;
                    if (basicAuthenticationIdentity != null)
                    {
                        basicAuthenticationIdentity.Id = userId;
                    }
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Public constructor to initialize product service instance
 /// </summary>
 public AuthenticateController()
 {
     _tokenServices = ServicesFactory.GetTokenServices();
     _userServices  = ServicesFactory.GetUserServices();
 }
Ejemplo n.º 6
0
 public UserController()
 {
     _userServices = ServicesFactory.GetUserServices();
 }