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); } }
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); } }
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); } }