<commit_before>﻿namespace King.Service.Integration
{
    using King.Azure.Data;
    using Microsoft.WindowsAzure.Storage.Table;
    using NUnit.Framework;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;

    [TestFixture]
    public class TableStorageTests
    {
        #region Members
        private readonly string ConnectionString = "UseDevelopmentStorage=true;";
        private ITableStorage storage = null;
        #endregion

        public class Helper : TableEntity
        {
            public Guid Id
            {
                get;
                set;
            }
        }

        [SetUp]
        public void Init()
        {
            var table = "testing";
            this.storage = new TableStorage(table, ConnectionString);
            storage.CreateIfNotExists().Wait();
        }
        
        [TearDown]
        public void Dispose()
        {
            storage.Delete().Wait();
        }

        [Test]
        public async Task CreateIfNotExists()
        {
            var table = 'a' + Guid.NewGuid().ToString().ToLowerInvariant().Replace('-', 'a');
            var storage = new TableStorage(table, ConnectionString);
            var created = await storage.CreateIfNotExists();

            Assert.IsTrue(created);

            await storage.Delete();
        }

        [Test]
        public async Task CreateIfNotExistsAlreadyExists()
        {
            var table = 'a' + Guid.NewGuid().ToString().ToLowerInvariant().Replace('-', 'a');
            var storage = new TableStorage(table, ConnectionString);
            var created = await storage.CreateIfNotExists();

            Assert.IsTrue(created);
            created = await storage.CreateIfNotExists();
            Assert.IsFalse(created);

            await storage.Delete();
        }

        [Test]
        public async Task Create()
        {
            var table = 'a' + Guid.NewGuid().ToString().ToLowerInvariant().Replace('-', 'a');
            var storage = new TableStorage(table, ConnectionString);
            var created = await storage.Create();

            Assert.IsTrue(created);

            await storage.Delete();
        }

        [Test]
        public async Task Delete()
        {
            var table = 'a' + Guid.NewGuid().ToString().ToLowerInvariant().Replace('-', 'a');
            var storage = new TableStorage(table, ConnectionString);
            var created = await storage.Create();

            Assert.IsTrue(created);

            await storage.Delete();

            created = await storage.Create();
            Assert.IsTrue(created);

            await storage.Delete();
        }

        [Test]
        public async Task Insert()
        {
            var entity = new TableEntity()
            {
                PartitionKey = "partition",
                RowKey = "row",
            };
            var entities = new List<TableEntity>();
            entities.Add(entity);
            await storage.Insert(entities);

            var returned = storage.QueryByPartition<TableEntity>("partition");
            Assert.IsNotNull(returned);
            Assert.AreEqual(1, returned.Count());
            var e = returned.First();
            Assert.AreEqual(entity.PartitionKey, e.PartitionKey);
            Assert.AreEqual(entity.RowKey, e.RowKey);
        }

        [Test]
        public async Task InsertOrReplace()
        {
            var entity = new TableEntity()
            {
                PartitionKey = "partition",
                RowKey = "row",
            };
            var entities = new List<TableEntity>();
            entities.Add(entity);
            await storage.Insert(entities);
            await storage.InsertOrReplace(entity);

            var returned = storage.QueryByPartition<TableEntity>("partition");
            Assert.IsNotNull(returned);
            Assert.AreEqual(1, returned.Count());
            var e = returned.First();
            Assert.AreEqual(entity.PartitionKey, e.PartitionKey);
            Assert.AreEqual(entity.RowKey, e.RowKey);
        }

        [Test]
        public async Task InsertOrReplaceDictionary()
        {
            var p = Guid.NewGuid().ToString();
            var r = Guid.NewGuid().ToString();
            var entity = new Dictionary<string, object>();
            entity.Add(TableStorage.PartitionKey, p);
            entity.Add(TableStorage.RowKey, r);
            await storage.InsertOrReplace(entity);

            var e = storage.QueryByPartitionAndRow<TableEntity>(p, r);
            Assert.IsNotNull(e);
            Assert.AreEqual(entity[TableStorage.PartitionKey], e.PartitionKey);
            Assert.AreEqual(entity[TableStorage.RowKey], e.RowKey);
        }

        [Test]
        public async Task InsertOrReplaceDictionaryNoRow()
        {
            var p = Guid.NewGuid().ToString();
            var entity = new Dictionary<string, object>();
            entity.Add(TableStorage.PartitionKey, p);
            await storage.InsertOrReplace(entity);

            var returned = storage.QueryByPartition<TableEntity>(p);
            Assert.IsNotNull(returned);
            Assert.AreEqual(1, returned.Count());
            var e = returned.FirstOrDefault();
            Assert.AreEqual(entity[TableStorage.PartitionKey], e.PartitionKey);
        }<commit_msg>storing more datas<commit_after>﻿namespace King.Service.Integration
{
    using King.Azure.Data;
    using Microsoft.WindowsAzure.Storage.Table;
    using NUnit.Framework;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;

    [TestFixture]
    public class TableStorageTests
    {
        #region Members
        private readonly string ConnectionString = "UseDevelopmentStorage=true;";
        private ITableStorage storage = null;
        #endregion

        public class Helper : TableEntity
        {
            public Guid Id
            {
                get;
                set;
            }
        }

        [SetUp]
        public void Init()
        {
            var table = "testing";
            this.storage = new TableStorage(table, ConnectionString);
            storage.CreateIfNotExists().Wait();
        }
        
        [TearDown]
        public void Dispose()
        {
            storage.Delete().Wait();
        }

        [Test]
        public async Task CreateIfNotExists()
        {
            var table = 'a' + Guid.NewGuid().ToString().ToLowerInvariant().Replace('-', 'a');
            var storage = new TableStorage(table, ConnectionString);
            var created = await storage.CreateIfNotExists();

            Assert.IsTrue(created);

            await storage.Delete();
        }

        [Test]
        public async Task CreateIfNotExistsAlreadyExists()
        {
            var table = 'a' + Guid.NewGuid().ToString().ToLowerInvariant().Replace('-', 'a');
            var storage = new TableStorage(table, ConnectionString);
            var created = await storage.CreateIfNotExists();

            Assert.IsTrue(created);
            created = await storage.CreateIfNotExists();
            Assert.IsFalse(created);

            await storage.Delete();
        }

        [Test]
        public async Task Create()
        {
            var table = 'a' + Guid.NewGuid().ToString().ToLowerInvariant().Replace('-', 'a');
            var storage = new TableStorage(table, ConnectionString);
            var created = await storage.Create();

            Assert.IsTrue(created);

            await storage.Delete();
        }

        [Test]
        public async Task Delete()
        {
            var table = 'a' + Guid.NewGuid().ToString().ToLowerInvariant().Replace('-', 'a');
            var storage = new TableStorage(table, ConnectionString);
            var created = await storage.Create();

            Assert.IsTrue(created);

            await storage.Delete();

            created = await storage.Create();
            Assert.IsTrue(created);

            await storage.Delete();
        }

        [Test]
        public async Task Insert()
        {
            var entity = new TableEntity()
            {
                PartitionKey = "partition",
                RowKey = "row",
            };
            var entities = new List<TableEntity>();
            entities.Add(entity);
            await storage.Insert(entities);

            var returned = storage.QueryByPartition<TableEntity>("partition");
            Assert.IsNotNull(returned);
            Assert.AreEqual(1, returned.Count());
            var e = returned.First();
            Assert.AreEqual(entity.PartitionKey, e.PartitionKey);
            Assert.AreEqual(entity.RowKey, e.RowKey);
        }

        [Test]
        public async Task InsertOrReplace()
        {
            var entity = new TableEntity()
            {
                PartitionKey = "partition",
                RowKey = "row",
            };
            var entities = new List<TableEntity>();
            entities.Add(entity);
            await storage.Insert(entities);
            await storage.InsertOrReplace(entity);

            var returned = storage.QueryByPartition<TableEntity>("partition");
            Assert.IsNotNull(returned);
            Assert.AreEqual(1, returned.Count());
            var e = returned.First();
            Assert.AreEqual(entity.PartitionKey, e.PartitionKey);
            Assert.AreEqual(entity.RowKey, e.RowKey);
        }

        [Test]
        public async Task InsertOrReplaceDictionary()
        {
            var p = Guid.NewGuid().ToString();
            var r = Guid.NewGuid().ToString();
            var entity = new Dictionary<string, object>();
            entity.Add(TableStorage.PartitionKey, p);
            entity.Add(TableStorage.RowKey, r);
            entity.Add("Id", Guid.NewGuid());
            await storage.InsertOrReplace(entity);

            var e = storage.QueryByPartitionAndRow<Helper>(p, r);
            Assert.IsNotNull(e);
            Assert.AreEqual(entity[TableStorage.PartitionKey], e.PartitionKey);
            Assert.AreEqual(entity[TableStorage.RowKey], e.RowKey);
            Assert.AreEqual(entity["Id"], e.Id);
        }

        [Test]
        public async Task InsertOrReplaceDictionaryNoRow()
        {
            var p = Guid.NewGuid().ToString();
            var entity = new Dictionary<string, object>();
            entity.Add(TableStorage.PartitionKey, p);
            await storage.InsertOrReplace(entity);

            var returned = storage.QueryByPartition<TableEntity>(p);
            Assert.IsNotNull(returned);
            Assert.AreEqual(1, returned.Count());
            var e = returned.FirstOrDefault();
            Assert.AreEqual(entity[TableStorage.PartitionKey], e.PartitionKey);
        }
{'fraction_non_alphanumeric': 0.10945733567532588, 'fraction_numerical': 0.0005546824443006379, 'mean_word_length': 1.7845559845559846, 'pattern_counts': {'":': 0, '<': 19, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5708256', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2641, 'n_words': 572}