Beispiel #1
0
        public void TestAddPromotionBookOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseFourBooks();
            }

            using (var context = new EfCoreContext(options))
            {
                var service = new AddRemovePromotionService(context);

                //ATTEMPT
                var dto = service.GetOriginal(1);
                dto.ActualPrice     = dto.OrgPrice / 2;
                dto.PromotionalText = "Half price today!";
                var book = service.AddPromotion(dto);
                context.SaveChanges();

                //VERIFY
                service.IsValid.ShouldBeTrue();
                book.ActualPrice.ShouldEqual(book.OrgPrice / 2);
            }
        }
Beispiel #2
0
        public void TestAddPromotionBookWithError()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseFourBooks();
            }

            using (var context = new EfCoreContext(options))
            {
                var service = new AddRemovePromotionService(context);

                //ATTEMPT
                var dto = service.GetOriginal(1);
                dto.ActualPrice     = dto.OrgPrice / 2;
                dto.PromotionalText = "";
                service.AddPromotion(dto);

                //VERIFY
                service.IsValid.ShouldBeFalse();
                service.Errors.Single().ToString().ShouldEqual("You must provide some text to go with the promotion.");
            }
        }
Beispiel #3
0
        public void TestRemovePromotionBookOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseFourBooks();
            }

            using (var context = new EfCoreContext(options))
            {
                var service = new AddRemovePromotionService(context);
                var dto     = service.GetOriginal(1);
                dto.ActualPrice     = dto.OrgPrice / 2;
                dto.PromotionalText = "";
                service.AddPromotion(dto);

                //ATTEMPT
                var book = service.RemovePromotion(dto.BookId);

                //VERIFY
                book.ActualPrice.ShouldEqual(dto.OrgPrice);
            }
        }