예제 #1
0
        public GetOpenIdOutput GetOpenId(GetOpenIdInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var openUserHead =
                _openUserHeadsRepository.FirstOrDefault(
                    x =>
                    x.UserId == input.UserId &&
                    x.OpenPlatformMicroApplicationId == input.OpenPlatformMicroApplicationId);

            if (openUserHead == null)
            {
                var id = Guid.NewGuid();
                openUserHead = _openUserHeadsRepository.Insert(new Models.OpenUserHeads
                {
                    CreateTime = DateTime.Now,
                    OpenPlatformMicroApplicationId = input.OpenPlatformMicroApplicationId,
                    UserId = input.UserId,
                    Id     = id,
                    OpenId = id.ToString("N")
                });
            }
            return(new GetOpenIdOutput {
                OpenId = openUserHead.OpenId
            });
        }
예제 #2
0
 public void TextInsert()
 {
     var user = new UserInfo()
     {
         UserName    = "******",
         RealName    = "成天",
         GmtCreate   = DateTime.Now,
         GmtModified = DateTime.Now
     };
     var result = userInfoRepository.Insert(user);
 }
예제 #3
0
        public async Task shouldtriggereventoninsertedwithdapper()
        {
            var triggerCount = 0;

            Resolve <IEventBus>().Register <EntityCreatedEventData <Blog> >(
                eventData =>
            {
                eventData.Entity.Name.ShouldBe("OnSoftware");
                eventData.Entity.IsTransient().ShouldBe(false);
                triggerCount++;
            });

            blogDapperRepository.Insert(new Blog("OnSoftware", "www.studiox.com"));

            triggerCount.ShouldBe(1);
        }
        public async Task should_trigger_event_on_inserted_with_dapper()
        {
            var triggerCount = 0;

            Resolve <IEventBus>().Register <EntityCreatedEventData <Blog> >(
                eventData =>
            {
                eventData.Entity.Name.ShouldBe("OnSoftware");
                eventData.Entity.IsTransient().ShouldBe(false);
                triggerCount++;
            });

            _blogDapperRepository.Insert(new Blog("OnSoftware", "www.aspnetboilerplate.com"));

            triggerCount.ShouldBe(1);
        }
예제 #5
0
        public void DoSomeStuff()
        {
            var people = _personDapperRepository.Query("select * from AppPersons");

            _personDapperRepository.Execute("Insert into AppPersons (Id,Name,CreationTime) values ('" + Guid.NewGuid() + "','Name_" + Guid.NewGuid().ToString().Substring(10) + "','" + Clock.Now.ToString() + "')");
            _personDapperRepository.Execute("UPDATE AppPersons set Name=@name where Id=@Id", new { name = "Name_" + Guid.NewGuid().ToString().Substring(10), Id = people.FirstOrDefault()?.Id });
            var person = people.FirstOrDefault();

            person.Name = "Yebin_" + Guid.NewGuid().ToString().Substring(15);
            _personDapperRepository.Update(person);
            person = _personDapperRepository.Single(people.Skip(1).Take(1).First().Id);
            _personDapperRepository.Insert(new Person {
                Name = "Yebin_" + Guid.NewGuid().ToString().Substring(15), Id = Guid.NewGuid(), CreationTime = Clock.Now
            });
            _personDapperRepository.Delete(people.Skip(2).Take(1).First().Id);
        }
예제 #6
0
        public void DoSomeCoolStuff()
        {
            using (StoveSession.Use(1))
            {
                using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
                {
                    _productDapperRepository.Insert(new Product("JeanFromDapper"));

                    Product product = _productRepository.FirstOrDefault(x => x.Name == "JeanFromDapper");

                    _productRepository.InsertAndGetId(new Product("JeanFromNH"));

                    uow.Complete();
                }
            }
        }
