public void Test_ThreadRatingCaluclations() { 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); CMSThreadRatingManager manager = new CMSThreadRatingManager(this.DataStore); for (int i = 0; i < 10; i++) { userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSThreadRating record = new CMSThreadRating(userBasic, thread, (short)i); BusinessObjectActionReport <RatingDataRepositoryActionStatus> report = manager.Create(record); Assert.AreEqual(RatingDataRepositoryActionStatus.Success, report.Status); } CMSThreadManager threadManager = new CMSThreadManager(this.DataStore); thread = threadManager.GetThread(section.CMSSectionType, thread.CMSThreadId); Assert.AreEqual(10, thread.CMSTotalRatings); Assert.AreEqual(45, thread.CMSRatingSum); Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file }
public void Test_CreateUpdateDeleteThreadRating() { 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); CMSThreadRatingManager manager = new CMSThreadRatingManager(this.DataStore); CMSThreadRating record = new CMSThreadRating(userBasic, thread, 1); BusinessObjectActionReport <RatingDataRepositoryActionStatus> report = manager.Create(record); Assert.AreEqual(RatingDataRepositoryActionStatus.Success, report.Status); CMSThreadRating recordToCompare; for (int i = 0; i < this.DefaultUpdateTestIterations; i++) { PopulateWithRandomValues(record, this.DummyDataManager, this.Random); recordToCompare = record; manager.Update(record); record = manager.GetThreadRating(thread, 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, thread, userBasic); Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Delete(CMSThreadRating cmsThreadRating) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsThreadRating); if (businessObjectActionReport.ValidationResult.IsValid) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_ThreadRatings_Delete(cmsThreadRating.CMSUserId, cmsThreadRating.CMSThreadId); } } catch (Exception ex) { _Log.Error("Error at cms_ThreadRatings_Delete", ex); throw new DataStoreException(ex, true); } if (num != 0) { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.WarnFormat("CMSThreadRating {0} was not deleted from the database (ErrorCode: {1})." , DebugUtility.GetObjectString(cmsThreadRating), num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSThreadRating {0} was not deleted from the database because the validation failed.\nReport: {1}", DebugUtility.GetObjectString(cmsThreadRating), businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
internal static void Delete(IDataStore dataStore, CMSThread thread, IUserBasic userBasic) { CMSThreadRatingManager manager = new CMSThreadRatingManager(dataStore); CMSThreadRating threadRating = manager.GetThreadRating(thread, userBasic); BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Delete(threadRating); Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status); Assert.IsNull(manager.GetThreadRating(thread, userBasic)); Trace.WriteLine("Successfully deleted threadRating " + threadRating.CMSThreadId + " -> " + threadRating.CMSUserId); }
internal static void PopulateWithRandomValues(CMSThreadRating record, DummyDataManager dtm, Random random) { record.Rating = (short)random.Next(1, 1000); }
internal BusinessObjectActionReport <RatingDataRepositoryActionStatus> Create(CMSThreadRating cmsThreadRating) { BusinessObjectActionReport <RatingDataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <RatingDataRepositoryActionStatus>(RatingDataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsThreadRating); if (businessObjectActionReport.ValidationResult.IsValid) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_ThreadRatings_InsertOrUpdate(cmsThreadRating.Rating, cmsThreadRating.CMSThreadId, cmsThreadRating.CMSUserId); } } catch (Exception ex) { _Log.Error("Error at cms_ThreadRatings_InsertOrUpdate", ex); throw new DataStoreException(ex, true); } switch (num) { case -1: businessObjectActionReport.Status = RatingDataRepositoryActionStatus.SelfRatingNotAllowed; break; case 0: cmsThreadRating.DateCreatedUtc = DateTime.UtcNow; break; default: businessObjectActionReport.Status = RatingDataRepositoryActionStatus.SqlError; _Log.ErrorFormat("CMSThreadRating {0} was not inserted at the database (ErrorCode: {1})." , DebugUtility.GetObjectString(cmsThreadRating), num); break; } } else { businessObjectActionReport.Status = RatingDataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSThreadRating {0} was not inserted at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsThreadRating) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }