public void UpsertTransactionCommandHandler_EmptyDbUpsertList_ListSaved()
        {
            //given
            var transactionTypes = new[]
            {
                new TransactionType {
                    Name = "t1", Outcome = true
                }
            };

            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertTransactionTypesCommandHandler(repository);
            var command    = new UpsertTransactionTypesCommand(transactionTypes);

            //when
            handler.Execute(command);

            //then
            var orderedTransactionTypesInDatabase = repository.Database.Query <TransactionType>().OrderBy(x => x.Id).ToArray();
            var orderedTransactionTypes           = transactionTypes.OrderBy(x => x.Id).ToArray();

            Assert.Equal(orderedTransactionTypes, orderedTransactionTypesInDatabase);
            Assert.Equal(orderedTransactionTypes.Select(x => x.Name), orderedTransactionTypesInDatabase.Select(x => x.Name));
            Assert.Equal(orderedTransactionTypes.Select(x => x.Id), orderedTransactionTypesInDatabase.Select(x => x.Id));
            Assert.Equal(orderedTransactionTypes.Select(x => x.IsDefault), orderedTransactionTypesInDatabase.Select(x => x.IsDefault));
            Assert.Equal(orderedTransactionTypes.Select(x => x.Income), orderedTransactionTypesInDatabase.Select(x => x.Income));
            Assert.Equal(orderedTransactionTypes.Select(x => x.Outcome), orderedTransactionTypesInDatabase.Select(x => x.Outcome));
        }
Beispiel #2
0
        public void UpsertTransactionCommandHandler_EmptyDbUpsertOneObject_ObjectSaved()
        {
            //given
            var transactions = new[]
            {
                new Transaction {
                    Notes = new List <string> {
                        "test1"
                    }, Positions = new List <Position> {
                        new Position {
                            Title = "p1"
                        }
                    }
                }
            };

            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertTransactionsCommandHandler(repository);
            var command    = new UpsertTransactionsCommand(transactions);

            //when
            handler.Execute(command);

            //then
            var orderedTransactionsInDatabase = repository.Database.Query <Transaction>().OrderBy(x => x.Id);

            Assert.Equal(transactions.OrderBy(x => x.Id), orderedTransactionsInDatabase);
        }
        public void CategoryQueryHandler_CategoryQueryNotEmptyDatabase_Array()
        {
            //given
            var repository   = LiteDbHelper.CreateMemoryDb();
            var handler      = new CategoryQueryHandler(repository);
            var query        = new CategoryQuery();
            var rootCategory = new Category(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1))
            {
                Name   = "1",
                Parent = null
            };
            var categories = new[]
            {
                rootCategory,
                new Category(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2))
                {
                    Name   = "2",
                    Parent = rootCategory
                }
            };

            repository.Database.GetCollection <Category>().InsertBulk(categories);

            //when
            var result = handler.Execute(query);

            //then
            Assert.Equal(categories, result);
        }
Beispiel #4
0
        public void TransactionTypesQueryHandler_TransactionTypesQueryNotEmptyDatabaseWithQuery_MatchingArray()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new TransactionTypesQueryHandler(repository);
            Expression <Func <TransactionType, bool> > linqQuery = x => x.IsDefault && x.Outcome;
            var query        = new TransactionTypesQuery(linqQuery);
            var transactions = new[]
            {
                new TransactionType {
                    Income = true, IsDefault = true, Name = "income"
                },
                new TransactionType {
                    Outcome = true, IsDefault = true, Name = "outcome"
                },
            };

            repository.Database.GetCollection <TransactionType>().InsertBulk(transactions);
            var matchingTransactions = transactions.AsQueryable().Where(linqQuery).ToArray();

            //when
            var result = handler.Execute(query);

            //then
            Assert.Equal(matchingTransactions.Length, result.Length);
            Assert.Equal(matchingTransactions, result);
        }
Beispiel #5
0
        public void InitApp()
        {
            Players = LiteDbHelper.GetPlayers();

            #region TeamsTab

            teamsPlayerCheckListBox.DataSource    = Players;
            teamsPlayerCheckListBox.DisplayMember = "Name";

            #endregion

            #region PlayersTab

            playersListBox.DataSource    = Players;
            playersListBox.DisplayMember = "Name";
            var ranks = new List <string>();
            foreach (PlayerRank rank in Enum.GetValues(typeof(PlayerRank)))
            {
                ranks.Add(rank.ToString());
            }

            playerRankCombo.DataSource = ranks;

            #endregion
        }
