<commit_before>﻿using InterSystems.AspNet.Identity.Cache;
using Microsoft.AspNet.Identity;
using System;
using System.Data.Entity.Validation;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace Identity.Test
{
    public class IdentityUserStoreTest
    {
        [Fact]
        public void AddUserWithNoUserNameFailsTest()
        {
            var db = UnitTestHelper.CreateDefaultDb();
            var store = new IdentityUserStore<IdentityUser>(db);
            Assert.Throws<DbEntityValidationException>(
                () => AsyncHelper.RunSync(() => store.CreateAsync(new IdentityUser())));
        }

        [Fact]
        public async Task CanDisableAutoSaveChangesTest()
        {
            var db = new NoopIdentityDbContext();
            var store = new IdentityUserStore<IdentityUser>(db);
            store.AutoSaveChanges = false;
            var user = new IdentityUser("test");
            await store.CreateAsync(user);
            Assert.False(db.SaveChangesCalled);

            Clear(db);
        }

        [Fact]
        public async Task CreateAutoSavesTest()
        {
            var db = new NoopIdentityDbContext();
            db.Configuration.ValidateOnSaveEnabled = false;
            var store = new IdentityUserStore<IdentityUser>(db);
            var user = new IdentityUser("test");
            await store.CreateAsync(user);
            Assert.True(db.SaveChangesCalled);
        }

        [Fact]
        public async Task UpdateAutoSavesTest()
        {
            var db = new NoopIdentityDbContext();
            var store = new IdentityUserStore<IdentityUser>(db);
            var user = new IdentityUser("test");
            await store.UpdateAsync(user);
            Assert.True(db.SaveChangesCalled);

            Clear(db);
        }

        [Fact]
        public async Task AddDupeUserIdWithStoreFailsTest()
        {
            var db = UnitTestHelper.CreateDefaultDb();
            var store = new IdentityUserStore<IdentityUser>(db);
            var user = new IdentityUser("dupemgmt");
            await store.CreateAsync(user);
            var u2 = new IdentityUser { Id = user.Id, UserName = "User" };
            try
            {
                await store.CreateAsync(u2);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.True(e.InnerException.InnerException.Message.Contains("Нарушение Ограничений UNIQUE"));
            }

            Clear(db);<commit_msg>Message changed according to other cache versions<commit_after>﻿using InterSystems.AspNet.Identity.Cache;
using Microsoft.AspNet.Identity;
using System;
using System.Data.Entity.Validation;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace Identity.Test
{
    public class IdentityUserStoreTest
    {
        [Fact]
        public void AddUserWithNoUserNameFailsTest()
        {
            var db = UnitTestHelper.CreateDefaultDb();
            var store = new IdentityUserStore<IdentityUser>(db);
            Assert.Throws<DbEntityValidationException>(
                () => AsyncHelper.RunSync(() => store.CreateAsync(new IdentityUser())));
        }

        [Fact]
        public async Task CanDisableAutoSaveChangesTest()
        {
            var db = new NoopIdentityDbContext();
            var store = new IdentityUserStore<IdentityUser>(db);
            store.AutoSaveChanges = false;
            var user = new IdentityUser("test");
            await store.CreateAsync(user);
            Assert.False(db.SaveChangesCalled);

            Clear(db);
        }

        [Fact]
        public async Task CreateAutoSavesTest()
        {
            var db = new NoopIdentityDbContext();
            db.Configuration.ValidateOnSaveEnabled = false;
            var store = new IdentityUserStore<IdentityUser>(db);
            var user = new IdentityUser("test");
            await store.CreateAsync(user);
            Assert.True(db.SaveChangesCalled);
        }

        [Fact]
        public async Task UpdateAutoSavesTest()
        {
            var db = new NoopIdentityDbContext();
            var store = new IdentityUserStore<IdentityUser>(db);
            var user = new IdentityUser("test");
            await store.UpdateAsync(user);
            Assert.True(db.SaveChangesCalled);

            Clear(db);
        }

        [Fact]
        public async Task AddDupeUserIdWithStoreFailsTest()
        {
            var db = UnitTestHelper.CreateDefaultDb();
            var store = new IdentityUserStore<IdentityUser>(db);
            var user = new IdentityUser("dupemgmt");
            await store.CreateAsync(user);
            var u2 = new IdentityUser { Id = user.Id, UserName = "User" };
            try
            {
                await store.CreateAsync(u2);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.True(e.InnerException.InnerException.Message.Contains("UNIQUE"));
            }

            Clear(db);
{'fraction_non_alphanumeric': 0.09316037735849056, 'fraction_numerical': 0.0007861635220125787, 'mean_word_length': 1.9638905066977286, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '5699517', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1289, 'n_words': 281}