예제 #7
0
        //[Fact(Skip = "Effort does not support Dapper queries.")]
        public void DapperRepositories_Should_Work_Within_A_UnitOfWorkScope()
        {
            _productDapperRepository.Insert(new Product("TShirt", "Red", 5)
            {
                Id = 1
            });

            Product productFromEf = _productRepository.Get(1);

            _productDapperRepository.GetList(x => x.Name == "TShirt").ShouldNotBeNull();

            productFromEf.Name = "Pants";
            _productDapperRepository.Update(productFromEf);

            _productDapperRepository.GetListPaged(x => x.Name == "Pants", 1, 10, true, product => product.Name, product => product.Color);
        }
예제 #8
0
        public void Should_Trigger_Event_On_Insert()
        {
            var triggerCount = 0;

            Resolve <IEventBus>().Register <EntityCreatedEventData <Person> >(
                eventData =>
            {
                eventData.Entity.Name.ShouldBe("Oguzhan_To_Fire_Event");
                eventData.Entity.IsTransient().ShouldBe(false);
                triggerCount++;
            });

            _personDapperRepository.Insert(new Person("Oguzhan_To_Fire_Event"));

            triggerCount.ShouldBe(1);
        }
예제 #9
0
        public void DoSomeStuff()
        {
            using (IUnitOfWorkCompleteHandle uow = UnitOfWorkManager.Begin())
            {
                using (StoveSession.Use(266))
                {
                    _productDapperRepository.Insert(new Product("TShirt"));
                    int gomlekId = _productDapperRepository.InsertAndGetId(new Product("Gomlek"));

                    Product gomlekFromEf = _productRepository.FirstOrDefault(gomlekId);

                    _productDapperRepository.Execute("update products set Name = @name where Id = @id", new { name = "TShirt_From_ExecuteQuery", @id = gomlekId });

                    Product firstProduct = _productDapperRepository.Get(gomlekId);

                    _animalRepository.InsertAndGetId(new Animal("Bird"));

                    _animalDapperRepository.GetAll(x => x.Name == "Bird");

                    _productDapperRepository.GetAll(x => x.Id == 1 || x.Name == "Gomlek" || x.CreationTime == DateTime.Now);

                    _productDapperRepository.GetAll(x => (x.Id == 1 && x.Name == "Gomlek") || x.CreationTime == DateTime.Now);

                    _productDapperRepository.GetAll(x => ((x.Id == 1 || x.Name == "Gomlek") && x.CreationTime == DateTime.Now) ||
                                                    (x.Id == 1 || x.Name == "Gomlek") && x.CreationTime == DateTime.Now);

                    IEnumerable <Product> products = _productDapperRepository.GetAll();

                    firstProduct.Name = "Something";

                    _productDapperRepository.Update(firstProduct);

                    _mailDapperRepository.Insert(new Mail("New Product Added"));
                    Guid mailId = _mailDapperRepository.InsertAndGetId(new Mail("Second Product Added"));

                    IEnumerable <Mail> mails = _mailDapperRepository.GetAll();

                    Mail firstMail = mails.First();

                    firstMail.Subject = "Sorry wrong email!";

                    _mailDapperRepository.Update(firstMail);
                }

                uow.Complete();
            }
        }
예제 #10
0
        public async Task should_trigger_event_on_inserted_with_dapper()
        {
            var triggerCount = 0;

            The <IEventBus>().Register <EntityCreatedEventData <Blog> >(
                eventData =>
            {
                eventData.Entity.Name.ShouldBe("OnSoftware");
                eventData.Entity.IsTransient().ShouldBe(false);
                triggerCount++;
            });

            using (IUnitOfWorkCompleteHandle uow = The <IUnitOfWorkManager>().Begin())
            {
                _blogDapperRepository.Insert(new Blog("OnSoftware", "www.stove.com"));
                uow.Complete();
            }

            triggerCount.ShouldBe(1);
        }
