public void testGetPreferencesForNonExistingUser()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10);

            // Exception is expected since such user does not exist
            instance.GetPreferencesFromUser(1);
        }
        public void testReleaseValidUser()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10);
            long?takenUserID = instance.TakeAvailableUser();

            Assert.True(instance.ReleaseUser(takenUserID.Value));
        }
        public void testGetUserIDs()
        {
            IPreferenceArray prefs        = new GenericUserPreferenceArray(1);
            long             sampleUserID = 1;

            prefs.SetUserID(0, sampleUserID);
            long sampleItemID = 11;

            prefs.SetItemID(0, sampleItemID);

            FastByIDMap <IPreferenceArray> delegatePreferences = new FastByIDMap <IPreferenceArray>();

            delegatePreferences.Put(sampleUserID, prefs);

            PlusAnonymousConcurrentUserDataModel instance = getTestableWithDelegateData(10, delegatePreferences);

            long anonymousUserID = instance.TakeAvailableUser().Value;

            IPreferenceArray tempPrefs = new GenericUserPreferenceArray(1);

            tempPrefs.SetUserID(0, anonymousUserID);
            tempPrefs.SetItemID(0, 22);

            instance.SetTempPrefs(tempPrefs, anonymousUserID);

            var userIDs = instance.GetUserIDs();

            userIDs.MoveNext();

            Assert.AreEqual(sampleUserID, userIDs.Current);
            Assert.False(userIDs.MoveNext());
        }
        public void testSetMultipleTempPreferences()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10);

            long anonymousUserID1 = instance.TakeAvailableUser().Value;
            long anonymousUserID2 = instance.TakeAvailableUser().Value;

            IPreferenceArray tempPrefs1 = new GenericUserPreferenceArray(1);

            tempPrefs1.SetUserID(0, anonymousUserID1);
            tempPrefs1.SetItemID(0, 1);

            IPreferenceArray tempPrefs2 = new GenericUserPreferenceArray(2);

            tempPrefs2.SetUserID(0, anonymousUserID2);
            tempPrefs2.SetItemID(0, 2);
            tempPrefs2.SetUserID(1, anonymousUserID2);
            tempPrefs2.SetItemID(1, 3);

            instance.SetTempPrefs(tempPrefs1, anonymousUserID1);
            instance.SetTempPrefs(tempPrefs2, anonymousUserID2);

            Assert.AreEqual(tempPrefs1, instance.GetPreferencesFromUser(anonymousUserID1));
            Assert.AreEqual(tempPrefs2, instance.GetPreferencesFromUser(anonymousUserID2));
        }
        public void testTakeFirstAvailableUser()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10);
            long expResult = PlusAnonymousUserDataModel.TEMP_USER_ID;
            long?result    = instance.TakeAvailableUser();

            Assert.AreEqual(expResult, result);
        }
        public void testReleasePreviouslyReleasedUser()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10);
            long takenUserID = instance.TakeAvailableUser().Value;

            Assert.True(instance.ReleaseUser(takenUserID));
            Assert.False(instance.ReleaseUser(takenUserID));
        }
        public void testTakeUnavailableUser()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(1);

            // Take the only available user
            instance.TakeAvailableUser();
            // There are no more users available
            Assert.IsNull(instance.TakeAvailableUser());
        }
        public void testSetAndGetTempPreferences()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10);
            long             anonymousUserID = instance.TakeAvailableUser().Value;
            IPreferenceArray tempPrefs       = new GenericUserPreferenceArray(1);

            tempPrefs.SetUserID(0, anonymousUserID);
            tempPrefs.SetItemID(0, 1);
            instance.SetTempPrefs(tempPrefs, anonymousUserID);
            Assert.AreEqual(tempPrefs, instance.GetPreferencesFromUser(anonymousUserID));
            instance.ReleaseUser(anonymousUserID);
        }
        public void testGetNumAnonymousUsers()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10);

            long anonymousUserID1 = instance.TakeAvailableUser().Value;

            IPreferenceArray tempPrefs1 = new GenericUserPreferenceArray(1);

            tempPrefs1.SetUserID(0, anonymousUserID1);
            tempPrefs1.SetItemID(0, 1);

            instance.SetTempPrefs(tempPrefs1, anonymousUserID1);

            // Anonymous users should not be included into the universe.
            Assert.AreEqual(0, instance.GetNumUsers());
        }
        public void testGetPreferencesForNonAnonymousUser()
        {
            IPreferenceArray prefs        = new GenericUserPreferenceArray(1);
            long             sampleUserID = 1;

            prefs.SetUserID(0, sampleUserID);
            long sampleItemID = 11;

            prefs.SetItemID(0, sampleItemID);

            FastByIDMap <IPreferenceArray> delegatePreferences = new FastByIDMap <IPreferenceArray>();

            delegatePreferences.Put(sampleUserID, prefs);

            PlusAnonymousConcurrentUserDataModel instance = getTestableWithDelegateData(10, delegatePreferences);

            Assert.AreEqual(prefs, instance.GetPreferencesFromUser(sampleUserID));
        }
        public void testGetPreferenceValue()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10);

            long anonymousUserID = instance.TakeAvailableUser().Value;

            IPreferenceArray tempPrefs = new GenericUserPreferenceArray(1);

            tempPrefs.SetUserID(0, anonymousUserID);
            long sampleItemID = 1;

            tempPrefs.SetItemID(0, sampleItemID);
            tempPrefs.SetValue(0, float.MaxValue);

            instance.SetTempPrefs(tempPrefs, anonymousUserID);

            Assert.AreEqual(float.MaxValue, instance.GetPreferenceValue(anonymousUserID, sampleItemID), EPSILON);
        }
        public void testGetPreferencesForItem()
        {
            IPreferenceArray prefs        = new GenericUserPreferenceArray(2);
            long             sampleUserID = 4;

            prefs.SetUserID(0, sampleUserID);
            long sampleItemID = 11;

            prefs.SetItemID(0, sampleItemID);
            prefs.SetUserID(1, sampleUserID);
            long sampleItemID2 = 22;

            prefs.SetItemID(1, sampleItemID2);

            FastByIDMap <IPreferenceArray> delegatePreferences = new FastByIDMap <IPreferenceArray>();

            delegatePreferences.Put(sampleUserID, prefs);

            PlusAnonymousConcurrentUserDataModel instance = getTestableWithDelegateData(10, delegatePreferences);

            long anonymousUserID = instance.TakeAvailableUser().Value;

            IPreferenceArray tempPrefs = new GenericUserPreferenceArray(2);

            tempPrefs.SetUserID(0, anonymousUserID);
            tempPrefs.SetItemID(0, sampleItemID);
            tempPrefs.SetUserID(1, anonymousUserID);
            long sampleItemID3 = 33;

            tempPrefs.SetItemID(1, sampleItemID3);

            instance.SetTempPrefs(tempPrefs, anonymousUserID);

            Assert.AreEqual(sampleUserID, instance.GetPreferencesForItem(sampleItemID).Get(0).GetUserID());
            Assert.AreEqual(2, instance.GetPreferencesForItem(sampleItemID).Length());
            Assert.AreEqual(1, instance.GetPreferencesForItem(sampleItemID2).Length());
            Assert.AreEqual(1, instance.GetPreferencesForItem(sampleItemID3).Length());

            Assert.AreEqual(2, instance.GetNumUsersWithPreferenceFor(sampleItemID));
            Assert.AreEqual(1, instance.GetNumUsersWithPreferenceFor(sampleItemID, sampleItemID2));
            Assert.AreEqual(1, instance.GetNumUsersWithPreferenceFor(sampleItemID, sampleItemID3));
        }
        public void testReleaseInvalidUser()
        {
            PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10);

            Assert.False(instance.ReleaseUser(long.MaxValue));
        }