Beispiel #6
0
        public void TransactionQueryHandler_TransactionQueryNotEmptyDatabaseWithQuery_MatchingArray()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new TransactionQueryHandler(repository);
            Expression <Func <Transaction, bool> > linqQuery = x => x.Title.Contains("1");
            var query        = new TransactionQuery(linqQuery);
            var transactions = new[]
            {
                new Transaction(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1))
                {
                    Title = "t1"
                },
                new Transaction(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2))
                {
                    Title = "t2"
                }
            };

            repository.Database.GetCollection <Transaction>().InsertBulk(transactions);
            var matchingTransactions = transactions.AsQueryable().Where(linqQuery).ToArray();

            //when
            var result = handler.Execute(query);

            //then
            Assert.Equal(matchingTransactions.Length, result.Length);
            Assert.Equal(matchingTransactions, result);
        }
Beispiel #7
0
        private async void ExecuteSaveCommand(object obj)
        {
            var loader = await MaterialDialog.Instance.LoadingDialogAsync("Contact du serveur ... ", Configurations.MaterialConfig.MaterialLoadingDialogConfiguration);

            DemandeurIdentite.Id          = LiteDbHelper.CurrentUser.Id;
            DemandeurIdentite.Email       = LiteDbHelper.CurrentUser.Email;
            DemandeurIdentite.Password    = LiteDbHelper.CurrentUser.Password;
            DemandeurIdentite.Telephone   = Code.DialCode + DemandeurIdentite.Telephone;
            DemandeurIdentite.Nationalite = Pays.CountryName;
            //DemandeurIdentite.Naissance = LiteDbHelper.CurrentUser.Naissance;
            var data = DemandeurIdentite;

            try
            {
                await RestService.For <IBackendService>(Configurations.ServerConfig.Host).Update(JsonConvert.SerializeObject(DemandeurIdentite));

                LiteDbHelper.UpdateDataUser(DemandeurIdentite);
                await loader.DismissAsync();

                await Navigation.PushAsync(new HomePage());
            }
            catch (Exception e)
            {
                await loader.DismissAsync();

                if (e is Refit.ApiException)
                {
                    await MaterialDialog.Instance.SnackbarAsync($"{((Refit.ApiException)e).Content}", 3000, Configurations.MaterialConfig.MaterialSnackbarConfigurationError);
                }
                else
                {
                    await MaterialDialog.Instance.SnackbarAsync($"Erreur: {e.Message}", 3000, Configurations.MaterialConfig.MaterialSnackbarConfigurationError);
                }
            }
        }
Beispiel #8
0
        public void StockQueryHandler_StockQueryNotEmptyDatabase_Array()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new StockQueryHandler(repository);
            var query      = new StockQuery();
            var stocks     = new[]
            {
                new CashManager.Data.DTO.Stock(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1))
                {
                    Name        = "1",
                    IsUserStock = true,
                    Balance     = new Balance {
                        Value = 12.34m
                    }
                },
                new CashManager.Data.DTO.Stock(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2))
                {
                    Name        = "2",
                    IsUserStock = false
                }
            };

            repository.Database.GetCollection <CashManager.Data.DTO.Stock>().InsertBulk(stocks);

            //when
            var result = handler.Execute(query);

            //then
            Assert.Equal(stocks, result);
            Assert.Equal(stocks[0].Balance, result[0].Balance);
            Assert.Equal(stocks[0].Balance.Value, result[0].Balance.Value);
        }
