예제 #1
0
        public void Test_ContentRatingCaluclations()
        {
            IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager);
            CMSSection section   = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random);
            CMSThread  thread    = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random);
            CMSContent content   = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random);

            CMSContentRatingManager manager = new CMSContentRatingManager(this.DataStore);

            for (int i = 0; i < 10; i++)
            {
                userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager);

                CMSContentRating record = new CMSContentRating(userBasic, content, (short)i);

                BusinessObjectActionReport <RatingDataRepositoryActionStatus> report = manager.Create(record);
                Assert.AreEqual(RatingDataRepositoryActionStatus.Success, report.Status);
            }

            CMSContentManager contentManager = new CMSContentManager(this.DataStore);

            content = contentManager.GetContent(content.CMSContentId);
            Assert.AreEqual(10, content.CMSTotalRatings);
            Assert.AreEqual(45, content.CMSRatingSum);

            Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file
        }
예제 #2
0
        public MessageRating GetMessageRating(Message message, IUserBasic userBasic)
        {
            CMSContentRating contentRating = _CMSContentRatingManager.GetContentRating(message.CMSContent, userBasic);

            if (contentRating != null)
            {
                return(new MessageRating(contentRating));
            }
            return(null);
        }
예제 #3
0
        internal static void Delete(IDataStore dataStore, CMSContent content, IUserBasic userBasic)
        {
            CMSContentRatingManager manager = new CMSContentRatingManager(dataStore);

            CMSContentRating contentRating = manager.GetContentRating(content, userBasic);

            BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Delete(contentRating);

            Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status);
            Assert.IsNull(manager.GetContentRating(content, userBasic));

            Trace.WriteLine("Successfully deleted contentRating " + contentRating.CMSContentId + " -> " + contentRating.CMSUserId);
        }
예제 #4
0
        public void Test_SelfRatingConstraint()
        {
            IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager);
            CMSSection section   = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random);
            CMSThread  thread    = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random);
            CMSContent content   = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random);

            CMSContentRatingManager manager = new CMSContentRatingManager(this.DataStore);

            CMSContentRating record = new CMSContentRating(userBasic, content, 1);
            BaseRatingInfo   baseRatingInfo;

            BusinessObjectActionReport <RatingDataRepositoryActionStatus> report = manager.Create(record, true, false, out baseRatingInfo);

            Assert.AreEqual(RatingDataRepositoryActionStatus.SelfRatingNotAllowed, report.Status);

            Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file
        }
예제 #5
0
        internal BusinessObjectActionReport <DataRepositoryActionStatus> Update(CMSContentRating cmsContentRating)
        {
            BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success);

            businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsContentRating);
            if (businessObjectActionReport.ValidationResult.IsValid)
            {
                int num = 0;
                try
                {
                    using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext())
                    {
                        num = dataStoreContext.cms_ContentRatings_InsertOrUpdate(cmsContentRating.Rating, cmsContentRating.CMSContentId, cmsContentRating.CMSUserId, true);
                    }
                }
                catch (Exception ex)
                {
                    _Log.Error("Error at cms_ContentRatings_InsertOrUpdate", ex);
                    throw new DataStoreException(ex, true);
                }
                if (num == 0)
                {
                    cmsContentRating.DateCreatedUtc = DateTime.UtcNow;
                }
                else
                {
                    businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError;
                    _Log.ErrorFormat("CMSContentRating {0} was not updated at the database (ErrorCode: {1})."
                                     , DebugUtility.GetObjectString(cmsContentRating), num);
                }
            }
            else
            {
                businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed;
                _Log.WarnFormat("CMSContentRating {0} was not updated at the database because the validation failed.\nReport: {1}"
                                , DebugUtility.GetObjectString(cmsContentRating), businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII));
            }
            return(businessObjectActionReport);
        }
