コード例 #1
0
        public void ListOrderedByUserId()
        {
            // Arrange
            using (SpendingContext spendingContext = new SpendingContext())
            {
                SpendingRepository spendingRepository = new SpendingRepository(spendingContext);
                SpendingController sut = new SpendingController(spendingRepository);

                // Act
                ObjectResult actionResult = sut.ListByUserId(1, "Date") as ObjectResult;


                // Assert
                IEnumerable <SpendingDto> spendings = (IEnumerable <SpendingDto>)actionResult.Value;
                Assert.Empty(spendings);
            }
        }
コード例 #2
0
        public void ListOrderedWithWrongOrderBy_Fails()
        {
            string wrongOrderBy = "loki";

            // Arrange
            using (SpendingContext spendingContext = new SpendingContext())
            {
                SpendingRepository spendingRepository = new SpendingRepository(spendingContext);
                SpendingController sut = new SpendingController(spendingRepository);

                // Act
                BadRequestResult actionResult = sut.ListByUserId(1, wrongOrderBy) as BadRequestResult;

                // Assert
                Assert.Equal(400, actionResult.StatusCode);
            }
        }
コード例 #3
0
        public void AddSpendingAndListIt()
        {
            // Arrange
            using (SpendingContext spendingContext = new SpendingContext())
            {
                SpendingRepository spendingRepository = new SpendingRepository(spendingContext);
                SpendingController sut = new SpendingController(spendingRepository);

                // Act
                IStatusCodeActionResult actionResult = sut.AddSpending(1, DateTime.UtcNow.AddDays(-1), 100, "USD", "Misc", "Armor") as IStatusCodeActionResult;

                // Assert
                Assert.Equal(200, actionResult.StatusCode);
                ObjectResult listResult             = sut.ListByUserId(1, "Date") as ObjectResult;
                IEnumerable <SpendingDto> spendings = (IEnumerable <SpendingDto>)listResult.Value;
                Assert.Single(spendings);
            }
        }