public void Test_RemoveSecondInstanceOfSameLoadedObjectDoesNotRemoveIt() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO originalContactPerson = new ContactPersonTestBO(); ContactPersonTestBO copyContactPerson = new ContactPersonTestBO(); copyContactPerson.ContactPersonID = originalContactPerson.ContactPersonID; BusinessObjectManager.Instance.Add(copyContactPerson); //---------------Assert Precondition---------------- Assert.AreNotSame(originalContactPerson, copyContactPerson); Assert.AreEqual(originalContactPerson.ID.GetObjectId(), copyContactPerson.ID.GetObjectId()); Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(copyContactPerson)); Assert.IsFalse(boMan.Contains(originalContactPerson)); //---------------Execute Test ---------------------- BusinessObjectManager.Instance.Remove(originalContactPerson); //---------------Test Result ----------------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(copyContactPerson)); Assert.IsFalse(boMan.Contains(originalContactPerson)); }
public void Test_SavedObject_Twice_AddedToObjectManager_Once() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = new ContactPersonTestBO(); cp.Surname = TestUtil.CreateRandomString(); cp.Save(); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp)); //---------------Execute Test ---------------------- cp.Surname = TestUtil.CreateRandomString(); cp.Save(); //---------------Test Result ----------------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp)); Assert.IsTrue(boMan.Contains(cp.ID)); Assert.IsTrue(boMan.Contains(cp.ID.GetObjectId())); Assert.AreSame(cp, boMan[cp.ID.GetObjectId()]); Assert.AreSame(cp, boMan[cp.ID]); }
public BusinessObjectActionReport <DataRepositoryActionStatus> Update(IDepartmentModel department) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(department); if (businessObjectActionReport.ValidationResult.IsValid) { int num; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) num = dataStoreContext.wm_Departments_Update(department.DepartmentId, department.ParentDepartmentId, department.Name, department.OfficeId); } catch (Exception ex) { _Log.Error("Error at wm_Departments_Update", ex); throw new DataStoreException(ex, true); } if (num == 0) { businessObjectActionReport.Status = DataRepositoryActionStatus.NoRecordRowAffected; _Log.ErrorFormat("Department {0} was not updated at the database, NoRecordRowAffected" , DebugUtility.GetObjectString(department)); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("Department {0} was not updated at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(department) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public void Test_Add_CopyOfSameObjectTwiceShould_ThrowError() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO(); BusinessObjectManager boMan = BusinessObjectManager.Instance; boMan.Add(cp); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); //---------------Execute Test ---------------------- ContactPersonTestBO cp2 = new ContactPersonTestBO(); cp2.ContactPersonID = cp.ContactPersonID; try { boMan.Add(cp2); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains("There was a serious developer exception. Two copies of the business object", ex.Message); StringAssert.Contains(" were added to the object manager", ex.Message); } }
public void Test_LoadObject_UpdateObjectMan_NonGenericLoad() { //---------------Set up test pack------------------- ClassDef classDef = ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = CreateSavedCP(); IPrimaryKey id = cp.ID; cp = null; TestUtil.WaitForGC(); boMan.ClearLoadedObjects(); //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); //---------------Execute Test ---------------------- ContactPersonTestBO contactPersonTestBO = (ContactPersonTestBO)BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject(classDef, id); //---------------Test Result ----------------------- Assert.IsNotNull(contactPersonTestBO); Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(contactPersonTestBO)); Assert.IsTrue(boMan.Contains(id)); Assert.IsTrue(boMan.Contains(id.GetObjectId())); Assert.AreSame(contactPersonTestBO, boMan[id.GetObjectId()]); Assert.AreSame(contactPersonTestBO, boMan[id]); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Delete(CMSContent cmsContent, bool deleteLinkedThreads) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsContent); if (businessObjectActionReport.ValidationResult.IsValid) { int num = this.Delete(cmsContent.CMSContentId, deleteLinkedThreads); if (num == 0 || num == -1003) { businessObjectActionReport.Status = DataRepositoryActionStatus.NoRecordRowAffected; } else if (num < 0) { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.WarnFormat("CMSContent {0} was not deleted from the database (ErrorCode: {1})." , DebugUtility.GetObjectString(cmsContent) , num); } else { businessObjectActionReport.Status = DataRepositoryActionStatus.Success; } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSContent {0} was not deleted from the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsContent) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public BusinessObjectActionReport <DataRepositoryActionStatus> Delete(IApplication application) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(application); if (businessObjectActionReport.ValidationResult.IsValid) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) num = dataStoreContext.wm_Applications_Delete(application.ApplicationId); } catch (Exception ex) { _Log.Error("Error at wm_Applications_Delete", ex); throw new DataStoreException(ex, true); } if (num == 0) { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.WarnFormat("Application {0} was not deleted from the database (ErrorCode: {1})." , DebugUtility.GetObjectString(application) , num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("Application {0} was not deleted from the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(application) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Update(CMSGroup cmsGroup) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsGroup); if (businessObjectActionReport.ValidationResult.IsValid) { try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) businessObjectActionReport.Status = (DataRepositoryActionStatus)dataStoreContext.cms_Groups_InsertOrUpdate(cmsGroup.CMSGroupId, cmsGroup.Name, cmsGroup.Description, cmsGroup.CMSGroupType); return(businessObjectActionReport); } catch (Exception ex) { _Log.Error("Error at cms_Groups_InsertOrUpdate", ex); throw new DataStoreException(ex, true); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSGroup {0} was not updated at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsGroup) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
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); }
public void Test_ReturnSameObjectFromBusinessObjectLoader() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadClassDefWithAddressTestBOsRelationship(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO originalContactPerson = CreateSavedCP(); IPrimaryKey id = originalContactPerson.ID; originalContactPerson = null; boMan.ClearLoadedObjects(); TestUtil.WaitForGC(); //load second object from DB to ensure that it is now in the object manager ContactPersonTestBO myContact2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(id); //---------------Assert Precondition---------------- Assert.AreNotSame(originalContactPerson, myContact2); //---------------Execute Test ---------------------- ContactPersonTestBO myContact3 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(id); //---------------Test Result ----------------------- Assert.AreNotSame(originalContactPerson, myContact3); Assert.AreSame(myContact2, myContact3); }
public void Test_ChangePrimaryKeyForCompositeKey_UpdatedObjectMan() { //---------------Set up test pack------------------- ContactPersonCompositeKey.LoadClassDefs(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonCompositeKey cp = new ContactPersonCompositeKey(); cp.PK1Prop1 = TestUtil.CreateRandomString(); cp.PK1Prop2 = TestUtil.CreateRandomString(); cp.Save(); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp.ID)); Assert.AreSame(cp, boMan[cp.ID]); //---------------Execute Test ---------------------- cp.PK1Prop1 = TestUtil.CreateRandomString(); cp.PK1Prop2 = TestUtil.CreateRandomString(); cp.Save(); //---------------Test Result ----------------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp)); Assert.IsTrue(boMan.Contains(cp.ID)); Assert.IsTrue(boMan.Contains(cp.ID.GetObjectId())); Assert.AreSame(cp, boMan[cp.ID.GetObjectId()]); Assert.AreSame(cp, boMan[cp.ID]); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Update(CMSContent cmsContent, string[] tags, bool doReindex) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsContent); if (businessObjectActionReport.ValidationResult.IsValid) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_Contents_Update( cmsContent.CMSContentId , cmsContent.CMSThreadId , cmsContent.CMSParentContentId , cmsContent.AuthorUserId , cmsContent.CMSContentLevel , cmsContent.Subject , cmsContent.FormattedBody , cmsContent.IsApproved , cmsContent.IsLocked , cmsContent.CMSContentType , cmsContent.CMSContentStatus , cmsContent.CMSExtraInfo , cmsContent.CMSBaseContentId , cmsContent.UrlFriendlyName , tags); } } catch (Exception ex) { _Log.Error("Error at cms_Contents_Update", ex); throw new DataStoreException(ex, true); } if (num != 0) { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.ErrorFormat("CMSContent {0} was not updated from the database (ErrorCode: {1})." , DebugUtility.GetObjectString(cmsContent) , num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSContent {0} was not updated at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsContent) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public void Test_CreateObjectManager() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- BusinessObjectManager boMan = BusinessObjectManager.Instance; //---------------Test Result ----------------------- Assert.AreEqual(0, boMan.Count); // Assert.IsInstanceOfType(typeof(BusinessObjectManager), boMan); }
public void Test_BusinessObjectRegexValidation() { // TODO (Roman): Write a proper test for this MyTestClass testClass = new MyTestClass(); testClass.Name = "abcDEF123--"; testClass.Email = "*****@*****.**"; testClass.SomeInteger = 144; testClass.SomeLong = 155; Assert.IsTrue(BusinessObjectManager.Validate(testClass).IsValid); }
public void Test_SetBusinessObjectManager_ShouldSet() { //---------------Set up test pack------------------- IBusinessObjectManager expectedObjectManager = new BusinessObjectManager(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- BORegistry.BusinessObjectManager = expectedObjectManager; //---------------Test Result ----------------------- var actualObjectManager = BORegistry.BusinessObjectManager; Assert.AreSame(expectedObjectManager, actualObjectManager); }
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); }
public void Test_NewObjectNotAddedToObjectManager() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); //---------------Execute Test ---------------------- new ContactPersonTestBO(); //---------------Test Result ----------------------- Assert.AreEqual(0, boMan.Count); }
public BusinessObjectActionReport <DataRepositoryActionStatus> Create(IEmail email) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(email); int num; if (businessObjectActionReport.ValidationResult.IsValid) { try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) num = dataStoreContext.wm_Emails_Insert( email.ApplicationId , email.Subject , email.Body , email.Recipients , email.Sender , email.CreatedByUserId , email.Status , email.Priority , email.EmailType); } catch (Exception ex) { _Log.Error("Error at wm_Emails_Insert", ex); throw new DataStoreException(ex, true); } if (num > 0) { email.EmailId = num; } else { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.ErrorFormat("Email was not inserted at the database (ErrorCode: {0}).", num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("Email {0} was not inserted at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(email) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Create(CMSThread cmsThread) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsThread); if (businessObjectActionReport.ValidationResult.IsValid) { int num = -1; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_Threads_Insert( cmsThread.CMSSectionId , cmsThread.CMSName , cmsThread.CMSStickyDateUtc , cmsThread.IsLocked , cmsThread.CMSIsSticky , cmsThread.IsApproved , cmsThread.CMSThreadStatus); } } catch (Exception ex) { _Log.Error("Error at cms_Threads_Insert", ex); throw new DataStoreException(ex, true); } if (num > 0) { cmsThread.CMSThreadId = num; cmsThread.DateCreatedUtc = DateTime.UtcNow; } else { businessObjectActionReport.Status = DataRepositoryActionStatus.NoRecordRowAffected; } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSThread {0} was not inserted at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsThread) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public void Test_LoadObjectWhenAlreadyObjectInObjectManager() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadClassDefWithAddressTestBOsRelationship(); BusinessObjectManager boMan = BusinessObjectManager.Instance; AddressTestBO address; ContactPersonTestBO cp = CreateSavedCP_WithOneAddresss(out address); IPrimaryKey contactPersonID = cp.ID; IPrimaryKey addresssID = address.ID; cp = null; address = null; TestUtil.WaitForGC(); boMan.ClearLoadedObjects(); AddressTestBO addressOut; CreateSavedCP_WithOneAddresss(out addressOut); CreateSavedCP_WithOneAddresss(out addressOut); CreateSavedCP_WithOneAddresss(out addressOut); //---------------Assert Precondition---------------- Assert.AreEqual(6, boMan.Count); //---------------Execute Test ---------------------- ContactPersonTestBO loadedCP = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(contactPersonID); RelatedBusinessObjectCollection <AddressTestBO> addresses = loadedCP.AddressTestBOs; //---------------Test Result ----------------------- Assert.AreEqual(1, addresses.Count); Assert.AreEqual(8, boMan.Count); Assert.IsTrue(boMan.Contains(loadedCP)); Assert.AreSame(loadedCP, boMan[contactPersonID]); AddressTestBO loadedAddress = addresses[0]; Assert.IsTrue(boMan.Contains(loadedAddress)); Assert.IsTrue(boMan.Contains(addresssID)); Assert.IsTrue(boMan.Contains(addresssID.GetObjectId())); Assert.AreSame(loadedAddress, boMan[addresssID]); Assert.AreSame(loadedAddress, boMan[addresssID.GetObjectId()]); }
public static BusinessObjectActionReport <UniqueUserActionStatus> Update(UniqueUser user) { BusinessObjectActionReport <UniqueUserActionStatus> actionReport = new BusinessObjectActionReport <UniqueUserActionStatus>(UniqueUserActionStatus.Success); actionReport.ValidationResult = BusinessObjectManager.Validate(user); if (actionReport.ValidationResult.IsValid) { try { UsersDataContext dc = Configuration.GetUsersDataContext(); int affectedRows = dc.UpdateUniqueUser(user.UserID, user.AccountStatus, user.Timezone, user.Firstname, user.Lastname , user.DateOfBirth, user.City, user.IsNewletterSubscriber); if (affectedRows == 0) { actionReport.Status = UniqueUserActionStatus.NoRecordRowAffected; LogManager.LogEvent(ApplicationLocation.DataAccess, EventType.Error , "User " + user.UserID.ToString() + " was not updated at the database."); } } catch (SqlException ex) { actionReport.Status = UniqueUserActionStatus.SqlException; LogManager.LogException(ApplicationLocation.DataAccess, ex); } catch (Exception ex) { actionReport.Status = UniqueUserActionStatus.UnknownError; LogManager.LogException(ApplicationLocation.DataAccess, ex); } finally { } } else { actionReport.Status = UniqueUserActionStatus.ValidationFailed; LogManager.LogEvent(ApplicationLocation.DataAccess, EventType.Warning, "User " + user.UserID.ToString() + " was not updated at the database because the validation failed. Report: " + actionReport.ValidationResult.ToString(CommonTools.TextFormat.ASCII)); } return(actionReport); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Create(CMSFile cmsFile, string[] tags) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsFile); if (businessObjectActionReport.ValidationResult.IsValid) { int num = -1; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_Files_Insert(cmsFile.ApplicationId, cmsFile.CMSUserId, cmsFile.CMSFileType, cmsFile.FileName, cmsFile.Content, cmsFile.ContentType, cmsFile.ContentSize, cmsFile.FriendlyFileName, cmsFile.CMSHeight, cmsFile.CMSWidth, cmsFile.ContentId, tags); } } catch (Exception ex) { _Log.Error("Error at cms_Files_Insert", ex); throw new DataStoreException(ex, true); } if (num > 0) { cmsFile.CMSFileId = num; cmsFile.DateCreatedUtc = DateTime.UtcNow; } else if (num == -501) {// this is a special condition for system profile images to ensure thread safety on inserts businessObjectActionReport.Status = DataRepositoryActionStatus.UniqueKeyConstraint; } else { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.ErrorFormat("CMSFile was not inserted at the database (ErrorCode: {0}).", num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSFile {0} was not inserted at the database because the validation failed.\nReport: {1}", cmsFile.CMSFileId , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public void Test_ChildElementPropagation() { int validInteger = 120; int invalidInteger = 1000; MyParent myParent = new MyParent(); myParent.MyChild = new MyChild(invalidInteger); BusinessObjectValidationResult businessObjectValidationResult = BusinessObjectManager.Validate(myParent); Assert.AreEqual(ValidationStatus.NotAllPropertiesValid, businessObjectValidationResult.ValidationStatus); Trace.WriteLine(businessObjectValidationResult.ToString(TextFormat.ASCII)); myParent.MyChild = new MyChild(validInteger); businessObjectValidationResult = BusinessObjectManager.Validate(myParent); Assert.AreEqual(ValidationStatus.Valid, businessObjectValidationResult.ValidationStatus); Trace.WriteLine(businessObjectValidationResult.ToString(TextFormat.ASCII)); myParent.MyChildList = new List <MyChild>(); myParent.MyChildList.Add(new MyChild(validInteger)); myParent.MyChildList.Add(new MyChild(validInteger)); myParent.MyChildList.Add(new MyChild(validInteger)); businessObjectValidationResult = BusinessObjectManager.Validate(myParent); Assert.AreEqual(ValidationStatus.Valid, businessObjectValidationResult.ValidationStatus); Trace.WriteLine(businessObjectValidationResult.ToString(TextFormat.ASCII)); myParent.MyChildList = new List <MyChild>(); myParent.MyChildList.Add(new MyChild(validInteger)); myParent.MyChildList.Add(new MyChild(invalidInteger)); myParent.MyChildList.Add(new MyChild(invalidInteger)); businessObjectValidationResult = BusinessObjectManager.Validate(myParent); Assert.AreEqual(ValidationStatus.NotAllPropertiesValid, businessObjectValidationResult.ValidationStatus); Trace.WriteLine(businessObjectValidationResult.ToString(TextFormat.ASCII)); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Update(CMSSection cmsSection) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsSection); if (businessObjectActionReport.ValidationResult.IsValid) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_Sections_Update(cmsSection.CMSSectionId, cmsSection.CMSParentSectionId, cmsSection.CMSGroupId , cmsSection.Name, cmsSection.Description, cmsSection.CMSSectionType, cmsSection.IsActive, cmsSection.IsModerated); } } catch (Exception ex) { _Log.Error("Error at cms_Sections_Update", ex); throw new DataStoreException(ex, true); } // TODO (Roman): make sure we return the right values from db if (num != -1003) { if (num == 0) { businessObjectActionReport.Status = DataRepositoryActionStatus.NoRecordRowAffected; } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.NameNotUnique; } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSSection {0} was not updated at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsSection) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public void Test_DeleteObject_RemovesFromObjectMan() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = CreateSavedCP(); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp)); Assert.AreSame(cp, boMan[cp.ID]); //---------------Execute Test ---------------------- cp.Delete(); cp.Save(); //---------------Test Result ----------------------- Assert.AreEqual(0, boMan.Count); }
public void Test_LoadObject_SingleRelationship_UpdatedObjectMan_Generic() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadClassDefWithAddressTestBOsRelationship(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = CreateSavedCP(); AddressTestBO address = new AddressTestBO(); address.ContactPersonID = cp.ContactPersonID; address.Save(); IPrimaryKey contactPersonID = cp.ID; IPrimaryKey addresssID = address.ID; cp = null; address = null; TestUtil.WaitForGC(); boMan.ClearLoadedObjects(); //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); //---------------Execute Test ---------------------- AddressTestBO loadedAddress = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <AddressTestBO>(addresssID); ContactPersonTestBO loadedCP = loadedAddress.ContactPersonTestBO; //---------------Test Result ----------------------- Assert.AreEqual(2, boMan.Count); Assert.IsTrue(boMan.Contains(loadedCP)); Assert.IsTrue(boMan.Contains(contactPersonID)); Assert.AreSame(loadedCP, boMan[contactPersonID]); Assert.IsTrue(boMan.Contains(loadedAddress)); Assert.IsTrue(boMan.Contains(addresssID)); Assert.IsTrue(boMan.Contains(addresssID.GetObjectId())); Assert.AreSame(loadedAddress, boMan[addresssID]); Assert.AreSame(loadedAddress, boMan[addresssID.GetObjectId()]); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> CreateTemporaryFile(CMSFile cmsFile) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsFile); if (businessObjectActionReport.ValidationResult.IsValid) { DateTime utcNow = DateTime.UtcNow; int num = -1; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_FilesTemp_Insert(cmsFile.ApplicationId, cmsFile.CMSUserId, cmsFile.CMSFileType, cmsFile.FileName, cmsFile.Content , cmsFile.ContentType, cmsFile.ContentSize, cmsFile.FriendlyFileName, cmsFile.CMSHeight, cmsFile.CMSWidth); } } catch (Exception ex) { _Log.Error("Error at cms_FilesTemp_Insert", ex); throw new DataStoreException(ex, true); } if (num > 0) { cmsFile.CMSFileId = num; cmsFile.IsTemporary = true; cmsFile.DateCreatedUtc = DateTime.UtcNow; } else { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.ErrorFormat("Temporary CMSFile {0} was not inserted at the database (ErrorCode: {1}).", cmsFile.CMSFileId, num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("Temporary CMSFile {0} was not inserted at the database because the validation failed.\nReport: {1}", cmsFile.CMSFileId, businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public void Test_RemoveFromObjectManager() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO cp = new ContactPersonTestBO(); cp.Surname = TestUtil.CreateRandomString(); boMan.Add(cp); //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp)); //---------------Execute Test ---------------------- boMan.Remove(cp); //---------------Test Result ----------------------- Assert.AreEqual(0, boMan.Count); Assert.IsFalse(boMan.Contains(cp)); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { ICityManager cityManager = (ICityManager)BusinessObjectManager.GetCityManager(); ddlCities.DataSource = cityManager.GetCities(); //ddlCities.DataMember = "CityId"; ddlCities.DataValueField = "CityId"; ddlCities.DataTextField = "Name"; ddlCities.DataBind(); } catch (CityManagerException) { } catch (Exception) { } } }
public void Test_SaveDuplicateObject_DoesNotAddItselfToObjectManager() { //This scenario is unlikely to ever happen in normal use but is frequently hit during testing. //An object that has a reference to it is removed from the object manager (usually via ClearLoadedObjects). // A second instance of the same object is now loaded. This new instance is therefore added to the object manager. // The first object is saved. This must not remove the second instance of the object from the object manager and insert a itself. //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectManager boMan = BusinessObjectManager.Instance; ContactPersonTestBO originalContactPerson = new ContactPersonTestBO(); originalContactPerson.Surname = "FirstSurname"; originalContactPerson.Save(); IPrimaryKey origCPID = originalContactPerson.ID; BusinessObjectManager.Instance.ClearLoadedObjects(); //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); Assert.IsFalse(boMan.Contains(originalContactPerson)); //---------------Execute Test Step 1---------------------- ContactPersonTestBO myContact2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(origCPID); //---------------Test Result Step 1----------------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(myContact2)); //---------------Execute Test Step 2---------------------- originalContactPerson.Surname = TestUtil.CreateRandomString(); originalContactPerson.Save(); //---------------Test Result Step 1----------------------- Assert.AreNotSame(originalContactPerson, myContact2); Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(myContact2)); Assert.IsFalse(boMan.Contains(originalContactPerson)); }
public void Test_CompositePrimaryKey_CreateBO_DoesNotAddToObjectManager() { //---------------Set up test pack------------------- ContactPersonCompositeKey.LoadClassDefs(); IBusinessObjectManager boMan = new BusinessObjectManager(); BORegistry.BusinessObjectManager = boMan; //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); //---------------Execute Tests---------------------- new ContactPersonCompositeKey(); //---------------Execute Test ---------------------- Assert.AreEqual(1, boMan.Count); }
public void Test_ObjectID_CreateBO_DoesNotAddToObjectManager() { //---------------Set up test pack------------------- SetupDefaultContactPersonBO(); IBusinessObjectManager boMan = new BusinessObjectManager(); BORegistry.BusinessObjectManager = boMan; //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); //---------------Execute Tests---------------------- new ContactPersonTestBO(); //---------------Execute Test ---------------------- Assert.AreEqual(1, boMan.Count); }
public void Test_GetBusinessObject_WithPrimaryKey_WhenNotExistsWhenComposite_ShouldRetNull_FixBug533() { //--------------- Set up test pack ------------------ var businessObjectManager = new BusinessObjectManager(); BORegistry.BusinessObjectManager = businessObjectManager; ContactPersonCompositeKey.LoadClassDefs(); var cp = CreateCompositeCP(); var otherBOMan = new BusinessObjectManager(); //----------------Assert Preconditions--------------- Assert.IsNotNull(cp.ID); Assert.IsFalse(otherBOMan.Contains(cp.ID)); //--------------- Execute Test ---------------------- var found = otherBOMan.GetBusinessObject(cp.ID); //--------------- Test Result ----------------------- Assert.IsNull(found); }
public void Test_GetBusinessObject_WithPrimaryKey_WhenExistsWhenComposite_ShouldRetObject_FixBug533() { //--------------- Set up test pack ------------------ var businessObjectManager = new BusinessObjectManager(); BORegistry.BusinessObjectManager = businessObjectManager; ContactPersonCompositeKey.LoadClassDefs(); var expectedFound = CreateCompositeCP(); //----------------Assert Preconditions--------------- Assert.IsNotNull(expectedFound.ID); Assert.IsNotNull(((BOPrimaryKey)expectedFound.ID).BusinessObject); Assert.IsTrue(businessObjectManager.Contains(expectedFound.ID)); //--------------- Execute Test ---------------------- var found = businessObjectManager.GetBusinessObject(expectedFound.ID); //--------------- Test Result ----------------------- Assert.AreSame(expectedFound, found); }
public void Test_GetBusinessObject_WithPrimaryKey_WhenNotExists_ShouldRetNull_FixBug533() { //--------------- Set up test pack ------------------ var businessObjectManager = new BusinessObjectManager(); BORegistry.BusinessObjectManager = businessObjectManager; SetupDefaultContactPersonBO(); var cp = new ContactPersonTestBO(); var otherBOMan = new BusinessObjectManager(); //----------------Assert Preconditions--------------- Assert.IsFalse(otherBOMan.Contains(cp.ID)); //--------------- Execute Test ---------------------- var found = otherBOMan.GetBusinessObject(cp.ID); //--------------- Test Result ----------------------- Assert.IsNull(found); }
public void Test_SaveForCompositeKey_UpdatedObjectMan() { //---------------Set up test pack------------------- ContactPersonCompositeKey.LoadClassDefs(); IBusinessObjectManager boMan = new BusinessObjectManager(); BORegistry.BusinessObjectManager = boMan; var cp = new ContactPersonCompositeKey { PK1Prop1 = TestUtil.GetRandomString(), PK1Prop2 = TestUtil.GetRandomString() }; //---------------Assert Precondition---------------- Assert.AreEqual(1, boMan.Count); //---------------Execute Test ---------------------- cp.Save(); //---------------Test Result ----------------------- Assert.AreEqual(1, boMan.Count); Assert.IsTrue(boMan.Contains(cp)); Assert.IsTrue(boMan.Contains(cp.ID)); Assert.IsTrue(boMan.Contains(cp.ID.ObjectID)); Assert.AreSame(cp, boMan[cp.ID.ObjectID]); Assert.AreSame(cp, boMan[cp.ID]); }
public void Test_CompositePrimaryKey_SetPrimaryKeyPropValue_DoesNotAddToObjectManager() { //---------------Set up test pack------------------- ContactPersonCompositeKey.LoadClassDefs(); IBusinessObjectManager boMan = new BusinessObjectManager(); BORegistry.BusinessObjectManager = boMan; //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); //---------------Execute Tests---------------------- var cp = new ContactPersonCompositeKey {PK1Prop1 = TestUtil.GetRandomString()}; //---------------Execute Test ---------------------- Assert.AreEqual(1, boMan.Count); }
public void Test_GetBusinessObject_WithPrimaryKey_WhenExists_ShouldRetObject_FixBug533() { //--------------- Set up test pack ------------------ var businessObjectManager = new BusinessObjectManager(); BORegistry.BusinessObjectManager = businessObjectManager; SetupDefaultContactPersonBO(); var expectedFound = new ContactPersonTestBO(); //----------------Assert Preconditions--------------- Assert.IsTrue( businessObjectManager.Contains(expectedFound.ID)); //--------------- Execute Test ---------------------- var found = businessObjectManager.GetBusinessObject(expectedFound.ID); //--------------- Test Result ----------------------- Assert.AreSame(expectedFound, found); }
public void Test_CompositePrimaryKey_SetBothPrimaryKeyPropValues_DoesNotAddToObjectManager() { //---------------Set up test pack------------------- ContactPersonCompositeKey.LoadClassDefs(); IBusinessObjectManager boMan = new BusinessObjectManager(); BORegistry.BusinessObjectManager = boMan; //---------------Assert Precondition---------------- Assert.AreEqual(0, boMan.Count); //---------------Execute Tests---------------------- var cp = CreateCompositeCP(); //---------------Execute Test ---------------------- Assert.IsNotNull(cp); Assert.AreEqual(1, boMan.Count); }
public void Test_SetBusinessObjectManager_ShouldSet() { //---------------Set up test pack------------------- IBusinessObjectManager expectedObjectManager = new BusinessObjectManager(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- BORegistry.BusinessObjectManager = expectedObjectManager; //---------------Test Result ----------------------- var actualObjectManager = BORegistry.BusinessObjectManager; Assert.AreSame(expectedObjectManager, actualObjectManager); }