コード例 #1
0
        public Result <Expenses> Get(int id, int plannerId)
        {
            var             result          = new Result <Expenses>();
            ExpensesService ExpensesService = new ExpensesService();

            result.Value     = ExpensesService.GetById(id, plannerId);
            result.IsSuccess = true;
            return(result);
        }
コード例 #2
0
        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);
            }
        }