<commit_before>﻿using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.Events.Bus;
using Abp.Events.Bus.Entities;
using Abp.NHibernate.Tests.Entities;
using Shouldly;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Abp.NHibernate.Tests
{
    public class Basic_Repository_Tests : NHibernateTestBase
    {
        private readonly IRepository<Person> _personRepository;
        private readonly IRepository<Book> _booksRepository;
        private readonly IUnitOfWorkManager _unitOfWorkManager;

        public Basic_Repository_Tests()
        {
            _personRepository = Resolve<IRepository<Person>>();
            _booksRepository = Resolve<IRepository<Book>>();
            _unitOfWorkManager = Resolve<IUnitOfWorkManager>();

            UsingSession(session => session.Save(new Person() { Name = "emre" }));
            UsingSession(session => session.Save(new Book { Name = "Hitchhikers Guide to the Galaxy" }));
            UsingSession(session => session.Save(new Book { Name = "My First ABCs", IsDeleted = true }));
        }

        [Fact]
        public void Should_Insert_People()
        {
            _personRepository.Insert(new Person() { Name = "halil" });

            var insertedPerson = UsingSession(session => session.Query<Person>().FirstOrDefault(p => p.Name == "halil"));
            insertedPerson.ShouldNotBe(null);
            insertedPerson.IsTransient().ShouldBe(false);
            insertedPerson.Name.ShouldBe("halil");
        }

        [Fact]
        public async Task Should_Insert_People_Async()
        {
            await _personRepository.InsertAsync(new Person() { Name = "halil" });

            var insertedPerson = UsingSession(session => session.Query<Person>().FirstOrDefault(p => p.Name == "halil"));
            insertedPerson.ShouldNotBeNull();
            insertedPerson.IsTransient().ShouldBeFalse();
            insertedPerson.Name.ShouldBe("halil");
        }

        [Fact]
        public void Should_Filter_SoftDelete()
        {<commit_msg>Add unit test to check FirstOrDefault result<commit_after>﻿using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.Events.Bus;
using Abp.Events.Bus.Entities;
using Abp.NHibernate.Tests.Entities;
using Shouldly;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Abp.NHibernate.Tests
{
    public class Basic_Repository_Tests : NHibernateTestBase
    {
        private readonly IRepository<Person> _personRepository;
        private readonly IRepository<Book> _booksRepository;
        private readonly IUnitOfWorkManager _unitOfWorkManager;

        public Basic_Repository_Tests()
        {
            _personRepository = Resolve<IRepository<Person>>();
            _booksRepository = Resolve<IRepository<Book>>();
            _unitOfWorkManager = Resolve<IUnitOfWorkManager>();

            UsingSession(session => session.Save(new Person() { Name = "emre" }));
            UsingSession(session => session.Save(new Book { Name = "Hitchhikers Guide to the Galaxy" }));
            UsingSession(session => session.Save(new Book { Name = "My First ABCs", IsDeleted = true }));
        }

        [Fact]
        public async Task Should_Get_Null_On_Not_Found()
        {
            var person = _personRepository.FirstOrDefault(-1);
            person.ShouldBeNull();

            person = await _personRepository.FirstOrDefaultAsync(-1);
            person.ShouldBeNull();
        }

        [Fact]
        public void Should_Insert_People()
        {
            _personRepository.Insert(new Person() { Name = "halil" });

            var insertedPerson = UsingSession(session => session.Query<Person>().FirstOrDefault(p => p.Name == "halil"));
            insertedPerson.ShouldNotBe(null);
            insertedPerson.IsTransient().ShouldBe(false);
            insertedPerson.Name.ShouldBe("halil");
        }

        [Fact]
        public async Task Should_Insert_People_Async()
        {
            await _personRepository.InsertAsync(new Person() { Name = "halil" });

            var insertedPerson = UsingSession(session => session.Query<Person>().FirstOrDefault(p => p.Name == "halil"));
            insertedPerson.ShouldNotBeNull();
            insertedPerson.IsTransient().ShouldBeFalse();
            insertedPerson.Name.ShouldBe("halil");
        }

        [Fact]
        public void Should_Filter_SoftDelete()
        {
{'fraction_non_alphanumeric': 0.10863636363636364, 'fraction_numerical': 0.00045454545454545455, 'mean_word_length': 2.7679794520547945, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4934356', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1187, 'n_words': 233}