Ejemplo n.º 1
0
        public void UpdateSpecificExpenseShouldModifyGivenExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpdateSpecificExpenseShouldModifyGivenExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var toAddExpense = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                };
                var addedExpense = expenseService.AddExpense(toAddExpense);

                // new modified expense
                var toUpdatedExpense = new ExpensesPostModel()
                {
                    Description = "Test description updated",
                    Sum         = 30,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "An updated test comment",
                            Important = true
                        }
                    }
                };
                var updatedExpense = expenseService.UpsertExpense(addedExpense.Id, toUpdatedExpense);


                Assert.IsNotNull(updatedExpense);
                Assert.AreEqual(toUpdatedExpense.Description, updatedExpense.Description);
                Assert.AreEqual(toUpdatedExpense.Sum, updatedExpense.Sum);
                Assert.AreEqual(toUpdatedExpense.Location, updatedExpense.Location);
                Assert.AreEqual(toUpdatedExpense.Date, updatedExpense.Date);
                Assert.AreEqual(toUpdatedExpense.Currency, updatedExpense.Currency);
                Assert.AreEqual(toUpdatedExpense.Type, updatedExpense.Type.ToString());
                Assert.AreEqual(toUpdatedExpense.Comments, updatedExpense.Comments);
            }
        }
Ejemplo n.º 2
0
        public void AddExpenseWithInvalidTypeFieldShouldNotCreateANewExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AddExpenseWithInvalidTypeFieldShouldNotCreateANewExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var expected = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Invalid Type",
                    Comments    = null
                };

                var actual = expenseService.AddExpense(expected);

                Assert.IsNull(actual);
            }
        }
Ejemplo n.º 3
0
        public void GetExpenseByInvalidIdShouldNotFindAnyExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetExpenseByInvalidIdShouldNotFindAnyExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var toAddExpense = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                };

                var actual = expenseService.AddExpense(toAddExpense);

                var expected = expenseService.GetExpenseById(55555);

                Assert.IsNull(expected);
            }
        }
Ejemplo n.º 4
0
        public void DeleteValidExpenseShouldDeleteExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteValidExpenseShouldDeleteExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var expected = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Food",
                    Comments    = null
                };
                // add the expense to db
                var actual = expenseService.AddExpense(expected);
                // delete expense and put return expense in obj
                var afterDelete = expenseService.DeleteExpense(actual.Id);
                // search for the added expense to see if exists in db
                var result = context.Expensess.Find(actual.Id);

                Assert.IsNotNull(afterDelete);
                Assert.IsNull(result);
            }
        }
Ejemplo n.º 5
0
        public void GetCommentsFilteredByValueShouldReturnAListOfFilteredComments()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetCommentsFilteredByValueShouldReturnAListOfFilteredComments))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var commentsService = new CommentsService(context);
                var expensesService = new ExpensesService(context);

                var expenseWithCommentToAdd = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 1 filtered",
                            Important = false
                        },
                        new Comment()
                        {
                            Text      = "A test comment 2 filtered",
                            Important = true
                        },
                        new Comment()
                        {
                            Text      = "A test comment 3",
                            Important = false
                        }
                    }
                };
                expensesService.AddExpense(expenseWithCommentToAdd);

                List <CommentGetModel> comments = commentsService.GetAll("filtered");
                int numberOfComments            = comments.Count;

                Assert.IsNotNull(comments);
                Assert.AreEqual(2, numberOfComments);
            }
        }
Ejemplo n.º 6
0
        public void DeleteValidExpenseWithCommentsShouldDeleteExpenseAndComments()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteValidExpenseWithCommentsShouldDeleteExpenseAndComments))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var expected = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                };
                // add the expense to db
                var actual = expenseService.AddExpense(expected);
                // delete expense and put return expense in obj
                var afterDelete = expenseService.DeleteExpense(actual.Id);
                // find the number of comments that exists in db
                int numberOfCommentsInDb = context.Comments.CountAsync().Result;
                // search for the added expense to see if exists in db
                var resultExpense = context.Expensess.Find(actual.Id);

                Assert.IsNotNull(afterDelete);
                Assert.IsNull(resultExpense);
                Assert.AreEqual(0, numberOfCommentsInDb);
            }
        }
Ejemplo n.º 7
0
        public void AddAValidExpenseShouldCreateANewExpense()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AddAValidExpenseShouldCreateANewExpense))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                var expenseService = new ExpensesService(context);

                var expected = new ExpensesPostModel()
                {
                    Description = "Test description",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Utilities",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                };

                var actual = expenseService.AddExpense(expected);

                Assert.IsNotNull(actual);
                Assert.AreEqual(expected.Description, actual.Description);
                Assert.AreEqual(expected.Sum, actual.Sum);
                Assert.AreEqual(expected.Location, actual.Location);
                Assert.AreEqual(expected.Date, actual.Date);
                Assert.AreEqual(expected.Currency, actual.Currency);
                Assert.AreEqual(expected.Type, actual.Type.ToString());
                Assert.AreEqual(expected.Comments, actual.Comments);
            }
        }
Ejemplo n.º 8
0
        public void CheckExpensesOnPaginatedListShouldReturnAllExpenseOnAPage()
        {
            var options = new DbContextOptionsBuilder <DataDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CheckExpensesOnPaginatedListShouldReturnAllExpenseOnAPage))
                          .Options;

            using (var context = new DataDbContext(options))
            {
                // declare service
                var expenseService = new ExpensesService(context);

                // add 5 expenses, for 2 pages with 3 expenses on a PaginatedList
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 1",
                    Sum         = 20,
                    Location    = "Cluj",
                    Date        = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "RON",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment",
                            Important = false
                        }
                    }
                });
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 2",
                    Sum         = 20,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 2",
                            Important = false
                        }
                    }
                });
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 2",
                    Sum         = 20,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 2",
                            Important = false
                        }
                    }
                });
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 2",
                    Sum         = 20,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 2",
                            Important = false
                        }
                    }
                });
                expenseService.AddExpense(new ExpensesPostModel()
                {
                    Description = "Test description 2",
                    Sum         = 20,
                    Location    = "Brasov",
                    Date        = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                    Currency    = "Euro",
                    Type        = "Food",
                    Comments    = new List <Comment>()
                    {
                        new Comment()
                        {
                            Text      = "A test comment 2",
                            Important = false
                        }
                    }
                });

                // set the page number
                int Page = 1;
                PaginatedList <ExpensesGetModel> actual =
                    expenseService.GetAllExpenses(Page,
                                                  DateTime.ParseExact("04/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                                  DateTime.ParseExact("06/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                                  TaskWork.Models.Type.Food);

                // check if something is returned and number of expenses on the first page
                Assert.IsNotNull(actual);
                Assert.AreEqual(3, actual.Entries.Count);

                // set the page number
                Page = 2;
                PaginatedList <ExpensesGetModel> actual2 =
                    expenseService.GetAllExpenses(Page,
                                                  DateTime.ParseExact("04/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                                  DateTime.ParseExact("06/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                                  TaskWork.Models.Type.Food);

                // check if something is returned and number of expenses on on the second page
                Assert.IsNotNull(actual2);
                Assert.AreEqual(2, actual2.Entries.Count);
            }
        }