public void DiscountIsExpiredTest() { Discount discount = new GenreDiscount(DateTime.Today.AddDays(1000).Date, 10, new Genre("bl")); discount.IsExpired(DateTime.Today.AddDays(10001).Date).Should().BeTrue(); discount.IsExpired(DateTime.Today.Date).Should().BeFalse(); discount.IsExpired(DateTime.Today.AddDays(1000).Date).Should().BeFalse(); }
public async Task <GenreDiscount> CreateGenreDiscount(DateTime expireDate, decimal discountPercentage, int genreId) { var genreDiscount = new GenreDiscount() { ExpireDate = expireDate, DiscountPercentage = discountPercentage, GenreId = genreId }; await Set <GenreDiscount>() .AddAsync(genreDiscount); await SaveChangesAsync(); return(genreDiscount); }
public void GenreDiscountCtorTest() { List <Genre> genres1 = new List <Genre> { new Genre("fantasy") }; BookInfo bookInfo1 = new BookInfo("Harry Potter and the Chamber of Secrets", "J.K.Rowling", genres1); decimal cost = 500.1m; DateTime arriveDate = DateTime.Today.Date; Book book = new Book(bookInfo1, cost, arriveDate); var expireDate = DateTime.Today.AddDays(1000).Date; Discount discount = new GenreDiscount(expireDate, 80, new Genre("fantasy")); discount.ExpireDate.Should().Be(expireDate); }
public void BookDiscountApplyDiscountTest() { List <Genre> genres1 = new List <Genre> { new Genre("fantasy") }; BookInfo bookInfo1 = new BookInfo("Harry Potter and the Chamber of Secrets", "J.K.Rowling", genres1); decimal cost = 500.11m; Book book1 = new Book(bookInfo1, cost, DateTime.Today.Date); List <Genre> genres2 = new List <Genre> { new Genre("other") }; BookInfo bookInfo2 = new BookInfo("One Flew Over the Cuckoo's Nest", " Ken Kesey", genres2); Book book2 = new Book(bookInfo2, 600m, DateTime.Today.AddDays(-110)); var expireDate = DateTime.Today.AddDays(1000).Date; Discount discount = new GenreDiscount(expireDate, 80, new Genre("fantasy")); discount.ApplyDiscount(book1, DateTime.Today.Date).Cost.Should().Be(100.02m); discount.ApplyDiscount(book1, DateTime.Today.AddDays(1001).Date).Cost.Should().Be(book1.Cost); discount.ApplyDiscount(book2, DateTime.Today.Date).Cost.Should().Be(book2.Cost); }