Exemplo n.º 1
0
        public async Task AddExpense_WhenAddingDuplicatedExpenseWithoutComment_ShouldThrowAnExceptionWithTheCorrectErrorCode()
        {
            // Arrange
            var dtoExpense1 = new DTOExpense()
            {
                Amount = (decimal)1457.23, Category = "Restaurant", Comment = "A comment", Currency = "USD", PurchasedOn = this.currentTime.AddDays(-1), UserId = anthonyUser.Id
            };

            await this.expensesService.AddExpense(dtoExpense1);

            var dtoExpense2 = new DTOExpense()
            {
                Amount = (decimal)1457.23, Category = "Restaurant", Comment = "", Currency = "USD", PurchasedOn = this.currentTime.AddDays(-1), UserId = anthonyUser.Id
            };

            // Act
            Func <Task> addExpense = () => this.expensesService.AddExpense(dtoExpense2);

            // Assert
            ExpenseValidationException ex = await Assert.ThrowsAsync <ExpenseValidationException>(addExpense);

            var errorCodes = ex.GetErrorCodes();

            errorCodes.Should().HaveCount(2);
            errorCodes.Should().Contain(ExpenseErrorCode.DuplicatedExpense);
            errorCodes.Should().Contain(ExpenseErrorCode.CommentIsMandatory);
        }
Exemplo n.º 2
0
        public async Task AddExpense_WhenPurchaseMoreThan3MonthAgo_ShouldThrowAnExceptionWithTheCorrectErrorCode()
        {
            // Arrange
            var dtoExpense = new DTOExpense()
            {
                Amount = (decimal)10.23, Category = "Restaurant", Comment = "A comment", Currency = "USD", PurchasedOn = this.currentTime.AddDays(-100), UserId = anthonyUser.Id
            };

            // Act
            Func <Task> addExpense = () => this.expensesService.AddExpense(dtoExpense);

            // Assert
            ExpenseValidationException ex = await Assert.ThrowsAsync <ExpenseValidationException>(addExpense);

            var errorCodes = ex.GetErrorCodes();

            errorCodes.Should().HaveCount(1);
            errorCodes.First().Should().Be(ExpenseErrorCode.PurchaseMoreThan3MonthOld);
        }