コード例 #1
0
        public async Task <BookDiscount> CreateBookDiscount(DateTime expireDate, decimal discountPercentage, int bookInfoId)
        {
            var bookDiscount = new BookDiscount()
            {
                ExpireDate         = expireDate,
                DiscountPercentage = discountPercentage,
                BookInfoId         = bookInfoId
            };

            await Set <BookDiscount>()
            .AddAsync(bookDiscount);

            await SaveChangesAsync();

            return(bookDiscount);
        }
コード例 #2
0
ファイル: BookDiscountTest.cs プロジェクト: YGAR84/CSharpNSU
        public void BookDiscountCtorTest()
        {
            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 BookDiscount(expireDate, 80, bookInfo1);

            discount.ExpireDate.Should().Be(expireDate);
        }
コード例 #3
0
ファイル: Init.cs プロジェクト: ismailmayat/PotterKata
        public static Discounter Discounter()
        {
            IDiscount twoBookDiscount = new BookDiscount(2, 5);

            IDiscount threeBookDiscount = new BookDiscount(3, 10);

            IDiscount fourBookDiscount = new BookDiscount(4, 20);

            IDiscount fiveBookDiscount = new BookDiscount(5, 25);

            IEnumerable <IDiscount> discounts = new List <IDiscount> {
                twoBookDiscount, threeBookDiscount, fourBookDiscount, fiveBookDiscount
            };

            var discounter = new Discounter(discounts, 8M, 5);

            return(discounter);
        }
コード例 #4
0
ファイル: BookDiscountTest.cs プロジェクト: YGAR84/CSharpNSU
        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 BookDiscount(expireDate, 80, bookInfo1);

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