Ejemplo n.º 1
0
 /// <summary>
 /// Update the commission display
 /// </summary>
 /// <param name="businessChannelOverride">Override to be modified</param>
 private void UpsertCommissionDisplay(BusinessChannelOverride businessChannelOverride)
 {
     var dictionaryInstance = new DictionaryInstance()
     {
         CultureCode = ROOT,
         Content = businessChannelOverride.DisplayCommission ?? String.Empty,
         Item = new DictionaryDataItem()
         {
             ItemKey =
                 string.Format(DictionaryConstants.BUSINESS_CHANNEL_OVERRIDE_DISPLAY_COMMISION,
                               businessChannelOverride.Id)
         }
     };
     dictionaryDao.UpsertDictionaryInstance(dictionaryInstance);
     businessChannelOverride.DctCommissionDisplay = dictionaryInstance.ItemId;
     businessChannelOverrideDao.Modify(businessChannelOverride);
 }
Ejemplo n.º 2
0
            public void UpsertWithFaultyCultureThrowsException()
            {
                // Arrange
                var item = new DictionaryInstance
                {
                    CultureCode = FAULTY_CULTURE,
                    Content = CONTENT,
                    Item = new DictionaryDataItem
                    {
                        ItemKey = NEW_DICT_KEY
                    }
                };

                // Act
                dictionaryDao.UpsertDictionaryInstance(item);

                // Assert done in expectedException
            }  
Ejemplo n.º 3
0
            public void InsertNewKeyIsSuccessful()
            {
                // Arrange
                var instance = new DictionaryInstance
                {
                    CultureCode = CULTURE,
                    Content = CONTENT,
                    Item = new DictionaryDataItem
                    {
                        ItemKey = NEW_DICT_KEY
                    }
                };

                // Act
                bool result = dictionaryDao.UpsertDictionaryInstance(instance);

                // Assert
                Assert.IsTrue(result, "upsert did not work");
                Assert.IsTrue(instance.ItemId != default(int), "Id was not set post insert");
            }
Ejemplo n.º 4
0
            public void UpdateOfExistingKeyIsSuccessful()
            {
                // Arrange
                var item = new DictionaryInstance
                {
                    CultureCode = CULTURE,
                    Content = CONTENT,
                    Item = new DictionaryDataItem
                    {
                        ItemKey = NEW_DICT_KEY
                    }
                };
                int originalId = 0;
                
                bool result = dictionaryDao.UpsertDictionaryInstance(item);
                // double check insert is working
                Assert.IsTrue(result, "upsert did not work");
                originalId = item.ItemId;

                item.Content = ALTERED_CONTENT;

                // Act
                result = dictionaryDao.UpsertDictionaryInstance(item);

                // Assert
                Assert.IsTrue(result, "upsert did not work");
                Assert.AreEqual(originalId, item.ItemId, "Ids didn't match after update");
            }
Ejemplo n.º 5
0
            public void EmptyContentReturnsFalse()
            {
                // Arrange
                IDictionaryDao mockDao = MockRepository.GenerateMock<IDictionaryDao>();

                DictionaryInstance instance = new DictionaryInstance
                                                  {
                                                      Content = string.Empty,
                                                      CultureCode = VALID_CULTURE,
                                                      Item = new DictionaryDataItem
                                                      {
                                                          ItemKey = VALID_KEY
                                                      }
                                                  };

                // make sure we check before dao call
                mockDao.Expect(ddao => ddao.UpsertDictionaryInstance(Arg<DictionaryInstance>.Is.Anything))
                       .Repeat.Never();

                DictionaryManager manager = new DictionaryManager()
                    {
                        DictionaryDao = mockDao
                    };

                // Act
                bool response = manager.UpsertDictionaryInstance(instance);

                // Assert
                Assert.IsFalse(response, "Response should be false");
                mockDao.VerifyAllExpectations();
            }
Ejemplo n.º 6
0
            public void ValidDataCallsMethodsReturnsTrue()
            {
                // Arrange
                IDictionaryDao mockDao = MockRepository.GenerateMock<IDictionaryDao>();

                DictionaryInstance instance = new DictionaryInstance
                {
                    Content = VALID_CONTENT,
                    CultureCode = VALID_CULTURE,
                    Item = new DictionaryDataItem
                    {
                        ItemKey = VALID_KEY
                    }
                };

                // make sure we check before dao call
                mockDao.Expect(ddao => ddao.UpsertDictionaryInstance(Arg<DictionaryInstance>.Matches(dict => dict.Content == instance.Content &&
                                                                                                             dict.CultureCode == instance.CultureCode &&
                                                                                                             dict.Item.ItemKey == instance.Item.ItemKey))).Return(true).Repeat.Once();

                DictionaryManager manager = new DictionaryManager()
                {
                    DictionaryDao = mockDao
                };

                // Act
                bool response = manager.UpsertDictionaryInstance(instance);

                // Assert
                Assert.IsTrue(response, "Response should be true for good data");
                mockDao.VerifyAllExpectations();
            } 
Ejemplo n.º 7
0
        /// <summary>
        /// Add/modify a translation for a dictionary item
        /// </summary>
        /// <param name="dictInstance">instance to add/modify</param>
        /// <param name="skipContentCheck">Allow saving keys with empty or null content</param>
        /// <returns>true if successful</returns>
        public bool UpsertDictionaryInstance(DictionaryInstance dictInstance, bool skipContentCheck = false)
        {
            // something isn't right
            if (dictInstance.IsValid(skipContentCheck) == false)
            {
                return false;
            }

            var result = dictionaryDao.UpsertDictionaryInstance(dictInstance);
            if (result)
            {
                Cache.Cache.DictionaryCache.Invalidate(dictInstance.Item.ItemKey);
            }
            return result;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add/Modify a dictionary instance
        /// If it is new culture for existing item it will insert
        /// </summary>
        /// <param name="instance">instance to change/add</param>
        /// <returns>true if successful from db</returns>
        public bool UpsertDictionaryInstance(DictionaryInstance instance)
        {
            const string UPSERTSQL = "Dictionary.UpsertItem";

            var parameters = new List<SqlParameter>();
            parameters.Add(DbHelper.CreateParameter(ITEM_KEY, instance.Item.ItemKey));
            parameters.Add(DbHelper.CreateParameter(CULTURE_CODE, instance.CultureCode));
            parameters.Add(DbHelper.CreateParameter(CONTENT, instance.Content));
            parameters.Add(DbHelper.CreateParameter(USER_ID, Auditing.AuditFieldsHelper.GetUserId()));
            SqlParameter outParam = DbHelper.CreateParameterOut<int>(ITEM_ID, SqlDbType.Int);
            parameters.Add(outParam);

            try
            {
                DbHelper.ExecuteNonQueryCommand(UPSERTSQL, CommandType.StoredProcedure, parameters);
            }
            catch (SqlException sqlException)
            {
                throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30111,
                                                                                     "DictionaryDao.UpsertDictionaryInstance",
                                                                                     additionalDescriptionParameters:
                                                                                         (new object[] { instance.CultureCode, instance.Content, instance.Item.ItemKey }),
                                                                                     arguments:
                                                                                         new object[] { }, exception: sqlException));
            }
            instance.ItemId = DbHelper.ParameterValue<int>(outParam);
            return instance.ItemId != default(int);
        }