public void CreateShouldAddAndReturnTheCreatedExpense()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CreateShouldAddAndReturnTheCreatedExpense))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var taskService = new ExpensesService(context);
                var added       = taskService.Create(new Lab6.Viewmodels.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);


                Assert.IsNotNull(added);
                Assert.AreEqual("Variable", added.Description);
                Assert.AreNotEqual("Fixed", added.Description);
            }
        }
        public void UpsertShouldModifyTheGivenExpense()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldModifyTheGivenExpense))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expenseService = new ExpensesService(context);
                var added          = new 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
                        }
                    },
                };

                var toAdd  = expenseService.Create(added, null);
                var update = new ExpensePostModel()
                {
                    Description = "Variable-Updated"
                };

                var toUp         = expenseService.Create(update, null);
                var updateResult = expenseService.Upsert(toUp.Id, toUp);


                Assert.IsNotNull(updateResult);
                Assert.AreEqual(toUp.Description, updateResult.Description);
            }
        }
        public void GetByIdShouldReturnExpenseWithCorrectId()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnExpenseWithCorrectId))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expenseService = new ExpensesService(context);
                var added          = new 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
                        }
                    },
                };

                var current  = expenseService.Create(added, null);
                var expected = expenseService.GetById(current.Id);

                Assert.IsNotNull(expected);
                Assert.AreEqual(expected.Description, current.Description);
                Assert.AreEqual(expected.Location, current.Location);
                Assert.AreEqual(expected.Sum, current.Sum);
                Assert.AreEqual(expected.Id, current.Id);
            }
        }
        public void DeleteExpenseWithCommentsShouldDeleteExpenseAndComments()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteExpenseWithCommentsShouldDeleteExpenseAndComments))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expensesService = new ExpensesService(context);

                var expected = new 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
                        }
                    },
                };

                var actual               = expensesService.Create(expected, null);
                var afterDelete          = expensesService.Delete(actual.Id);
                int numberOfCommentsInDb = context.Comments.CountAsync().Result;
                var resultExpense        = context.Expenses.Find(actual.Id);

                Assert.IsNotNull(afterDelete);
                Assert.IsNull(resultExpense);
                Assert.AreEqual(0, numberOfCommentsInDb);
            }
        }
        public void GetAllShouldReturnCorrectNumberOfPagesForExpenses()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForExpenses))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expenseService = new ExpensesService(context);
                var added          = expenseService.Create(new Lab6.Viewmodels.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);
            }
        }
Beispiel #6
0
        public void GetAllShouldReturnCorrectNumberOfPagesForComments()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForComments))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var taskService    = new ExpensesService(context);
                var commentService = new CommentsService(context);
                var added          = new 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      = "An important expense",
                            Owner     = null
                        }
                    },
                };

                var current = taskService.Create(added, null);

                var allComments = commentService.GetAll(string.Empty, 1);
                Assert.AreEqual(1, allComments.NumberOfPages);
            }
        }
 public void Post([FromBody] ExpenseDTO expense)
 {
     expensesService.Create(expense);
 }