public void Personalization_Repository_Should_Save_User_Events()
 {
     int repoCount = _personalizationRepository.GetEvents().Count();
     UserEvent ue = new UserEvent("testuser", "127.0.0.1", 1, 1, System.Guid.NewGuid(), UserBehavior.LoggingIn);
     _personalizationRepository.Save(ue);
     Assert.AreEqual(repoCount + 1, _personalizationRepository.GetEvents().Count());
 }
        public void Personalization_UserEvent_Should_Track_UserName_IP_Category_ProductID_OrderID_Date_Behavior()
        {
            System.Guid orderID = System.Guid.NewGuid();
            UserEvent ue = new UserEvent("testuser", 
                "127.0.0.1", 1, 1, orderID, UserBehavior.LoggingIn);

            Assert.AreEqual(ue.Behavior, UserBehavior.LoggingIn);
            Assert.AreEqual(ue.IP, "127.0.0.1");
            Assert.AreEqual(ue.CategoryID, 1);
            Assert.AreEqual(ue.OrderID, orderID);
            Assert.AreEqual(ue.ProductID, 1);
        
        }
        public TestPersonalizationRepository()
        {

            eventList = new List<UserEvent>();
            ICatalogRepository catalogRepository = new TestCatalogRepository();
            
            //looking at products
            for (int i = 1; i < 50; i++)
            {

                for (int x = 10; x <= 20; x++)
                {
                    Category c = catalogRepository
                        .GetCategories().WithCategoryID(x).Take(1).SingleOrDefault();
                    
                    //take the first
                    Product p = c.Products[0];

                    UserEvent ue = new UserEvent("testuser", "127.0.0.1", c.ID, p.ID, System.Guid.Empty, 
                        UserBehavior.ViewProduct);
                    
                    eventList.Add(ue);

                    //skew twice for 12
                    c = catalogRepository
                        .GetCategories().WithCategoryID(12).Take(1).SingleOrDefault();

                    p = c.Products[0];

                    ue = new UserEvent("testuser", "127.0.0.1", c.ID, p.ID, System.Guid.Empty,
                        UserBehavior.ViewProduct);
                    
                    eventList.Add(ue);
                }


            }

            //view some products
            for (int i = 1; i <= 5; i++)
            {

                Product p = catalogRepository.GetProducts().WithProductID(i).SingleOrDefault();
                UserEvent ue = new UserEvent("testuser", "127.0.0.1", null, p.ID, System.Guid.Empty,
                    UserBehavior.ViewProduct);
                
                eventList.Add(ue);

            }

        }
Beispiel #4
0
        public void Save(Commerce.Data.UserEvent userEvent)
        {
            using (DB db = new DB())
            {
                //make sure there's a user
                int userCount = (from u in db.Users
                                 where u.UserName == userEvent.UserName
                                 select u).Count();

                //if not, need to add one
                if (userCount == 0)
                {
                    Commerce.Data.SqlRepository.User newUser = new Commerce.Data.SqlRepository.User();
                    newUser.UserName   = userEvent.UserName;
                    newUser.CreatedOn  = DateTime.Now;
                    newUser.ModifiedOn = DateTime.Now;
                    db.Users.InsertOnSubmit(newUser);
                }

                //there is no updating of user events - it's always an insert
                Commerce.Data.SqlRepository.UserEvent newEvent = new Commerce.Data.SqlRepository.UserEvent();

                //some left/right
                newEvent.IP         = userEvent.IP;
                newEvent.UserName   = userEvent.UserName;
                newEvent.ProductID  = userEvent.ProductID;
                newEvent.CategoryID = userEvent.CategoryID;
                newEvent.EventDate  = DateTime.Now;
                if (userEvent.OrderID != Guid.Empty)
                {
                    newEvent.OrderID = userEvent.OrderID;
                }
                else
                {
                    newEvent.OrderID = null;
                }
                newEvent.UserBehaviorID = (int)userEvent.Behavior;

                db.UserEvents.InsertOnSubmit(newEvent);
                db.SubmitChanges();
            }
        }
        public void Personalization_Service_Should_Save_Valid_UserEvent()
        {
            UserEvent ue = new UserEvent("testuser", "127.0.0.1", 1, 1, System.Guid.NewGuid(), UserBehavior.LoggingIn);
            int eventCount = _personalizationRepository.GetEvents().Count();
            _personalizationService.SaveUserEvent(ue);
            Assert.AreEqual(eventCount + 1, _personalizationRepository.GetEvents().Count());

        }
 public void Personalization_Service_Should_Throw_With_No_IP_On_Save()
 {
     UserEvent ue = new UserEvent("testuser", "", 1, 1, System.Guid.NewGuid(), UserBehavior.LoggingIn);
     bool threw = false;
     try
     {
         _personalizationService.SaveUserEvent(ue);
     }
     catch (System.InvalidOperationException x)
     {
         threw = true;
     }
     Assert.IsTrue(threw);
 }
 public void Save(UserEvent userEvent)
 {
     eventList.Add(userEvent);
 }
 public void SaveProductView(string userName, string IP, Product product) {
     //track this request
     UserEvent ue = new UserEvent(userName, IP,
         null,product.ID, System.Guid.Empty, UserBehavior.ViewProduct);
     _pRepo.Save(ue);
 }
        public void SaveCategoryView(string userName, string IP, Category category)
        {
            //track this request
            UserEvent ue = new UserEvent(userName, IP,
                category.ID, null, System.Guid.Empty, UserBehavior.ViewCategory);
            _pRepo.Save(ue);

        }
        /// <summary>
        /// Save's the user event to the repository
        /// </summary>
        /// <param name="userEvent"></param>
        public void SaveUserEvent(UserEvent userEvent)
        {
            //make sure there's a username
            if (String.IsNullOrEmpty(userEvent.UserName))
                throw new InvalidOperationException("Need a username to track this event");

            //and an IP
            if(String.IsNullOrEmpty(userEvent.IP))
                throw new InvalidOperationException("IP Address must be set");

            _pRepo.Save(userEvent);

        }