Beispiel #9
0
        public void Query_NotEmptyDbFilter_FilteredArray()
        {
            //given
            var repo  = LiteDbHelper.CreateMemoryDb();
            var input = new[]
            {
                new Tag {
                    Name = "a"
                },
                new Tag {
                    Name = "b"
                },
                new Tag {
                    Name = "c"
                },
                new Tag(),
                new Tag(),
            };

            repo.Database.UpsertBulk(input);

            //when
            var result = repo.Database.Query <Tag>(x => !string.IsNullOrEmpty(x.Name));

            //then
            Assert.Equal(input.Where(x => !string.IsNullOrEmpty(x.Name)).OrderBy(x => x.Id), result.OrderBy(x => x.Id));
        }
        public void UpsertStockCommandHandler_EmptyDbUpsertOneObject_ObjectSaved()
        {
            //given
            var stocks = new[]
            {
                new Stock {
                    Name = "test1", Balance = new Balance {
                        Value = 12.45m
                    }
                }
            };

            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertStocksCommandHandler(repository);
            var command    = new UpsertStocksCommand(stocks);

            //when
            handler.Execute(command);

            //then
            var orderedStocksInDatabase = repository.Database.Query <Stock>().OrderBy(x => x.Id).ToArray();

            Assert.Equal(stocks.OrderBy(x => x.Id), orderedStocksInDatabase);
            Assert.Equal(stocks[0].Balance, orderedStocksInDatabase[0].Balance);
            Assert.Equal(stocks[0].Balance.Value, orderedStocksInDatabase[0].Balance.Value);
        }
        public void UpsertStockCommandHandler_EmptyDbUpsertList_ListSaved()
        {
            //given
            var stocks = new[]
            {
                new Stock {
                    Name = "test1"
                },
                new Stock {
                    Name = "test2"
                }
            };

            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertStocksCommandHandler(repository);
            var command    = new UpsertStocksCommand(stocks);

            //when
            handler.Execute(command);

            //then
            var orderedStocksInDatabase = repository.Database.Query <Stock>().OrderBy(x => x.Id);

            Assert.Equal(stocks.OrderBy(x => x.Id), orderedStocksInDatabase);
        }
        public void UpsertCategoriesCommandHandler_EmptyDbUpsertList_ListSaved()
        {
            //given
            var categories = new[]
            {
                new Category {
                    Name = "test1"
                },
                new Category {
                    Name = "test2"
                }
            };

            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertCategoriesCommandHandler(repository);
            var command    = new UpsertCategoriesCommand(categories);

            //when
            handler.Execute(command);

            //then
            var orderedCategoryInDatabase = repository.Database.Query <Category>().OrderBy(x => x.Id);

            Assert.Equal(categories.OrderBy(x => x.Id), orderedCategoryInDatabase);
        }
Beispiel #13
0
        public void TagQueryHandler_TagQueryNotEmptyDatabase_Array()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new TagQueryHandler(repository);
            var query      = new TagQuery();
            var tags       = new[]
            {
                new Tag {
                    Name = "tag1"
                },
                new Tag {
                    Name = "tag2"
                },
                new Tag {
                    Name = "tag3"
                },
                new Tag {
                    Name = "tag4"
                },
                new Tag {
                    Name = "tag5"
                },
            };

            repository.Database.UpsertBulk(tags);

            //when
            var result = handler.Execute(query);

            //then
            Assert.Equal(tags.OrderBy(x => x.Id), result.OrderBy(x => x.Id));
        }
        public void UpsertSearchStateCommandHandler_EmptyDbUpsertListOfNamedObjects_ListSaved()
        {
            //given
            var searchStates = new[]
            {
                new SearchState {
                    Name = "test1"
                },
                new SearchState {
                    Name = "test2"
                }
            };

            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertSearchStateCommandHandler(repository);
            var command    = new UpsertSearchStateCommand(searchStates);

            //when
            handler.Execute(command);

            //then
            var orderedSearchStatesInDatabase = repository.Database.Query <SearchState>().OrderBy(x => x.Id);

            Assert.Equal(searchStates.OrderBy(x => x.Id), orderedSearchStatesInDatabase);
        }
Beispiel #15
0
        public override object Add(string key, object entry, DateTime utcExpiry)
        {
            var item = LiteDbHelper.QueryAll <CacheItem>().Find(q => q.Key == key);

            if (item != null)
            {
                if (item.Expiration <= DateTime.Now)
                {
                    LiteDbHelper.Delete <CacheItem>(item.Id);
                }
                else
                {
                    return(BinarySerializer.Deserialize(item.Entry));
                }
            }


            LiteDbHelper.Add(new CacheItem
            {
                Key         = key,
                Entry       = BinarySerializer.Serialize(entry),
                Expiration  = utcExpiry,
                CreatedDate = DateTime.UtcNow
            });

            return(entry);
        }
Beispiel #16
0
        public override void Remove(string key)
        {
            var item = LiteDbHelper.QueryAll <CacheItem>().Find(q => q.Key == key);

            if (item != null)
            {
                LiteDbHelper.Delete <CacheItem>(item.Id);
            }
        }
Beispiel #17
0
        public void Remove_Null_0()
        {
            //given
            var repo = LiteDbHelper.CreateMemoryDb();

            //when
            int result = repo.Database.Remove <Dto>(null);

            //then
            Assert.Equal(0, result);
        }
