public void GivenEmptyContext_WhenClassificationRuleIsAddedAndSave_ThenCanBeLoaded() { //Given var saveContext = GetNewContext(); //When var repo = saveContext.GetRepository<IRepository<ClassificationDefinition>>(); ClassificationDefinition def = new ClassificationDefinition(); def.Category = "Cat"; def.Description = "Desc"; def.SubCategory = "Sub"; def.Rules.Add(new ClassificationRule() { RegularExpression = "Test1" }); def.Rules.Add(new ClassificationRule() { RegularExpression = "Test2", Account = "Acc1" }); def.Rules.Add(new ClassificationRule() { RegularExpression = "Test3", CounterAccount = "Acc2" }); repo.Add(def); saveContext.SaveChanges(); //Then var loadContext = GetNewContext(); var repoLoad = saveContext.GetRepository<IRepository<ClassificationDefinition>>(); var loadedDefinition = repoLoad.GetAll().Single(); Assert.AreEqual("Cat", loadedDefinition.Category); Assert.AreEqual("Desc", loadedDefinition.Description); Assert.AreEqual("Sub", loadedDefinition.SubCategory); Assert.AreEqual(3, loadedDefinition.Rules.Count); Assert.AreEqual(1, loadedDefinition.Rules.Count(a => a.RegularExpression == "Test1" && a.Account == null && a.CounterAccount == null)); Assert.AreEqual(1, loadedDefinition.Rules.Count(a => a.RegularExpression == "Test2" && a.Account == "Acc1" && a.CounterAccount == null)); Assert.AreEqual(1, loadedDefinition.Rules.Count(a => a.RegularExpression == "Test3" && a.Account == null && a.CounterAccount == "Acc2")); }
public void OnNavigatedTo(ClassificationDefinition selected, BankOperation templateOperation) { if (selected == null) { EditMode = EditMode.Add; ClassificationDefinition newDefinition = new ClassificationDefinition(); ClassificationRule newRule = new ClassificationRule(); newDefinition.Rules.Add(newRule); if (templateOperation != null) { newDefinition.Category = templateOperation.Category; newDefinition.SubCategory = templateOperation.SubCategory; newRule.RegularExpression = templateOperation.Description; newRule.Account = templateOperation.BankAccount.Number; newRule.CounterAccount = templateOperation.CounterAccount; } Data = newDefinition; } else { EditMode = EditMode.Edit; Data = _definitionsRepository.Get(selected.Id); } }
private void InternalMerge(ClassificationDefinition first, IEnumerable<ClassificationDefinition> selectedDefinitions) { foreach (var item in selectedDefinitions) { if (item != first) { foreach (var rule in item.Rules) { first.Rules.Add(rule); } _definitionsRepository.Delete(item); } } _context.SaveChanges(); OnPropertyChanged(() => Data); }