예제 #11
0
        public void DoSomeStuff()
        {
            using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
            {
                Logger.Debug("Uow Began!");

                _personRepository.Insert(new Person("Oğuzhan"));
                _personRepository.Insert(new Person("Ekmek"));

                _animalRepository.Insert(new Animal("Kuş"));
                _animalRepository.Insert(new Animal("Kedi"));

                _animalDbContextProvider.GetDbContext().Animals.Add(new Animal("Kelebek"));

                _unitOfWorkManager.Current.SaveChanges();

                Person personCache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                Person person = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");
                Animal animal = _animalRepository.FirstOrDefault(x => x.Name == "Kuş");

                #region DAPPER

                var list = new List <string>
                {
                    "elma", "armut"
                };

                ExpressionStarter <Animal> predicate = PredicateBuilder.New <Animal>();
                predicate.And(x => x.Name == "Kuş");

                IEnumerable <Animal> birdsSet = _animalDapperRepository.GetSet(new { Name = "Kuş" }, 0, 10, "Id");

                IEnumerable <Person> personFromDapper = _personDapperRepository.GetList(new { Name = "Oğuzhan" });

                IEnumerable <Animal> birdsFromExpression = _animalDapperRepository.GetSet(predicate, 0, 10, "Id");

                IEnumerable <Animal> birdsPagedFromExpression = _animalDapperRepository.GetListPaged(x => x.Name == "Kuş", 0, 10, "Name");

                IEnumerable <Person> personFromDapperExpression = _personDapperRepository.GetList(x => x.Name.Contains("Oğuzhan"));

                int birdCount = _animalDapperRepository.Count(x => x.Name == "Kuş");

                var personAnimal = _animalDapperRepository.Query <PersonAnimal>("select Name as PersonName,'Zürafa' as AnimalName from Person with(nolock) where name=@name", new { name = "Oğuzhan" })
                                   .MapTo <List <PersonAnimalDto> >();

                birdsFromExpression.ToList();
                birdsPagedFromExpression.ToList();
                birdsSet.ToList();

                IEnumerable <Person> person2FromDapper = _personDapperRepository.Query("select * from Person with(nolock) where name =@name", new { name = "Oğuzhan" });

                _personDapperRepository.Insert(new Person("oğuzhan2"));
                int    id      = _personDapperRepository.InsertAndGetId(new Person("oğuzhan3"));
                Person person3 = _personDapperRepository.Get(id);
                person3.Name = "oğuzhan4";
                _personDapperRepository.Update(person3);
                _personDapperRepository.Delete(person3);

                #endregion

                Person person2Cache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                Person oguzhan = _personRepository.Nolocking(persons => persons.FirstOrDefault(x => x.Name == "Oğuzhan"));

                Person oguzhan2 = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");

                uow.Complete();

                _messageBus.Publish <IPersonAddedMessage>(new PersonAddedMessage
                {
                    Name          = "Oğuzhan",
                    CorrelationId = NewId.NextGuid()
                });

                //_hangfireBackgroundJobManager.EnqueueAsync<SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                //{
                //    Message = "Oğuzhan"
                //});

                _hangfireScheduleJobManager.ScheduleAsync <SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                {
                    Message = "Oğuzhan"
                }, Cron.Minutely());

                Logger.Debug("Uow End!");
            }
        }
