Пример #1
0
        public void GetAllShouldReturnCorrectNumberOfPages()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPages))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                // var commentService = new CommentService(context);
                var expenseService = new ExpenseService(context);
                var addedFlower    = expenseService.Create(new Lab2Expense.ViewModels.ExpensePostModel
                {
                    Description = "jshdkhsakjd",
                    Sum         = 1.23,
                    Location    = "jsfkdsf",
                    Date        = new DateTime(),
                    Currency    = "euro",
                    ExpenseType = "food",

                    Comments = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "asd",
                            Owner     = null
                        }
                    },
                }, null);

                var allComments = expenseService.GetAll(1);
                Assert.NotNull(allComments);
            }
        }
        public async Task GetAll()
        {
            using var service = new ExpenseService();
            var result = await service.GetAll();

            // TODO: Add additional checks
            Assert.IsNotNull(result);
            result.ToList().ForEach((item) =>
            {
                Assert.That(item.Month > 0);
                Assert.That(!string.IsNullOrEmpty(item.CategoryName));
                Assert.That(!string.IsNullOrEmpty(item.SourceName));
            });
        }
Пример #3
0
        public void GetAll()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CreateANewExpense))// "CreateANewTask")
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expenseService = new ExpenseService(context);

                User user = new User
                {
                    Username = "******"
                };

                PostExpenseDto expense = new PostExpenseDto
                {
                    Description = "tdssgafgadfla"
                };
                PostExpenseDto expense2 = new PostExpenseDto
                {
                    Description = "Alallalalalaal"
                };
                PostExpenseDto expense3 = new PostExpenseDto
                {
                    Description = "fdsjgaoidsfhgasidl"
                };
                expenseService.Create(expense, user);
                expenseService.Create(expense2, user);
                expenseService.Create(expense3, user);
                var populated = expenseService.GetAll(1);
                var empty     = expenseService.GetAll(2);
                Assert.AreEqual(4, populated.Entries.Count);
                Assert.Zero(empty.Entries.Count);
            }
        }
Пример #4
0
        public void TestGetAll()
        {
            var expenses = new List <Expense> {
                new Expense {
                    Id = 1
                }
            };
            var mockContext = new Mock <TestContext>();

            mockContext.Setup(p => p.Set <Expense>()).ReturnsDbSet(expenses);
            var service = new ExpenseService(mockContext.Object);

            var result = service.GetAll();

            Assert.Equal(1, result.Count);
        }
Пример #5
0
        public ActionResult GetAllByWallet(long idWallet)
        {
            try
            {
                //Pegando o id do usuario pelo token
                long?idUser = GetIdUser();

                if (idUser is null)
                {
                    return(NotFound("Usuário não encontrado!"));
                }

                var response = _expenseService.GetAll(Convert.ToInt64(idUser), idWallet);

                return(SetResponse(response));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #6
0
        public void GetAllShouldReturnCorrectNumberOfPagesForExpenses()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForExpenses))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expenseService = new ExpenseService(context);
                var added          = expenseService.Create(new LabII.DTOs.ExpensePostModel

                {
                    Description = "Variable",
                    Type        = "5",
                    Location    = "Sibiu",
                    Date        = Convert.ToDateTime("2019-05-05T11:11:11"),
                    Currency    = "USD",
                    Sum         = 555.77,
                    Comments    = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "Very important expense",
                            Owner     = null
                        }
                    },
                }, null);

                DateTime from = DateTime.Parse("2019-04-13T00:00:00");
                DateTime to   = DateTime.Parse("2019-06-19T00:00:00");

                var allExpenses = expenseService.GetAll(1, from, to);
                Assert.AreEqual(1, allExpenses.Entries.Count);
                Assert.IsNotNull(allExpenses);
            }
        }
Пример #7
0
 public async Task OnGet()
 {
     Expenses = await _service.GetAll(1);
 }
Пример #8
0
 // GET: Expenses
 public async Task <IActionResult> Index()
 {
     return(View(await _service.GetAll()));
 }
Пример #9
0
        public void CheckPaginatedListShouldReturnAllExpenseOnAPage()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CheckPaginatedListShouldReturnAllExpenseOnAPage))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                // declare service
                var expenseService = new ExpenseService(context);

                // add 6 expenses, for 2 pages with 5 expenses on a PaginatedList
                expenseService.Create(new Labo2.ViewModels.ExpensePostModel()
                {
                    Description = "Expense for test",
                    Sum         = 34,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("07/11/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "Comment test for expense",
                            Important = false
                        }
                    }
                }, null);
                expenseService.Create(new Labo2.ViewModels.ExpensePostModel()
                {
                    Description = "Expense2 for test",
                    Sum         = 34,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("07/10/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "Comment2 test for expense",
                            Important = false
                        }
                    }
                }, null);
                expenseService.Create(new Labo2.ViewModels.ExpensePostModel()
                {
                    Description = "Expense3 for test",
                    Sum         = 34,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("07/10/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "USD",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "Comment3 test for expense",
                            Important = false
                        }
                    }
                }, null);
                expenseService.Create(new Labo2.ViewModels.ExpensePostModel()
                {
                    Description = "Expense4 for test",
                    Sum         = 34,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("07/10/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "EURO",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "Comment4 test for expense",
                            Important = false
                        }
                    }
                }, null);
                expenseService.Create(new Labo2.ViewModels.ExpensePostModel()
                {
                    Description = "Expense5 for test",
                    Sum         = 34,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("07/10/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "EURO",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "Comment5 test for expense",
                            Important = false
                        }
                    }
                }, null);
                expenseService.Create(new Labo2.ViewModels.ExpensePostModel()
                {
                    Description = "Expense6 for test",
                    Sum         = 34,
                    Location    = "Oradea",
                    Date        = DateTime.ParseExact("07/10/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "EURO",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "Comment6 test for expense",
                            Important = false
                        }
                    }
                }, null);


                // setez nr paginii
                int Page = 1;
                PaginatedList <ExpenseGetModel> actual =
                    expenseService.GetAll(Page,
                                          DateTime.ParseExact("07/09/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                          DateTime.ParseExact("09/11/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                          Labo2.Models.Type.Utilities);

                // verific daca e ceva returnat si numarul de expenses pe pagina
                Assert.IsNotNull(actual);
                Assert.AreEqual(5, actual.Entries.Count);

                //  setez nr paginii
                Page = 2;
                PaginatedList <ExpenseGetModel> actual2 =
                    expenseService.GetAll(Page,
                                          DateTime.ParseExact("07/09/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                          DateTime.ParseExact("09/11/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                          Labo2.Models.Type.Utilities);

                // verific daca e ceva returnat si numarul de expenses pe pagina 2
                Assert.IsNotNull(actual2);
                Assert.AreEqual(1, actual2.Entries.Count);
            }
        }
Пример #10
0
 public List <Expense> Get()
 {
     return(_service.GetAll().ConfigureAwait(false).GetAwaiter().GetResult());
 }