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

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                var action1 = new MockBizActionPart1(context);
                var action2 = new MockBizActionPart2(context);
                var runner  = new RunnerTransact2WriteDb <TransactBizActionDto, TransactBizActionDto, TransactBizActionDto>(context, action1, action2);

                //ATTEMPT
                var output = runner.RunAction(new TransactBizActionDto(mode));

                //VERIFY
                runner.HasErrors.ShouldEqual(mode != MockBizActionTransact2Modes.Ok);
                context.Authors.Count().ShouldEqual(mode != MockBizActionTransact2Modes.Ok ? 0 : 2);
                if (mode == MockBizActionTransact2Modes.BizErrorPart1)
                {
                    runner.Errors.Single().ErrorMessage.ShouldEqual("Failed in Part1");
                }
                if (mode == MockBizActionTransact2Modes.BizErrorPart2)
                {
                    runner.Errors.Single().ErrorMessage.ShouldEqual("Failed in Part2");
                }
            }
        }
        public void RunAction(MockBizActionTransact2Modes mode)
        {
            //SETUP
            var inMemDb = new SqliteInMemory();

            using (var context = inMemDb.GetContextWithSetup())
            {
                var action1 = new MockBizActionPart1(context);
                var action2 = new MockBizActionPart2(context);
                var runner  = new RunnerTransact2WriteDb <TransactBizActionDto, TransactBizActionDto, TransactBizActionDto>(context, action1, action2);

                //ATTEMPT
                var output = runner.RunAction(new TransactBizActionDto(mode));

                //VERIFY
                runner.HasErrors.ShouldEqual(mode != MockBizActionTransact2Modes.Ok);
                context.Authors.Count().ShouldEqual(mode != MockBizActionTransact2Modes.Ok ? 0 : 2);
                if (mode == MockBizActionTransact2Modes.BizErrorPart1)
                {
                    runner.Errors.Single().ErrorMessage.ShouldEqual("Failed in Part1");
                }
                if (mode == MockBizActionTransact2Modes.BizErrorPart2)
                {
                    runner.Errors.Single().ErrorMessage.ShouldEqual("Failed in Part2");
                }
            }
        }
Beispiel #3
0
        public int PlaceOrder(bool acceptTAndCs)
        {
            var checkoutService = new CheckoutCookieService(checkoutCookie.GetValue());
            var placeOrderInDto = new PlaceOrderInDto(acceptTAndCs, checkoutService.UserId, checkoutService.LineItems);
            var order           = runner.RunAction(placeOrderInDto);

            if (runner.HasErrors)
            {
                return(0);
            }

            checkoutService.ClearAllLineItems();
            checkoutCookie.AddOrUpdateCookie(checkoutService.EncodeForCookie());

            return(order.OrderId);
        }
        public void RunActionThrowException()
        {
            //SETUP
            var inMemDb = new SqliteInMemory();

            using (var context = inMemDb.GetContextWithSetup())
            {
                var action1 = new MockBizActionPart1(context);
                var action2 = new MockBizActionPart2(context);
                var runner  = new RunnerTransact2WriteDb <TransactBizActionDto, TransactBizActionDto, TransactBizActionDto>(context, action1, action2);

                //ATTEMPT
                Assert.Throws <InvalidOperationException>(() => runner.RunAction(new TransactBizActionDto(MockBizActionTransact2Modes.ThrowExceptionPart2)));

                //VERIFY
                context.Authors.Count().ShouldEqual(0);
            }
        }
Beispiel #5
0
        public void RunActionThrowException()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options, new FakeUserIdService(userId)))
            {
                context.Database.EnsureCreated();
                var action1 = new MockBizActionPart1(context);
                var action2 = new MockBizActionPart2(context);
                var runner  = new RunnerTransact2WriteDb <TransactBizActionDto, TransactBizActionDto, TransactBizActionDto>(context, action1, action2);

                //ATTEMPT
                Assert.Throws <InvalidOperationException>(() => runner.RunAction(new TransactBizActionDto(MockBizActionTransact2Modes.ThrowExceptionPart2)));

                //VERIFY
                context.Authors.Count().ShouldEqual(0);
            }
        }
        /// <summary>
        /// This creates the order and, if successful clears the cookie
        /// </summary>
        /// <returns>Returns the OrderId, or zero if errors</returns>
        public int PlaceOrder(bool tsAndCsAccepted)
        {
            var checkoutService = new CheckoutCookieService(
                _checkoutCookie.GetValue());

            var order = _runner.RunAction(
                new PlaceOrderInDto(tsAndCsAccepted,
                                    checkoutService.UserId,
                                    checkoutService.LineItems));

            if (_runner.HasErrors)
            {
                return(0);
            }

            //successful so clear the cookie line items
            checkoutService.ClearAllLineItems();
            _checkoutCookie.AddOrUpdateCookie(
                checkoutService.EncodeForCookie());

            return(order.OrderId);
        }
Beispiel #7
0
        public void ExampleCodeForBook()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options, new FakeUserIdService(userId)))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseDummyBooks();
                var lineItems = new List <OrderLineItem>
                {
                    new OrderLineItem {
                        BookId = 1, NumBooks = 4
                    },
                    new OrderLineItem {
                        BookId = 2, NumBooks = 5
                    },
                    new OrderLineItem {
                        BookId = 3, NumBooks = 6
                    }
                };
                //ATTEMPT

                var dbAccess = new PlaceOrderDbAccess(context);
                var action1  = new PlaceOrderPart1(dbAccess);
                var action2  = new PlaceOrderPart2(dbAccess);
                var runner   = new RunnerTransact2WriteDb <
                    PlaceOrderInDto,
                    Part1ToPart2Dto,
                    Order>(context, action1, action2);
                var order = runner.RunAction(new PlaceOrderInDto(true, userId, lineItems.ToImmutableList()));

                //VERIFY
                runner.HasErrors.ShouldBeFalse();
                context.Orders.Count().ShouldEqual(1);
            }
        }
        public void ExampleCodeForBook()
        {
            //SETUP
            var inMemDb = new SqliteInMemory();

            using (var context = inMemDb.GetContextWithSetup())
            {
                context.SeedDatabaseDummyBooks();
                var lineItems = new List <OrderLineItem>
                {
                    new OrderLineItem {
                        BookId = 1, NumBooks = 4
                    },
                    new OrderLineItem {
                        BookId = 2, NumBooks = 5
                    },
                    new OrderLineItem {
                        BookId = 3, NumBooks = 6
                    }
                };
                var userId = Guid.NewGuid();
                //ATTEMPT

                var dbAccess = new PlaceOrderDbAccess(context);
                var action1  = new PlaceOrderPart1(dbAccess);
                var action2  = new PlaceOrderPart2(dbAccess);
                var runner   = new RunnerTransact2WriteDb <
                    PlaceOrderInDto,
                    Part1ToPart2Dto,
                    Order>(context, action1, action2);
                var order = runner.RunAction(new PlaceOrderInDto(true, userId, lineItems.ToImmutableList()));

                //VERIFY
                runner.HasErrors.ShouldBeFalse();
                context.Orders.Count().ShouldEqual(1);
            }
        }