예제 #12
0
        public async Task Dapper_Repository_Tests()
        {
            using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
            {
                //---Insert operation should work and tenant, creation audit properties must be set---------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Product insertedProduct = _productDapperRepository.GetAll(x => x.Name == "TShirt").FirstOrDefault();

                insertedProduct.ShouldNotBeNull();
                insertedProduct.TenantId.ShouldBe(AbpSession.TenantId);
                insertedProduct.CreationTime.ShouldNotBeNull();
                insertedProduct.CreatorUserId.ShouldBe(AbpSession.UserId);

                //----Update operation should work and Modification Audits should be set---------------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Product productToUpdate = _productDapperRepository.GetAll(x => x.Name == "TShirt").FirstOrDefault();
                productToUpdate.Name = "Pants";
                _productDapperRepository.Update(productToUpdate);

                productToUpdate.ShouldNotBeNull();
                productToUpdate.TenantId.ShouldBe(AbpSession.TenantId);
                productToUpdate.CreationTime.ShouldNotBeNull();
                productToUpdate.LastModifierUserId.ShouldBe(AbpSession.UserId);

                //---Get method should return single-------------------------------------------------------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Action getAction = () => _productDapperRepository.Single(x => x.Name == "TShirt");

                getAction.ShouldThrow <InvalidOperationException>("Sequence contains more than one element");

                //----Select * from syntax should work---------------------------------
                IEnumerable <Product> products = _productDapperRepository.Query("select * from Products");

                products.Count().ShouldBeGreaterThan(0);

                //------------Ef and Dapper should work under same transaction---------------------
                Product productFromEf     = _productRepository.FirstOrDefault(x => x.Name == "TShirt");
                Product productFromDapper = _productDapperRepository.Single(productFromEf.Id);

                productFromDapper.Name.ShouldBe(productFromEf.Name);
                productFromDapper.TenantId.ShouldBe(productFromEf.TenantId);

                //------Soft Delete should work for Dapper--------------
                _productDapperRepository.Insert(new Product("SoftDeletableProduct"));

                Product toSoftDeleteProduct = _productDapperRepository.Single(x => x.Name == "SoftDeletableProduct");

                _productDapperRepository.Delete(toSoftDeleteProduct);

                toSoftDeleteProduct.IsDeleted.ShouldBe(true);
                toSoftDeleteProduct.DeleterUserId.ShouldBe(AbpSession.UserId);
                toSoftDeleteProduct.TenantId.ShouldBe(AbpSession.TenantId);

                Product softDeletedProduct = _productRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                softDeletedProduct.ShouldBeNull();

                Product softDeletedProductFromDapper = _productDapperRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                softDeletedProductFromDapper.ShouldBeNull();

                using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                {
                    Product softDeletedProductWhenFilterDisabled = _productRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                    softDeletedProductWhenFilterDisabled.ShouldNotBeNull();

                    Product softDeletedProductFromDapperWhenFilterDisabled = _productDapperRepository.Single(x => x.Name == "SoftDeletableProduct");
                    softDeletedProductFromDapperWhenFilterDisabled.ShouldNotBeNull();
                }

                using (AbpSession.Use(2, 266))
                {
                    int productWithTenant2Id = _productDapperRepository.InsertAndGetId(new Product("ProductWithTenant2"));

                    Product productWithTenant2 = _productRepository.Get(productWithTenant2Id);

                    productWithTenant2.TenantId.ShouldBe(1); //Not sure about that?,Because we changed TenantId to 2 in this scope !!! Abp.TenantId = 2 now NOT 1 !!!
                }

                using (_unitOfWorkManager.Current.SetTenantId(3))
                {
                    int productWithTenant3Id = _productDapperRepository.InsertAndGetId(new Product("ProductWithTenant3"));

                    Product productWithTenant3 = _productRepository.Get(productWithTenant3Id);

                    productWithTenant3.TenantId.ShouldBe(3);
                }

                Product productWithTenantId3FromDapper = _productDapperRepository.FirstOrDefault(x => x.Name == "ProductWithTenant3");
                productWithTenantId3FromDapper.ShouldBeNull();

                Product p = await _productDapperRepository.FirstOrDefaultAsync(x => x.Status == Status.Active);

                p.ShouldNotBeNull();

                using (_unitOfWorkManager.Current.SetTenantId(3))
                {
                    Product productWithTenantId3FromDapperInsideTenantScope = _productDapperRepository.FirstOrDefault(x => x.Name == "ProductWithTenant3");
                    productWithTenantId3FromDapperInsideTenantScope.ShouldNotBeNull();
                }

                //About issue-#2091
                using (_unitOfWorkManager.Current.SetTenantId(AbpSession.TenantId))
                {
                    int productWithTenantId40 = _productDapperRepository.InsertAndGetId(new Product("ProductWithTenantId40"));

                    Product productWithTenant40 = _productRepository.Get(productWithTenantId40);

                    productWithTenant40.TenantId.ShouldBe(AbpSession.TenantId);
                    productWithTenant40.CreatorUserId.ShouldBe(AbpSession.UserId);
                }

                //Second DbContext tests
                int productDetailId = _productDetailRepository.InsertAndGetId(new ProductDetail("Woman"));
                _productDetailDapperRepository.Get(productDetailId).ShouldNotBeNull();

                uow.Complete();
            }
        }
