Exemple #1
0
        public void CreateANewExpense()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CreateANewExpense))//
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var     expenseService = new ExpenseService(context);
                Expense expense        = new Expense();
                User    user           = new User
                {
                    Username = "******"
                };
                var create = new Lab2.DTOs.PostExpenseDto
                {
                    Description = "Read1",
                    Sum         = 3,
                    Location    = "Read1",
                    Date        = DateTime.Now.AddDays(15),
                    Currency    = "ADF",
                    Type        = "FOOD",
                    // ClosedAt = null,
                    // Importance = "Medium",
                    // State = "InProgress",
                    Comments = expense.Comments
                };
                var result = expenseService.Create(create, user);
                Assert.NotNull(result);
                Assert.AreEqual(create.Description, result.Description);
            }
        }
Exemple #2
0
        public void UpdateExistingExpense()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpdateExistingExpense))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var expenseService       = new ExpenseService(context);
                var resultPostExpenseDto = new Lab2.DTOs.PostExpenseDto

                {
                    Description = "Read3",
                    Sum         = 3,
                    Location    = "Read3",
                    Date        = DateTime.Now,
                    Currency    = "ADF",
                    Type        = "FOOD",
                    Comments    = null
                };

                var user = new User
                {
                    FullName  = "Baggings",
                    Email     = "*****@*****.**",
                    Username  = "******",
                    Password  = "******",
                    CreatedAt = DateTime.Now
                };
                var lalala = expenseService.Create(resultPostExpenseDto, user);

                List <Comment> comments = new List <Comment>();
                Comment        comment  = new Comment
                {
                    Id        = 1,
                    Text      = "One Ring to Rule them All",
                    Important = true
                };
                comments.Add(comment);

                var dateDeadline = DateTime.Now.AddDays(20);

                var resultExpense = new Expense
                {
                    Description = "Read4",
                    Sum         = 3,
                    Location    = "Read4",
                    Date        = DateTime.Now,
                    Currency    = "ADF",
                    Comments    = null
                };
                context.Entry(lalala).State = EntityState.Detached;


                Assert.AreEqual(resultExpense.Location, "Read4");
                Assert.AreEqual(resultExpense.Description, "Read4");
                Assert.AreEqual(resultExpense.Currency, "ADF");
                Assert.AreEqual(resultExpense.Comments, null);
            }
        }
        public static Expense ModelFromDto(PostExpenseDto expenseDto)
        {
            TypeEnum type = TypeEnum.Other;

            if (expenseDto.Type == "Food")
            {
                type = TypeEnum.Food;
            }
            else if (expenseDto.Type == "Utilities")
            {
                type = TypeEnum.Utilities;
            }
            else if (expenseDto.Type == "Transportation")
            {
                type = TypeEnum.Transportation;
            }
            else if (expenseDto.Type == "Outing")
            {
                type = TypeEnum.Outing;
            }
            else if (expenseDto.Type == "Groceries")
            {
                type = TypeEnum.Groceries;
            }
            else if (expenseDto.Type == "Clothes")
            {
                type = TypeEnum.Clothes;
            }
            else if (expenseDto.Type == "Electronics")
            {
                type = TypeEnum.Electronics;
            }
            return(new Expense
            {
                Description = expenseDto.Description,
                Sum = expenseDto.Sum,
                Location = expenseDto.Location,
                Date = expenseDto.Date,
                Currency = expenseDto.Currency,
                Type = type,
                Comments = expenseDto.Comments
            });
        }
Exemple #4
0
        public void DeleteExistingExpense()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteExistingExpense))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var  expenseService = new ExpenseService(context);
                User user           = new User
                {
                    Username = "******"
                };
                var result = new Lab2.DTOs.PostExpenseDto

                {
                    //Added = DateTime.Now,
                    // Deadline = DateTime.Now.AddDays(15),
                    // ClosedAt = null,

                    Description = "Read1",
                    Sum         = 3,
                    Location    = "Read1",
                    Date        = DateTime.Now.AddDays(15),
                    Currency    = "ADF",
                    Type        = "FOOD",
                    // ClosedAt = null,
                    // Importance = "Medium",
                    // State = "InProgress",
                    Comments = null
                };
                Expense saveexpense = expenseService.Create(result, user);
                expenseService.Delete(saveexpense.Id);

                Assert.IsNull(expenseService.GetById(saveexpense.Id));
            }
        }