Example #1
0
        public void update_value_object_with_direct_context()
        {
            UserTestData.PrepareUser(userId);

            string houseNo = Guid.NewGuid().ToString("n");

            using (var kernel = new Ninject.StandardKernel())
            {
                kernel.ConfigureDirectContext();

                var orderingService = kernel.Get <IOrderingService>();

                // ACT
                orderingService.SetUserAddress(userId, new Address()
                {
                    City    = "PoznaƄ",
                    HouseNo = houseNo,
                    Street  = "Brzęczyszczykiewicza"
                });
            }

            using (var db = new MyContext())
            {
                var user = db.Users.FirstOrDefault(u => u.Id == userId);

                // ups, we updated the object, but didn't reattach it to the new context!
                AssertThat.AreEqual(houseNo, user.Address.HouseNo);
            }
        }
        public void update_related_entity_with_direct_context()
        {
            UserTestData.PrepareUser(userId);

            string itemName = $"item-{Guid.NewGuid()}";

            using (var kernel = new Ninject.StandardKernel())
            {
                kernel.ConfigureDirectContext();

                var orderingService = kernel.Get <IOrderingService>();

                // ACT
                orderingService.SetUserPreferences(userId, itemName);
            }

            using (var db = new MyContext())
            {
                var user = db.Users.Include(u => u.UserPreferences).FirstOrDefault(u => u.Id == userId);

                // ups, we updated the object, but didn't reattach it to the new context!
                AssertThat.AreEqual(itemName, user.UserPreferences.FavoriteProduct);
            }
        }