예제 #13
0
        public void DoSomeStuff()
        {
            try
            {
                using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
                {
                    Logger.Debug("Uow Began!");

                    int persionId1 = _personRepository.InsertAndGetId(new Person("Oğuzhan"));
                    _personRepository.Insert(new Person("Ekmek"));

                    int animalId1 = _animalRepository.InsertAndGetId(new Animal("Kuş"));
                    _animalRepository.Insert(new Animal("Kedi"));

                    _animalDbContextProvider.GetDbContext().Animals.Add(new Animal("Kelebek"));

                    _unitOfWorkManager.Current.SaveChanges();

                    Person personCache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                    Person person = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");
                    Animal animal = _animalRepository.FirstOrDefault(x => x.Name == "Kuş");

                    using (StoveSession.Use(266))
                    {
                        _productDapperRepository.Insert(new Product("TShirt1"));
                        int gomlekId = _productDapperRepository.InsertAndGetId(new Product("Gomlek1"));

                        Product firstProduct           = _productDapperRepository.FirstOrDefault(x => x.Name == "TShirt1");
                        IEnumerable <Product> products = _productDapperRepository.GetAll();

                        firstProduct.Name = "Something";

                        _productDapperRepository.Update(firstProduct);

                        _mailDapperRepository.Insert(new Mail("New Product Added"));
                        Guid mailId = _mailDapperRepository.InsertAndGetId(new Mail("Second Product Added"));

                        IEnumerable <Mail> mails = _mailDapperRepository.GetAll();

                        Mail firstMail = mails.First();

                        firstMail.Subject = "Sorry wrong email!";

                        _mailDapperRepository.Update(firstMail);
                    }

                    Animal oneAnimal      = _animalDapperRepository.Get(animalId1);
                    Animal oneAnimalAsync = _animalDapperRepository.GetAsync(animalId1).Result;

                    Person onePerson      = _personDapperRepository.Get(persionId1);
                    Person onePersonAsync = _personDapperRepository.GetAsync(persionId1).Result;

                    IEnumerable <Animal> birdsSet = _animalDapperRepository.GetSet(x => x.Name == "Kuş", 0, 10, "Id");

                    using (_unitOfWorkManager.Current.DisableFilter(StoveDataFilters.SoftDelete))
                    {
                        IEnumerable <Person> personFromDapperNotFiltered = _personDapperRepository.GetAll(x => x.Name == "Oğuzhan");
                    }

                    IEnumerable <Person> personFromDapperFiltered = _personDapperRepository.GetAll(x => x.Name == "Oğuzhan");

                    IEnumerable <Animal> birdsFromExpression = _animalDapperRepository.GetSet(x => x.Name == "Kuş", 0, 10, "Id");

                    IEnumerable <Animal> birdsPagedFromExpression = _animalDapperRepository.GetAllPaged(x => x.Name == "Kuş", 0, 10, "Name");

                    IEnumerable <Person> personFromDapperExpression = _personDapperRepository.GetAll(x => x.Name.Contains("Oğuzhan"));

                    int birdCount = _animalDapperRepository.Count(x => x.Name == "Kuş");

                    var personAnimal = _animalDapperRepository.Query <PersonAnimal>("select Name as PersonName,'Zürafa' as AnimalName from Persons with(nolock) where name=@name", new { name = "Oğuzhan" })
                                       .MapTo <List <PersonAnimalDto> >();

                    birdsFromExpression.ToList();
                    birdsPagedFromExpression.ToList();
                    birdsSet.ToList();

                    IEnumerable <Person> person2FromDapper = _personDapperRepository.Query("select * from Persons with(nolock) where name =@name", new { name = "Oğuzhan" });

                    _personDapperRepository.Insert(new Person("oğuzhan2"));
                    int    id      = _personDapperRepository.InsertAndGetId(new Person("oğuzhan3"));
                    Person person3 = _personDapperRepository.Get(id);
                    person3.Name = "oğuzhan4";
                    _personDapperRepository.Update(person3);
                    _personDapperRepository.Delete(person3);

                    Person person2Cache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                    //Person oguzhan = _personRepository.Nolocking(persons => persons.FirstOrDefault(x => x.Name == "Oğuzhan"));

                    Person oguzhan2 = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");

                    uow.Complete();

                    _messageBus.Publish <IPersonAddedMessage>(new PersonAddedMessage
                    {
                        Name          = "Oğuzhan",
                        CorrelationId = NewId.NextGuid()
                    });

                    //_hangfireBackgroundJobManager.EnqueueAsync<SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                    //{
                    //    Message = "Oğuzhan"
                    //});

                    //_hangfireScheduleJobManager.ScheduleAsync<SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                    //{
                    //    Message = "Oğuzhan"
                    //}, Cron.Minutely());

                    Logger.Debug("Uow End!");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw ex;
            }
        }
예제 #14
0
 public int?Insert(Table entity)
 {
     return(_dapperRepository.Insert(entity));
 }
예제 #15
0
        public void Dapper_Repository_Tests()
        {
            using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
            {
                //---Insert operation should work and tenant, creation audit properties must be set---------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Product insertedProduct = _productDapperRepository.GetAll(x => x.Name == "TShirt").FirstOrDefault();

                Guid mailId = _mailRepository.InsertAndGetId(new Mail("Hi There !"));
                _unitOfWorkManager.Current.SaveChanges();
                Mail mail = _mailDapperRepository.Get(mailId);
                mail.ShouldNotBeNull();
                mail.CreatorUserId.ShouldNotBeNull();
                mail.CreatorUserId.ShouldBe(StoveSession.UserId);

                Mail mailFromCustomRepository = _mailCustomDapperRepository.GetMailById(mailId);
                mailFromCustomRepository.ShouldNotBeNull();

                insertedProduct.ShouldNotBeNull();
                insertedProduct.CreationTime.ShouldNotBeNull();
                insertedProduct.CreatorUserId.ShouldNotBeNull();
                insertedProduct.CreatorUserId.ShouldBe(StoveSession.UserId);

                //----Update operation should work and Modification Audits should be set---------------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Product productToUpdate = _productDapperRepository.GetAll(x => x.Name == "TShirt").FirstOrDefault();
                productToUpdate.Name = "Pants";
                _productDapperRepository.Update(productToUpdate);

                productToUpdate.ShouldNotBeNull();

                productToUpdate.CreationTime.ShouldNotBeNull();
                productToUpdate.LastModifierUserId.ShouldBe(StoveSession.UserId);
                productToUpdate.CreatorUserId.ShouldBe(StoveSession.UserId);

                //---Get method should return single-------------------------------------------------------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Action getAction = () => _productDapperRepository.Single(x => x.Name == "TShirt");

                getAction.ShouldThrow <InvalidOperationException>("Sequence contains more than one element");

                //----Select * from syntax should work---------------------------------
                IEnumerable <Product> products = _productDapperRepository.Query("select * from Products");

                products.Count().ShouldBeGreaterThan(0);

                //------------Ef and Dapper should work under same transaction---------------------
                Product productFromEf     = _productRepository.FirstOrDefault(x => x.Name == "TShirt");
                Product productFromDapper = _productDapperRepository.Single(productFromEf.Id);

                productFromDapper.Name.ShouldBe(productFromEf.Name);

                //------Soft Delete should work for Dapper--------------
                _productDapperRepository.Insert(new Product("SoftDeletableProduct"));

                Product toSoftDeleteProduct = _productDapperRepository.Single(x => x.Name == "SoftDeletableProduct");

                _productDapperRepository.Delete(toSoftDeleteProduct);

                toSoftDeleteProduct.IsDeleted.ShouldBe(true);
                toSoftDeleteProduct.DeleterUserId.ShouldBe(StoveSession.UserId);

                Product softDeletedProduct = _productRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                softDeletedProduct.ShouldBeNull();

                Product softDeletedProductFromDapper = _productDapperRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                softDeletedProductFromDapper.ShouldBeNull();

                using (_unitOfWorkManager.Current.DisableFilter(StoveDataFilters.SoftDelete))
                {
                    Product softDeletedProductWhenFilterDisabled = _productRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                    softDeletedProductWhenFilterDisabled.ShouldNotBeNull();

                    Product softDeletedProductFromDapperWhenFilterDisabled = _productDapperRepository.Single(x => x.Name == "SoftDeletableProduct");
                    softDeletedProductFromDapperWhenFilterDisabled.ShouldNotBeNull();
                }

                using (StoveSession.Use(266))
                {
                    _productDapperRepository.Insert(new Product("InsertedProductWith266Id"));
                    Product InsertedProductWith266Id = _productDapperRepository.GetAll(x => x.Name == "InsertedProductWith266Id").FirstOrDefault();

                    InsertedProductWith266Id.ShouldNotBeNull();
                    InsertedProductWith266Id.CreationTime.ShouldNotBeNull();
                    InsertedProductWith266Id.CreatorUserId.ShouldNotBeNull();
                    InsertedProductWith266Id.CreatorUserId.ShouldBe(StoveSession.UserId);
                }

                _productDapperRepository.Insert(new Product("InsertedProductAfterSpecifiedUserId"));
                Product InsertedProductAfterSpecifiedUserId = _productDapperRepository.GetAll(x => x.Name == "InsertedProductAfterSpecifiedUserId").FirstOrDefault();

                InsertedProductAfterSpecifiedUserId.ShouldNotBeNull();
                InsertedProductAfterSpecifiedUserId.CreationTime.ShouldNotBeNull();
                InsertedProductAfterSpecifiedUserId.CreatorUserId.ShouldNotBeNull();
                InsertedProductAfterSpecifiedUserId.CreatorUserId.ShouldBe(StoveSession.UserId);

                uow.Complete();
            }
        }
예제 #16
0
        public void Test()
        {
            TestClass t1 = new TestClass();

            t1.Id   = 1;
            t1.Data = "test1";

            TestClass t2 = new TestClass();

            t2.Id             = 2;
            t2.Data           = "test2";
            t2.FakeNameColumn = "2222";

            var result = repo.Insert(t1);

            Assert.Equal(1, result);

            result = repo.Insert(t2);
            Assert.Equal(1, result);

            var item1 = repo.GetItem(new TestClass()
            {
                Id = 1
            });

            Assert.Equal("test1", item1.Data);

            var item2 = repo.GetItem(new TestClass()
            {
                Id = 2
            });

            Assert.Equal("test2", item2.Data);

            // update 테스트
            t1.Data           = "test1-1";
            t1.FakeNameColumn = "1111";

            result = repo.Update(t1);

            Assert.Equal(1, result);

            item1 = repo.GetItem(new TestClass()
            {
                Id = 1
            });
            Assert.Equal("test1-1", item1.Data);

            // 조건 리스트
            var list = repo.GetList(t1, new ParamColumn("Id", "<", "3"));

            Assert.Equal(2, list.Count);

            // 조건 아이템

            var item4 = repo.GetItem(t1, new ParamColumn(nameof(t1.LDate), "is not null", ""));

            Assert.Equal(1, item4.Id);

            item4 = repo.GetItem(t1, new ParamColumn(nameof(t1.LDate), "is null", null));

            Assert.Equal(2, item4.Id);

            item4 = repo.GetItem(t1, new ParamColumn(nameof(t1.Data), "like", "'%1-1'"));

            Assert.Equal(1, item4.Id);

            // Delete
            result = repo.Delete(new TestClass()
            {
                Id = 1, Data = "test1-1"
            });

            Assert.Equal(1, result);

            result = repo.Delete(new TestClass()
            {
                Id = 2
            });

            Assert.Equal(1, result);
        }
 public long Add(User user)
 {
     return(_userRepository.Insert(user));
 }