示例#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);
            }
        }