Exemplo n.º 1
0
        protected static GlobalmanticsContext GivenGlobalmanticsContext()
        {
            var options = new DbContextOptionsBuilder()
                          .UseSqlServer(Globalmantics.ConnectionString)
                          .Options;
            var context = new GlobalmanticsContext(options);

            return(context);
        }
Exemplo n.º 2
0
        protected static GlobalmanticsContext GivenGlobalmanticsContext(bool beginTransaction = true)
        {
            var context = new GlobalmanticsContext(new DbContextOptionsBuilder()
                                                   .UseSqlServer(Globalmantics.ConnectionString)
                                                   .Options);

            if (beginTransaction)
            {
                context.Database.BeginTransaction();
            }
            return(context);
        }
Exemplo n.º 3
0
        public void CanCreateUser()
        {
            var context    = new GlobalmanticsContext();
            var userSerice = new UserService(context);

            User user = userSerice.GetUserByEmail(
                "*****@*****.**");

            context.SaveChanges();

            user.UserId.Should().NotBe(0);
            user.Email.Should().Be("*****@*****.**");
        }
Exemplo n.º 4
0
        public void CanCreateUser()
        {
            var context = new GlobalmanticsContext(new DbContextOptionsBuilder()
                                                   .UseInMemoryDatabase()
                                                   .Options);
            var userService = new UserService(context);

            User user = userService.GetUserByEmail(
                "*****@*****.**");

            context.SaveChanges();

            user.UserId.Should().NotBe(0);
            user.Email.Should().Be("*****@*****.**");
        }
Exemplo n.º 5
0
        public void CanLoadCartWithNoItems()
        {
            string databaseName = Guid.NewGuid().ToString();

            var context = new GlobalmanticsContext(new DbContextOptionsBuilder()
                                                   .UseInMemoryDatabase(databaseName: databaseName)
                                                   .Options);
            var userService = new UserService(context);
            var cartService = new CartService(context);

            var user = userService.GetUserByEmail("*****@*****.**");

            context.SaveChanges();
            var cart = cartService.GetCartForUser(user);

            context.SaveChanges();

            cart.CartItems.Count().Should().Be(0);
        }
Exemplo n.º 6
0
        private void InitializeCartWithOneItem(string databaseName)
        {
            var context = new GlobalmanticsContext(new DbContextOptionsBuilder()
                                                   .UseInMemoryDatabase(databaseName)
                                                   .Options);

            var user = context.Add(User.Create("*****@*****.**"))
                       .Entity;

            context.SaveChanges();
            var cart        = context.Add(Cart.Create(user.UserId)).Entity;
            var catalogItem = context.Add(CatalogItem.Create
                                          (
                                              sku: "CAFE-314",
                                              description: "1 Pound Guatemalan Coffee Beans",
                                              unitPrice: 18.80m
                                          )).Entity;

            cart.AddItem(catalogItem, 2);
            context.SaveChanges();
        }
Exemplo n.º 7
0
 public CartService(GlobalmanticsContext context)
 {
     _context = context;
 }
Exemplo n.º 8
0
 public UserService(GlobalmanticsContext context)
 {
     _context = context;
 }