public void GetCreditCardWithCurrentAndNextBills_NoBillExistingBefore() { // Arrange MonthYear monthYear = MonthYear.Create(2018, 4); int creditCardId = testsUtils.AddSingleCreditCard().Id; var sut = new CreditCardController(new CreditCardRepository(dbUtils.DbContext)); // Act var creditCardList = sut.GetList(monthYear); // Assert Assert.Equal(1, creditCardList.Count); CreditCardBill currentBill = creditCardList.First().GetCurrentBill(monthYear); Assert.True(currentBill.Id > 0); Assert.Equal(TestsUtils.CLOSING_DAY, currentBill.ClosingDay); Assert.Equal(creditCardId, currentBill.CreditCard.Id); Assert.Equal(0, currentBill.Statements.Count); CreditCardBill nextBill = creditCardList.First().GetNextBill(monthYear); Assert.True(nextBill.Id > 0); Assert.Equal(TestsUtils.CLOSING_DAY, nextBill.ClosingDay); Assert.Equal(creditCardId, nextBill.CreditCard.Id); Assert.Equal(0, nextBill.Statements.Count); }
public void ShouldReturnNextMonthYear(int year, int month, int nextYear, int nextMonth) { // Arrange MonthYear monthYear = MonthYear.Create(year, month); // Act MonthYear nextMonthYear = monthYear.GetNextMonthYear(); // Assert Assert.Equal(MonthYear.Create(nextYear, nextMonth), nextMonthYear); }
public void ShouldReturnFirstDayOfMonthYear() { // Arrange MonthYear monthYear = MonthYear.Create(2018, 5); // Act DateTime firstDay = monthYear.GetFirstDay(); // Assert Assert.Equal(DateTime.Parse("2018-05-01"), firstDay); }
public void ShouldBeAValidMonth() { // Arrange var invalidMonth = 13; // Act Action create = () => MonthYear.Create(2018, invalidMonth); // Assert Assert.Throws <ArgumentException>(create); }
public void ShouldBeAValidYear() { // Arrange var invalidYear = 3000; // Act Action create = () => MonthYear.Create(invalidYear, 1); // Assert Assert.Throws <ArgumentException>(create); }
public void ShouldReturnMonthName() { // Arrange string[] possibleNames = new string[] { "janeiro", "january", "January" }; var monthYear = MonthYear.Create(2018, 1); // Act string result = monthYear.GetMonthName(); // Assert Assert.Contains(result, possibleNames); }
private static IDateService MockDateService(DateTime?currentDateTime) { Mock <IDateService> dateServiceMock = new Mock <IDateService>(); if (currentDateTime.HasValue) { DateTime date = currentDateTime.Value; dateServiceMock.Setup(x => x.GetCurrentDateTime()).Returns(date); dateServiceMock.Setup(x => x.GetCurrentMonthYear()).Returns(MonthYear.Create(date.Year, date.Month)); } return(dateServiceMock.Object); }
public void ShouldCompareMonthYears(int year, int month, bool expectedResult) { // Arrange MonthYear monthYear = MonthYear.Create(2018, 12); MonthYear anotherMonthYear = MonthYear.Create(year, month); // Act bool result1 = anotherMonthYear == monthYear; bool result2 = anotherMonthYear.Equals(monthYear); // Assert Assert.Equal(expectedResult, result1); Assert.Equal(expectedResult, result2); }
public void GetCreditCardWithCurrentAndNextBills_RecoveryExistingBills() { // Arrange MonthYear monthYear = MonthYear.Create(2018, 4); DbCreditCardDto creditCard = testsUtils.AddSingleCreditCard(); var bill = new DbCreditCardBillDto() { CreditCardId = creditCard.Id, ClosingDay = TestsUtils.CLOSING_DAY + 1, DueDate = monthYear.GetFirstDay(), CategoryId = creditCard.CategoryId }; dbUtils.Insert(bill); var statement = new DbCreditCardStatementDto() { BillId = bill.Id, Amount = 100m, BuyDate = DateTime.Parse("2018-05-05"), Description = "test credit card statement" }; dbUtils.Insert(statement); var sut = new CreditCardController(new CreditCardRepository(dbUtils.DbContext)); // Act var creditCardList = sut.GetList(monthYear); // Assert Assert.Equal(1, creditCardList.Count); CreditCardBill currentBill = creditCardList.First().GetCurrentBill(monthYear); Assert.Equal(bill.Id, currentBill.Id); Assert.Equal(TestsUtils.CLOSING_DAY + 1, currentBill.ClosingDay); Assert.Equal(creditCard.Id, currentBill.CreditCard.Id); Assert.Equal(1, currentBill.Statements.Count); CreditCardBill nextBill = creditCardList.First().GetNextBill(monthYear); Assert.True(nextBill.Id > 0); Assert.Equal(TestsUtils.CLOSING_DAY, nextBill.ClosingDay); Assert.Equal(creditCard.Id, nextBill.CreditCard.Id); Assert.Equal(0, nextBill.Statements.Count); }
public void GetDate() { // Arrange int year = 2018; int month = 5; int day = 6; MonthYear monthYear = MonthYear.Create(year, month); // Act DateTime result = monthYear.GetDate(day); // Assert Assert.Equal(year, result.Year); Assert.Equal(month, result.Month); Assert.Equal(day, result.Day); }
public void GetBankStatement() { // Arrange testsUtils.CleanAll(); int bankId = testsUtils.AddSingleBank(); dbUtils.Insert(new DbBankStatementDto() { BankId = bankId, Amount = 100, ExecutionDate = DateTime.Parse("2018-03-05") }); dbUtils.Insert(new DbBankStatementDto() { BankId = bankId, Amount = 200, ExecutionDate = DateTime.Parse("2018-04-05") }); dbUtils.Insert(new DbBankStatementDto() { BankId = bankId, Amount = 300, ExecutionDate = DateTime.Parse("2018-05-05") }); var sut = new BankRepository(dbUtils.DbContext); // Act var statementList = sut.GetList(MonthYear.Create(2018, 4)); // Assert Assert.Equal(1, statementList.Count); Assert.Equal(1, statementList.First().BankStatements.Count); Assert.Equal(200m, statementList.First().BankStatements.First().Amount.Value); }
public async Task GetPastPendingStatement() { // Arrange testsUtils.CleanAll(); int categoryId = testsUtils.AddSingleCategory(); dbUtils.Insert(new DbStatementDto() { Amount = 104, CategoryId = categoryId, Direction = 0, DueDate = DateTime.Parse("2018-04-15") }); dbUtils.Insert(new DbStatementDto() { Amount = 204, CategoryId = categoryId, Direction = 0, DueDate = DateTime.Parse("2018-04-20"), Paid = true, PaymentDate = DateTime.Parse("2018-04-20") }); dbUtils.Insert(new DbStatementDto() { Amount = 105, CategoryId = categoryId, Direction = 0, DueDate = DateTime.Parse("2018-05-15") }); dbUtils.Insert(new DbStatementDto() { Amount = 205, CategoryId = categoryId, Direction = 0, DueDate = DateTime.Parse("2018-05-20"), Paid = true, PaymentDate = DateTime.Parse("2018-05-20") }); dbUtils.Insert(new DbStatementDto() { Amount = 106, CategoryId = categoryId, Direction = 0, DueDate = DateTime.Parse("2018-06-15") }); dbUtils.Insert(new DbStatementDto() { Amount = 206, CategoryId = categoryId, Direction = 0, DueDate = DateTime.Parse("2018-06-20"), Paid = true, PaymentDate = DateTime.Parse("2018-06-20") }); var sut = new StatementRepository(dbUtils.DbContext); // Act var statementList = await sut.GetList(MonthYear.Create(2018, 5)); // Assert Assert.Equal(3, statementList.Count); Assert.Contains(statementList, x => x.Amount == 104); Assert.Contains(statementList, x => x.Amount == 105); Assert.Contains(statementList, x => x.Amount == 205); }
public MonthYear GetCurrentMonthYear() => MonthYear.Create(DateTime.Today.Year, DateTime.Today.Month);