Beispiel #18
0
        private void RemovePlayer(Player player)
        {
            LiteDbHelper.DeletePlayer(player);
            var existingPlayer = Players.FirstOrDefault(i => i.Id == player.Id);

            if (existingPlayer != null)
            {
                Players.Remove(existingPlayer);
            }
            SyncPlayerList();
        }
Beispiel #19
0
        public void Query_EmptyDb_Empty()
        {
            //given
            var repo = LiteDbHelper.CreateMemoryDb();

            //when
            var result = repo.Database.Query <Dto>();

            //then
            Assert.Empty(result);
        }
        public void DeleteStockCommandHandler_NullEmptyDb_EmptyDb()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new DeleteStockCommandHandler(repository);
            var command    = new DeleteStockCommand(null);

            //when
            handler.Execute(command);

            //then
            Assert.Empty(repository.Database.Query <Stock>());
        }
Beispiel #21
0
        public void UpsertBulk_Nulls_0()
        {
            //given
            var repo = LiteDbHelper.CreateMemoryDb();

            Dto[] input = { null, null, null };

            //when
            int result = repo.Database.UpsertBulk(input);

            //then
            Assert.Equal(0, result);
        }
Beispiel #22
0
        private void SavePlayer(Player player)
        {
            LiteDbHelper.UpsertPlayer(player);

            var existingPlayer = Players.FirstOrDefault(i => i.Id == player.Id);

            if (existingPlayer != null)
            {
                Players.Remove(existingPlayer);
            }
            Players.Add(player);
            SyncPlayerList();
        }
Beispiel #23
0
        public void Upsert_NotNullNotInDbAlQuery_TrueAndObjectInDb()
        {
            //given
            var repo    = LiteDbHelper.CreateMemoryDb();
            var element = new Dto();

            //when
            bool result = repo.Database.Upsert(element);

            //then
            Assert.True(result);
            Assert.Equal(element, repo.Database.GetCollection <Dto>().FindAll().First());
        }
Beispiel #24
0
        public void DeleteTransactionTypeCommandHandler_NotExisting_NoChange()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new DeleteTransactionTypeCommandHandler(repository);
            var command    = new DeleteTransactionTypeCommand(new TransactionType());

            //when
            handler.Execute(command);

            //then
            Assert.Empty(repository.Database.Query <TransactionType>());
        }
        public void UpsertCategoriesCommandHandler_NullEmptyDb_EmptyDb()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertCategoriesCommandHandler(repository);
            var command    = new UpsertCategoriesCommand((Category)null);

            //when
            handler.Execute(command);

            //then
            Assert.Empty(repository.Database.Query <Category>());
        }
Beispiel #26
0
        public void Remove_ElementInDb_1()
        {
            //given
            var repo  = LiteDbHelper.CreateMemoryDb();
            var input = new[] { new Tag(), new Tag() };

            repo.Database.UpsertBulk(input);

            //when
            int result = repo.Database.Remove(input[0]);

            //then
            Assert.Equal(1, result);
        }
Beispiel #27
0
        public void TransactionQueryHandler_TransactionQueryEmptyDatabase_EmptyArray()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new TransactionQueryHandler(repository);
            var query      = new TransactionQuery();

            //when
            var result = handler.Execute(query);

            //then
            Assert.NotNull(result);
            Assert.Empty(result);
        }
Beispiel #28
0
        public void Query_NotEmptyDb_Same()
        {
            //given
            var repo  = LiteDbHelper.CreateMemoryDb();
            var input = new[] { new Tag(), new Tag() };

            repo.Database.UpsertBulk(input);

            //when
            var result = repo.Database.Query <Tag>();

            //then
            Assert.Equal(input.OrderBy(x => x.Id), result.OrderBy(x => x.Id));
        }
Beispiel #29
0
        public void DeleteCategoryCommandHandler_Existing_Removed()
        {
            //given
            var category   = new Category();
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new DeleteCategoryCommandHandler(repository);
            var command    = new DeleteCategoryCommand(category);

            repository.Database.Upsert(category);

            //when
            handler.Execute(command);

            //then
            Assert.Empty(repository.Database.Query <Category>());
        }
        public void DeleteStockCommandHandler_Existing_Removed()
        {
            //given
            var stock      = new Stock();
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new DeleteStockCommandHandler(repository);
            var command    = new DeleteStockCommand(stock);

            repository.Database.Upsert(stock);

            //when
            handler.Execute(command);

            //then
            Assert.Empty(repository.Database.Query <Stock>());
        }