Пример #1
0
        public async Task RunActionAsync(MockBizActionWithWriteModes mode)
        {
            //SETUP
            var options = EfInMemory.CreateNewContextOptions();

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

                var action = new MockBizActionWithWriteAsync(context);
                var runner = new RunnerWriteDbWithValidationAsync <MockBizActionWithWriteModes, string>(action, context);

                //ATTEMPT
                var output = await runner.RunActionAsync(mode);

                //VERIFY
                output.ShouldEqual(mode.ToString());
                runner.HasErrors.ShouldEqual(mode != MockBizActionWithWriteModes.Ok);
                context.Orders.Count().ShouldEqual(mode != MockBizActionWithWriteModes.Ok ? 0 : 1);

                if (mode == MockBizActionWithWriteModes.BizError)
                {
                    runner.Errors.Single().ErrorMessage.ShouldEqual("There is a biz error.");
                }
                if (mode == MockBizActionWithWriteModes.SaveChangesError)
                {
                    runner.Errors.Single().ErrorMessage.ShouldEqual("If you want to order a 100 or more books please phone us on 01234-5678-90");
                }
            }
        }
        public void RunAction(MockBizActionWithWriteModes mode)
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options, new FakeUserIdService(userId)))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseFourBooks();

                var action = new MockBizActionWithWrite(context, userId);
                var runner = new RunnerWriteDbWithValidation <MockBizActionWithWriteModes, string>(action, context);

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

                //VERIFY
                output.ShouldEqual(mode.ToString());
                runner.HasErrors.ShouldEqual(mode != MockBizActionWithWriteModes.Ok);
                context.Orders.Count().ShouldEqual(mode != MockBizActionWithWriteModes.Ok ? 0 : 1);

                if (mode == MockBizActionWithWriteModes.BizError)
                {
                    runner.Errors.Single().ErrorMessage.ShouldEqual("There is a biz error.");
                }
                if (mode == MockBizActionWithWriteModes.SaveChangesError)
                {
                    runner.Errors.Single().ErrorMessage.ShouldEqual("If you want to order a 100 or more books please phone us on 01234-5678-90");
                }
            }
        }
Пример #3
0
        public Task <string> ActionAsync(MockBizActionWithWriteModes mode)
        {
            if (mode == MockBizActionWithWriteModes.BizError)
            {
                AddError("There is a biz error.");
            }

            var numBooks = (short)(mode == MockBizActionWithWriteModes.SaveChangesError ? 200 : 1);

            var order = new Order
            {
                CustomerId = _userId,
                LineItems  = new List <LineItem>
                {
                    new LineItem
                    {
                        BookId    = _context.Books.First().BookId,
                        LineNum   = 1,
                        BookPrice = 123,
                        NumBooks  = numBooks
                    }
                }
            };

            _context.Orders.Add(order);

            return(Task.FromResult(mode.ToString()));
        }
Пример #4
0
        public string Action(MockBizActionWithWriteModes mode)
        {
            if (mode == MockBizActionWithWriteModes.BizError)
            {
                AddError("There is a biz error.");
            }

            var numBooks = (short)(mode == MockBizActionWithWriteModes.SaveChangesError ? 200 : 1);

            var order = new Order
            {
                CustomerName = Guid.NewGuid(),
                LineItems    = new List <LineItem>
                {
                    new LineItem
                    {
                        BookId    = _context.Books.First().BookId,
                        LineNum   = 1,
                        BookPrice = 123,
                        NumBooks  = numBooks
                    }
                }
            };

            _context.Orders.Add(order);

            return(mode.ToString());
        }