<commit_before>﻿namespace Snittlistan.Test
{
    using System;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    using Castle.Windsor;
    using Moq;
    using Raven.Client;
    using Raven.Client.Embedded;
    using Snittlistan.Infrastructure.AutoMapper;
    using Snittlistan.Installers;
    using Snittlistan.Models;

    public abstract class DbTest : IDisposable
    {
        protected readonly IDocumentStore Store;

        public DbTest()
        {
            // configure AutoMapper too
            AutoMapperConfiguration
                .Configure(new WindsorContainer().Install(new AutoMapperInstaller()));

            Store = new EmbeddableDocumentStore { RunInMemory = true };

            // initialize
            RavenInstaller.InitializeStore(Store);
            Session = Store.OpenSession();
        }

        public IDocumentSession Session { get; private set; }

        public void Dispose()
        {
            Session.Dispose();
            Store.Dispose();
        }

        public void WaitForNonStaleResults<T>() where T : class
        {
            Session.Query<T>().Customize(x => x.WaitForNonStaleResults()).ToList();
        }

        public UrlHelper CreateUrlHelper()
        {
            var context = Mock.Of<HttpContextBase>();
            var routes = new RouteCollection();
            new RouteConfigurator(routes).Configure();
            return new UrlHelper(new RequestContext(Mock.Get(context).Object, new RouteData()), routes);
        }

        public User CreateActivatedUser(string firstName, string lastName, string email, string password)
        {
            var user = new User(
                firstName: firstName,
                lastName: lastName,
                email: email,
                password: password);
            user.Activate();
            Session.Store(user);
            Session.SaveChanges();
            WaitForNonStaleResults<User>();
            return user;
        }
    }
}<commit_msg>Improved api<commit_after>﻿namespace Snittlistan.Test
{
    using System;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    using Castle.Windsor;
    using Moq;
    using Raven.Client;
    using Raven.Client.Embedded;
    using Snittlistan.Infrastructure.AutoMapper;
    using Snittlistan.Installers;
    using Snittlistan.Models;

    public abstract class DbTest : IDisposable
    {
        protected readonly IDocumentStore Store;

        public DbTest()
        {
            // configure AutoMapper too
            AutoMapperConfiguration
                .Configure(new WindsorContainer().Install(new AutoMapperInstaller()));

            Store = new EmbeddableDocumentStore { RunInMemory = true };

            // initialize
            RavenInstaller.InitializeStore(Store);
            Session = Store.OpenSession();
        }

        protected IDocumentSession Session { get; private set; }

        public void Dispose()
        {
            Session.Dispose();
            Store.Dispose();
        }

        protected void WaitForNonStaleResults<T>() where T : class
        {
            Session.Query<T>().Customize(x => x.WaitForNonStaleResults()).ToList();
        }

        protected UrlHelper CreateUrlHelper()
        {
            var context = Mock.Of<HttpContextBase>();
            var routes = new RouteCollection();
            new RouteConfigurator(routes).Configure();
            return new UrlHelper(new RequestContext(Mock.Get(context).Object, new RouteData()), routes);
        }

        protected User CreateActivatedUser(string firstName, string lastName, string email, string password)
        {
            var user = new User(
                firstName: firstName,
                lastName: lastName,
                email: email,
                password: password);
            user.Activate();
            Session.Store(user);
            Session.SaveChanges();
            WaitForNonStaleResults<User>();
            return user;
        }
    }
}
{'fraction_non_alphanumeric': 0.08540925266903915, 'fraction_numerical': 0.0, 'mean_word_length': 1.7591623036649215, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '2329174', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1023, 'n_words': 239}