예제 #6
0
        public void Test_CreateUpdateDeleteContentRating()
        {
            IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager);
            CMSSection section   = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random);
            CMSThread  thread    = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random);
            CMSContent content   = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random);

            CMSContentRatingManager manager = new CMSContentRatingManager(this.DataStore);

            CMSContentRating record = new CMSContentRating(userBasic, content, 1);
            BaseRatingInfo   baseRatingInfo;

            BusinessObjectActionReport <RatingDataRepositoryActionStatus> report = manager.Create(record, true, true, out baseRatingInfo);

            Assert.AreEqual(RatingDataRepositoryActionStatus.Success, report.Status);
            Assert.AreEqual(1, baseRatingInfo.RatingSum);
            Assert.AreEqual(1, baseRatingInfo.TotalRatings);

            CMSContentRating recordToCompare;

            for (int i = 0; i < this.DefaultUpdateTestIterations; i++)
            {
                PopulateWithRandomValues(record, this.DummyDataManager, this.Random);
                recordToCompare = record;

                manager.Update(record);
                record = manager.GetContentRating(content, userBasic);

                string errors = string.Empty;
                // TODO (Roman): relax datetime comparisons
                Assert.IsTrue(DebugUtility.ArePropertyValuesEqual(record, recordToCompare, out errors), errors);
                Trace.WriteLine("Update test successfull.");
            }

            Delete(this.DataStore, content, userBasic);
            Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file
        }
예제 #7
0
        internal BusinessObjectActionReport <RatingDataRepositoryActionStatus> Create(CMSContentRating cmsContentRating, bool getBaseRatingInfo, bool allowSelfRating, out BaseRatingInfo baseRatingInfo)
        {
            baseRatingInfo = null;
            BusinessObjectActionReport <RatingDataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <RatingDataRepositoryActionStatus>(RatingDataRepositoryActionStatus.Success);

            businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsContentRating);
            if (businessObjectActionReport.ValidationResult.IsValid)
            {
                int num = 0;
                try
                {
                    using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext())
                    {
                        num = dataStoreContext.cms_ContentRatings_InsertOrUpdate(cmsContentRating.Rating, cmsContentRating.CMSContentId, cmsContentRating.CMSUserId, allowSelfRating);
                        if (getBaseRatingInfo)
                        {
                            baseRatingInfo = dataStoreContext.cms_Contents_GetBaseRatingInfo(cmsContentRating.CMSContentId);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _Log.Error("Error at cms_ContentRatings_InsertOrUpdate, cms_Contents_GetBaseRatingInfo", ex);
                    throw new DataStoreException(ex, true);
                }
                switch (num)
                {
                case -1:
                    businessObjectActionReport.Status = RatingDataRepositoryActionStatus.SelfRatingNotAllowed;
                    break;

                case 0:
                    cmsContentRating.DateCreatedUtc = DateTime.UtcNow;
                    break;

                default:
                    businessObjectActionReport.Status = RatingDataRepositoryActionStatus.SqlError;
                    _Log.ErrorFormat("CMSContentRating {0} was not inserted at the database (ErrorCode: {1})."
                                     , DebugUtility.GetObjectString(cmsContentRating), num);
                    break;
                }
            }
            else
            {
                businessObjectActionReport.Status = RatingDataRepositoryActionStatus.ValidationFailed;
                _Log.WarnFormat("CMSContentRating {0} was not inserted at the database because the validation failed.\nReport: {1}"
                                , DebugUtility.GetObjectString(cmsContentRating)
                                , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII));
            }
            return(businessObjectActionReport);
        }
예제 #8
0
        internal BusinessObjectActionReport <RatingDataRepositoryActionStatus> Create(CMSContentRating cmsContentRating)
        {
            BaseRatingInfo baseRatingInfo = null;

            return(this.Create(cmsContentRating, false, false, out baseRatingInfo));
        }
예제 #9
0
 internal MessageRating(CMSContentRating cmsContentRating)
 {
     this._CMSContentRating = cmsContentRating;
 }
예제 #10
0
 public MessageRating(IUserBasic ratingUser, Message ratedMessage, MessageRatingType messageRatingType)
 {
     this._CMSContentRating = new CMSContentRating(ratingUser, ratedMessage.CMSContent, (short)(messageRatingType));
 }
예제 #11
0
 public MessageRating(IUserBasic ratingUser, int messageId, MessageRatingType messageRatingType)
 {
     this._CMSContentRating = new CMSContentRating(ratingUser, messageId, (short)(messageRatingType));
 }
예제 #12
0
 internal static void PopulateWithRandomValues(CMSContentRating record, DummyDataManager dtm, Random random)
 {
     record.Rating = (short)random.Next(1, 1000);
 }