public void can_set_AccountTag_name_to_blank_or_null_but_then_IsValid_is_false(string name) { var accountTag = new AccountTag(101, "Holiday - USA 2010") {Name = name}; Assert.AreEqual(name, accountTag.Name); Assert.IsFalse(accountTag.IsValid); }
public AccountTagViewModel(AccountTag tag, IAccountTagRepository repository) { if (tag == null) throw new ArgumentNullException("tag"); if (repository == null) throw new ArgumentNullException("repository"); _tag = tag; _repository = repository; }
public void can_create_new_accountTag() { var accountTag = new AccountTag(1, "Holiday"); Assert.AreEqual(1, accountTag.Id); Assert.AreEqual("Holiday", accountTag.Name); Assert.IsTrue(accountTag.IsValid); }
public void can_create_new_AccountTagViewModel() { var tag = new AccountTag(1, "Entertainment"); var vm = new AccountTagViewModel(tag, _mockAccountTagRepository); Assert.AreEqual(tag.Id, vm.TagId); Assert.AreEqual(tag.Name, vm.TagName); }
public void can_emit_xml_describing_AccountTag() { var tag = new AccountTag(3, "Tax free Savings"); const string expectedResult = @"<tag id=""3"">Tax free Savings</tag>"; Assert.AreEqual(expectedResult, tag.EmitXml().ToString()); }
private static void DeleteAllProTags(Mobile from) { int deletedProTags = 0; foreach (Mobile m in World.Mobiles.Values) { if (m is PlayerMobile) { PlayerMobile pm = m as PlayerMobile; if (pm.Account == null) { continue; } Account acc = pm.Account as Account; for (int i = acc.Tags.Count - 1; i >= 0; --i) { if (i >= acc.Tags.Count) { continue; } AccountTag tag = acc.Tags[i]; if (tag.Name.StartsWith(ProTagPrefix(pm))) { acc.Tags.RemoveAt(i); deletedProTags++; } } } } from.SendMessage(68, "A total of {0} ProTags have been deleted.", deletedProTags); }
public void adding_a_new_AccountTag_without_an_id_gives_it_an_id_one_higher_than_maximum() { int maxId = _repository.GetAll().Select(n => n.Id).Max(); var newTag = new AccountTag(0, "Eating out"); _repository.Save(newTag); Assert.AreEqual(maxId + 1, newTag.Id); }
public void account_tags_are_not_equal_if_id_is_different() { var accountTag1 = new AccountTag(1, "Food"); var accountTag2 = new AccountTag(2, "Food"); Assert.IsFalse(accountTag1.Equals(accountTag2)); Assert.IsFalse(accountTag1 == accountTag2); Assert.AreNotEqual(accountTag1, accountTag2); Assert.AreNotSame(accountTag1, accountTag2); }
public void account_tags_are_equal__when_id_is_equal() { var accountTag1 = new AccountTag(2, "Food"); var accountTag2 = new AccountTag(2, "Bonanza"); Assert.IsTrue(accountTag1.Equals(accountTag2)); Assert.IsTrue(accountTag1 == accountTag2); Assert.AreEqual(accountTag1, accountTag2); Assert.AreNotSame(accountTag1, accountTag2); }
public void adding_a_new_AccountTag_to_empty_repository_gives_it_an_id_of_one() { foreach (var tag in _repository.GetAll().ToList()) _repository.Remove(tag); var newTag = new AccountTag(0, "Food - Eating out"); _repository.Save(newTag); Assert.AreEqual(1, newTag.Id); }
public void can_add_validation_to_accountTags_Name_setter_which_is_called_when_accountTag_Name_is_changed() { bool validatorCalled = false; var tag = new AccountTag(3, "ISAs"); tag.NameChanged += ((s, a) => { validatorCalled = true; }); tag.Name = "ISAs"; Assert.AreEqual("ISAs", tag.Name); Assert.IsTrue(validatorCalled); }
public void changing_AccountTagName_to_same_name_does_not_cause_update() { var tag = new AccountTag(1, "Holiday"); var vm = new AccountTagViewModel(tag, _mockAccountTagRepository); vm.PropertyChanged += _changeCounter.HandlePropertyChange; vm.TagName = "Holiday"; Assert.AreEqual(0, _changeCounter.NoOfPropertiesChanged); Assert.AreEqual(0, _changeCounter.TotalChangeCount); Assert.AreEqual(0, _changeCounter.ChangeCount("TagName")); _mocks.VerifyAllExpectationsHaveBeenMet(); }
public void attempting_to_change_AccountTagName_to_a_name_that_would_cause_a_duplicate_in_repository_do_not_call_repository() { var tag = new AccountTag(1, "Holiday"); var vm = new AccountTagViewModel(tag, _mockAccountTagRepository); vm.PropertyChanged += (s, args) => _changeCounter.HandlePropertyChange(s, args); Expect.Once.On(_mockAccountTagRepository).Method("CouldSetAccountTagName").Will(Return.Value(false)); vm.TagName = "Duplicate Name"; Assert.AreEqual(1, _changeCounter.NoOfPropertiesChanged); Assert.AreEqual(1, _changeCounter.TotalChangeCount); Assert.AreEqual(1, _changeCounter.ChangeCount("TagName")); _mocks.VerifyAllExpectationsHaveBeenMet(); }
public void changing_AccountTagName_to_valid_name_causes_AccountTag_to_be_updated() { var tag = new AccountTag(1, "Holiday"); var vm = new AccountTagViewModel(tag, _mockAccountTagRepository); vm.PropertyChanged += (s, args) => _changeCounter.HandlePropertyChange(s, args); Expect.Once.On(_mockAccountTagRepository).Method("CouldSetAccountTagName").Will(Return.Value(true)); Expect.Once.On(_mockAccountTagRepository).Method("Save").With(tag); vm.TagName = "Holidays"; Assert.AreEqual(1, _changeCounter.NoOfPropertiesChanged); Assert.AreEqual(1, _changeCounter.TotalChangeCount); Assert.AreEqual(1, _changeCounter.ChangeCount("TagName")); _mocks.VerifyAllExpectationsHaveBeenMet(); }
protected override void OnTarget(Mobile from, object targeted) { if (targeted is PlayerMobile) { PlayerMobile pm = targeted as PlayerMobile; if (pm.Account == null) { from.SendMessage(38, "{0} has no account!", pm.Name); return; } Account acc = pm.Account as Account; if (acc.Tags.Count == 0) { from.SendMessage("There are no ProTags set for {0}.", pm.Name); return; } bool noProTagsFound = true; for (int i = 0; i < acc.Tags.Count; ++i) { AccountTag tag = acc.Tags[i]; if (tag.Name.StartsWith(ProTagPrefix(pm))) { from.SendMessage("{0} = {1}", tag.Name.Replace(ProTagPrefix(pm), ""), tag.Value); noProTagsFound = false; } } if (noProTagsFound) { from.SendMessage("There are no ProTags set for {0}.", pm.Name); } } else { from.SendMessage(38, "You can only use this command on PlayerMobiles."); } }
public void AccountTags_property_returns_a_collection_of_AccountsTagViewModels_belonging_to_the_account() { var tag1 = new AccountTag(1, "Entertainment"); var tag2 = new AccountTag(2, "Food"); var tag3 = new AccountTag(3, "Services"); var account = new Account(1, "HSBC current", AccountType.Asset); account.AddTag(tag1); account.AddTag(tag2); account.AddTag(tag3); var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository); ObservableCollection<AccountTagViewModel> tagVMs = vm.AccountTags; var tagNames = tagVMs.Select(x => x.TagName).ToList(); Assert.AreEqual(3, tagVMs.Count); Assert.IsTrue(tagNames.Contains("Entertainment")); Assert.IsTrue(tagNames.Contains("Food")); Assert.IsTrue(tagNames.Contains("Services")); }
public void you_can_create_an_AccountTag_with_no_name_but_then_IsValid_is_false(string name) { var tag = new AccountTag(100, name); Assert.AreEqual(name, tag.Name); Assert.IsFalse(tag.IsValid); }
public void to_string_method_returns_name() { var tag = new AccountTag(1, "ISA"); Assert.AreEqual(tag.Name, tag.ToString()); }
public void exception_raised_if_you_create_new_AccountTagViewModel_with_null_accountTagRepository() { var tag = new AccountTag(1, "Entertainment"); Assert.Throws<ArgumentNullException>(() => new AccountTagViewModel(tag, null)); }
private static void RecalculateAccountNoValues(int verificationNo, decimal amount, TagHandlerAction tagHandlerAction, int accountTagNo, AccountTagCollection accountTags, Account account, out List <LogItem> logItems) { AccountTag currentAccountTag = accountTags.Find(at => at.No == accountTagNo); decimal totalAbsoluteAmount = 0; decimal totalRelativePercent = 0; foreach (var accountTag in accountTags) { if (accountTag.Type == AccountTagType.PercentOfRest) { totalRelativePercent += accountTag.RelativeValue; } else if (accountTag.Type == AccountTagType.ExactAmount) { totalAbsoluteAmount += accountTag.Amount; } } logItems = new List <LogItem>(); string logText; if (tagHandlerAction == TagHandlerAction.Untagged) { decimal newTotalRelativeAndUntaggedAmount = account.Balance + account.BalanceBroughtForwardAmount - totalAbsoluteAmount + amount; var relativeAccountTags = accountTags.Where(at => at.Type == AccountTagType.PercentOfRest); // Recalculate percent values (if there is anything left in the account after the withdrawal) if (newTotalRelativeAndUntaggedAmount > 0) { foreach (var accountTag in relativeAccountTags) { logText = string.Format("Relative account tag {0} changed value from {1} to ", accountTag.No, accountTag.RelativeValue.ToString("0.#########")); accountTag.RelativeValue = Math.Round(accountTag.Amount / newTotalRelativeAndUntaggedAmount, 9); if (accountTag.RelativeValue < 0) { accountTag.RelativeValue = 0; } else if (accountTag.RelativeValue > 1) { accountTag.RelativeValue = 1; } logText += accountTag.RelativeValue.ToString("0.#########") + "."; logItems.Add(new LogItem(CurrentApplication.UserNo, verificationNo, account.No, LogItemType.AccountTagRecalculated, logText, CurrentApplication.DateTimeNow)); } } } else if (tagHandlerAction == TagHandlerAction.Specified) { decimal newTotalRelativeAndUntaggedAmount = account.Balance + account.BalanceBroughtForwardAmount - totalAbsoluteAmount + amount; var relativeAccountTags = accountTags.Where(at => at.Type == AccountTagType.PercentOfRest); decimal totalRelativePercentAfter = 0m; if (currentAccountTag.Type == AccountTagType.ExactAmount) { logText = string.Format("Absolute account tag {0} changed value from {1} to {2}.", currentAccountTag.No, currentAccountTag.MoneyValue.ToString("0.####"), (currentAccountTag.MoneyValue + amount).ToString("0.####")); currentAccountTag.MoneyValue += amount; logItems.Add(new LogItem(CurrentApplication.UserNo, verificationNo, account.No, LogItemType.AccountTagRecalculated, logText, CurrentApplication.DateTimeNow)); } else { // Recalculate percent values (if there is anything left in the account after the withdrawal) if (newTotalRelativeAndUntaggedAmount > 0) { foreach (var accountTag in relativeAccountTags) { decimal accountTagAmount = accountTag.Amount; if (accountTag.No == currentAccountTag.No) { accountTagAmount += amount; } logText = string.Format("Relative account tag {0} changed value from {1} to ", accountTag.No, accountTag.RelativeValue.ToString("0.#########")); accountTag.RelativeValue = Math.Round(accountTagAmount / newTotalRelativeAndUntaggedAmount, 9); if (accountTag.RelativeValue < 0) { accountTag.RelativeValue = 0; } else if (accountTag.RelativeValue > 1) { accountTag.RelativeValue = 1; } totalRelativePercentAfter += accountTag.RelativeValue; logText += accountTag.RelativeValue.ToString("0.#########") + "."; logItems.Add(new LogItem(CurrentApplication.UserNo, verificationNo, account.No, LogItemType.AccountTagRecalculated, logText, CurrentApplication.DateTimeNow)); } } // If the total percent for all relative account tags was 100 percent before transaction, // then make sure that they are 100 percent after. if (totalRelativePercent == 1 || totalRelativePercentAfter > 1) { decimal diff = totalRelativePercentAfter - totalRelativePercent; var highestAccountTag = relativeAccountTags.OrderByDescending(at => at.Amount).First(); logText = string.Format("Relative account tag {0} value was adjusted from {1} to ", highestAccountTag.No, highestAccountTag.RelativeValue.ToString("0.#########")); highestAccountTag.RelativeValue -= diff; if (diff > 0) { logText += highestAccountTag.RelativeValue.ToString("0.#########") + "."; logItems.Add(new LogItem(CurrentApplication.UserNo, verificationNo, account.No, LogItemType.AccountTagRecalculated, logText, CurrentApplication.DateTimeNow)); } } } } else if (tagHandlerAction == TagHandlerAction.Split) { // Do nothing - alla account tag percent values are still correct } else { throw new NotImplementedException("TagType action " + tagHandlerAction + " is not implemented."); } decimal totalUntaggedAndRelativeAmount = account.BalanceBroughtForwardAmount + account.Balance - totalAbsoluteAmount; // Some validation if (amount < 0) { if (tagHandlerAction == TagHandlerAction.Specified) { if (Math.Abs(amount) > currentAccountTag.Amount) { if (currentAccountTag.Type == AccountTagType.ExactAmount) { throw new MoneyTagException( "Uttaget kan inte genomföras eftersom dess värde överstiger värdet för den valda märkningen som tillåter en transaktion på " + currentAccountTag.Amount.ToString(CurrentApplication.MoneyDisplayFormat) + " kr. Om du vill genomföra transaktionen måste du först ändra på märkningen."); } else // If relative amount { // Om det finns flera relativa kontotaggar med tillräckligt värde på så är det ok, annars inte. if (Math.Abs(amount) > totalUntaggedAndRelativeAmount) { throw new MoneyTagException( "Uttaget kan inte genomföras eftersom dess värde överstiger värdet för samtliga relativa märkningar inklusive omärkt belopp på " + totalUntaggedAndRelativeAmount.ToString(CurrentApplication.MoneyDisplayFormat) + " kr. Om du vill genomföra transaktionen måste du först ändra på märkningen."); } } } } else { if (tagHandlerAction == TagHandlerAction.Split) { if (Math.Abs(amount) > account.Balance + account.BalanceBroughtForwardAmount) { throw new MoneyTagException( "Uttaget kan inte genomföras eftersom dess värde överstiger det totala värdet för alla relativa märkningar (" + totalUntaggedAndRelativeAmount.ToString(CurrentApplication.MoneyDisplayFormat) + " kr). Om du vill genomföra transaktionen måste du först ändra på märkningen."); } } } } if (account.BalanceBroughtForwardAmount + account.Balance < 0 || account.Type == AccountType.Debt) { if (tagHandlerAction != TagHandlerAction.Untagged) { throw new MoneyTagException( "Du kan inte välja en märkning på ett skuldkonto eller på ett konto med negativt belopp."); } } }
public void passing_an_object_that_is_not_an_AccountViewModel_to_DeleteAccount_method_causes_an_exception() { var accountTag = new AccountTag(1, "HSBC current"); Assert.Throws<ArgumentException>(() => _accountMaintenenceViewModel.DeleteAccount(accountTag, null)); }
/// <summary> /// Function used to Add/Update Account information /// </summary> /// <param name="accountModel"></param> public void AddUpdateAccount(AccountModel accountModel) { Account account = new Account(); if (accountModel.ParentAccountId == 0) { accountModel.ParentAccountId = null; } if (accountModel.AccountTypeId == 0) { accountModel.AccountTypeId = null; } if (accountModel.IndustryId == 0) { accountModel.IndustryId = null; } //if account id is 0 then account will be added if (accountModel.AccountId == 0) { AutoMapper.Mapper.Map(accountModel, account); account.CreatedDate = DateTime.UtcNow; account.ModifiedDate = DateTime.UtcNow; account.Address = ValidateAddress(account.Address, accountModel.AddressModel); account.Address1 = ValidateAddress(account.Address1, accountModel.AddressModel1); accountRepository.Insert(account); } else //if account id is not 0 then account will be updated { account = accountRepository.SingleOrDefault(x => x.AccountId == accountModel.AccountId); // Created by and CreatedDate will not change during mapping accountModel.CreatedBy = account.CreatedBy; accountModel.CreatedDate = account.CreatedDate; AutoMapper.Mapper.Map(accountModel, account); account.ModifiedDate = DateTime.UtcNow; account.Address = ValidateAddress(account.Address, accountModel.AddressModel); account.Address1 = ValidateAddress(account.Address1, accountModel.AddressModel1); accountRepository.Update(account); } List <int> listAllExistingTagIds = new List <int>(); List <int> listNewTagIds = new List <int>(); List <int> listContactAssociatedTagIds = new List <int>(); List <int> listDeleteTagIds = new List <int>(); listContactAssociatedTagIds = account.AccountTags.Select(x => x.TagId).ToList(); if (!string.IsNullOrEmpty(accountModel.AccountTagIds)) { string[] arrTagIds = accountModel.AccountTagIds.Split(','); for (int i = 0; i < arrTagIds.Length; i++) { int tagId = arrTagIds[i].Decrypt(); if (listContactAssociatedTagIds.Where(x => x == tagId).Count() == 0) { listNewTagIds.Add(tagId); } else { listAllExistingTagIds.Add(tagId); } } } if (!string.IsNullOrEmpty(accountModel.NewTagNames)) { List <int> lisNewAddedTagIds = new List <int>(); lisNewAddedTagIds = AddTagsToSystem(accountModel.NewTagNames, accountModel.CompanyId, accountModel.CreatedBy.Value); if (lisNewAddedTagIds.Count > 0) { listNewTagIds = listNewTagIds.Concat(lisNewAddedTagIds).ToList(); } } for (int i = 0; i < listContactAssociatedTagIds.Count; i++) { if (listAllExistingTagIds.Where(x => x == listContactAssociatedTagIds[i]).Count() == 0) { listDeleteTagIds.Add(listContactAssociatedTagIds[i]); } } //Associate Tagids to contact if (listNewTagIds.Count > 0) { AccountTag accountTag; for (int i = 0; i < listNewTagIds.Count; i++) { accountTag = new AccountTag(); accountTag.AccountId = account.AccountId; accountTag.TagId = listNewTagIds[i]; accountTagRepository.Insert(accountTag); } } if (listDeleteTagIds.Count > 0) { accountTagRepository.Delete(x => x.AccountId == account.AccountId && listDeleteTagIds.Contains(x.TagId)); } }
public void passing_an_object_that_is_not_an_TransactionViewModel_to_DeleteTransaction_method_causes_an_exception() { SetUpValidJournalVM(); var accountTag = new AccountTag(1, "HSBC current"); Assert.Throws<ArgumentException>(() => _vm.DeleteTransaction(null, null)); Assert.Throws<ArgumentException>(() => _vm.DeleteTransaction(accountTag, null)); }
public void can_remove_an_AccountTag_from_an_Account_by_calling_RemoveAccountTag_method() { var tag1 = new AccountTag(1, "Entertainment"); var tag2 = new AccountTag(2, "Food"); var tag3 = new AccountTag(3, "Services"); var account = new Account(1, "HSBC current", AccountType.Asset); account.AddTag(tag1); account.AddTag(tag2); account.AddTag(tag3); var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository); vm.PropertyChanged += _changeCounter.HandlePropertyChange; ObservableCollection<AccountTagViewModel> tagVMs = vm.AccountTags; var tagVMToRemove = tagVMs.First(x => x.TagName == "Food"); Expect.Once.On(_mockAccountRepository).Method("Save").With(account); vm.RemoveAccountTag(tagVMToRemove, null); var tagIdsInViewModel = tagVMs.Select(x => x.TagId).ToList(); Assert.AreEqual(2, tagVMs.Count); Assert.IsFalse(tagIdsInViewModel.Contains(2)); Assert.IsTrue(tagIdsInViewModel.Contains(1)); Assert.IsTrue(tagIdsInViewModel.Contains(3)); Assert.AreEqual(1, _changeCounter.NoOfPropertiesChanged); Assert.AreEqual(1, _changeCounter.TotalChangeCount); Assert.AreEqual(1, _changeCounter.ChangeCount("AccountTags")); _mocks.VerifyAllExpectationsHaveBeenMet(); }
public void can_set_id_to_zero_when_creating_AccountTags_but_then_IsValid_is_false() { var accountTag = new AccountTag(0, "Holiday"); Assert.AreEqual(0, accountTag.Id); Assert.IsFalse(accountTag.IsValid); }
public void inserting_AccountTag_with_same_name_as_existing_AccountTag_causes_AccountTagAlreadyExistsException() { var existingTag = _repository.GetById(2); var newTag = new AccountTag(2000, existingTag.Name); Assert.Throws<EntityAlreadyExistsException>(() => _repository.Save(newTag)); }
public void when_validation_of_accountTags_Name_setter_fails_the_name_is_not_updated() { bool validatorCalled = false; var tag = new AccountTag(3, "Tax free Savings"); tag.NameChanged += ((s, a) => { validatorCalled = true; throw new EntityAlreadyExistsException(); }); Assert.Throws<EntityAlreadyExistsException>(() => tag.Name = "ISAs"); Assert.AreEqual("Tax free Savings", tag.Name); Assert.IsTrue(validatorCalled); }
public void TagId_property_returns_tags_id() { var tag = new AccountTag(122, "Misc expenses"); var vm = new AccountTagViewModel(tag, _mockAccountTagRepository); Assert.AreEqual(122, vm.TagId); }