<commit_before>﻿using System;
using System.Linq;
using NUnit.Framework;

namespace BrightstarDB.Tests.EntityFramework
{
    [TestFixture]
    public class DataTypeTests
    {
        private MyEntityContext _myEntityContext;

        private readonly string _connectionString = "Type=embedded;StoresDirectory=c:\\brightstar;StoreName=" + Guid.NewGuid();

        [TestFixtureSetUp]
        public void SetUp()
        {
            _myEntityContext = new MyEntityContext(_connectionString);
        }

        [Test]
        public void TestCreateAndSetProperties()
        {
            var entity = _myEntityContext.Entities.Create();
            var now = DateTime.Now;
            entity.SomeDateTime = now;
            entity.SomeDecimal = 3.14m;
            entity.SomeDouble = 3.14;
            entity.SomeFloat = 3.14F;
            entity.SomeInt = 3;
            entity.SomeNullableDateTime = null;
            entity.SomeNullableInt = null;
            entity.SomeString = "test entity";

            entity.SomeBool = true;
            entity.SomeLong = 50L;

            _myEntityContext.SaveChanges();
            var entityId = entity.Id;

            var newContext = new MyEntityContext(_connectionString);
            var checkEntity = newContext.Entities.FirstOrDefault(e => e.Id.Equals(entityId));

            Assert.IsNotNull(checkEntity);
            Assert.IsNotNull(checkEntity.SomeDateTime);
            Assert.IsNotNull(checkEntity.SomeDecimal);
            Assert.IsNotNull(checkEntity.SomeDouble);
            Assert.IsNotNull(checkEntity.SomeFloat);
            Assert.IsNotNull(checkEntity.SomeInt);
            Assert.IsNull(checkEntity.SomeNullableDateTime);
            Assert.IsNull(checkEntity.SomeNullableInt);
            Assert.IsNotNull(checkEntity.SomeString);

            Assert.AreEqual(now, checkEntity.SomeDateTime);
            Assert.AreEqual(3.14m, checkEntity.SomeDecimal);
            Assert.AreEqual(3.14, checkEntity.SomeDouble);
            Assert.AreEqual(3.14F, checkEntity.SomeFloat);
            Assert.AreEqual(3, checkEntity.SomeInt);
            Assert.AreEqual("test entity", checkEntity.SomeString);
            Assert.IsTrue(checkEntity.SomeBool);
            Assert.AreEqual(50L, checkEntity.SomeLong);          
        }


        [Test]
        public void TestCreateAndSetCollections()
        {<commit_msg>Unit test to try to replicate issue #128<commit_after>﻿using System;
using System.Linq;
using NUnit.Framework;

namespace BrightstarDB.Tests.EntityFramework
{
    [TestFixture]
    public class DataTypeTests
    {
        private MyEntityContext _myEntityContext;

        private readonly string _connectionString = "Type=embedded;StoresDirectory=c:\\brightstar;StoreName=" + Guid.NewGuid();

        [TestFixtureSetUp]
        public void SetUp()
        {
            _myEntityContext = new MyEntityContext(_connectionString);
        }

        [Test]
        public void TestCreateAndSetProperties()
        {
            var entity = _myEntityContext.Entities.Create();
            var now = DateTime.Now;
            entity.SomeDateTime = now;
            entity.SomeDecimal = 3.14m;
            entity.SomeDouble = 3.14;
            entity.SomeFloat = 3.14F;
            entity.SomeInt = 3;
            entity.SomeNullableDateTime = null;
            entity.SomeNullableInt = null;
            entity.SomeString = "test entity";

            entity.SomeBool = true;
            entity.SomeLong = 50L;

            _myEntityContext.SaveChanges();
            var entityId = entity.Id;

            var newContext = new MyEntityContext(_connectionString);
            var checkEntity = newContext.Entities.FirstOrDefault(e => e.Id.Equals(entityId));

            Assert.IsNotNull(checkEntity);
            Assert.IsNotNull(checkEntity.SomeDateTime);
            Assert.IsNotNull(checkEntity.SomeDecimal);
            Assert.IsNotNull(checkEntity.SomeDouble);
            Assert.IsNotNull(checkEntity.SomeFloat);
            Assert.IsNotNull(checkEntity.SomeInt);
            Assert.IsNull(checkEntity.SomeNullableDateTime);
            Assert.IsNull(checkEntity.SomeNullableInt);
            Assert.IsNotNull(checkEntity.SomeString);

            Assert.AreEqual(now, checkEntity.SomeDateTime);
            Assert.AreEqual(3.14m, checkEntity.SomeDecimal);
            Assert.AreEqual(3.14, checkEntity.SomeDouble);
            Assert.AreEqual(3.14F, checkEntity.SomeFloat);
            Assert.AreEqual(3, checkEntity.SomeInt);
            Assert.AreEqual("test entity", checkEntity.SomeString);
            Assert.IsTrue(checkEntity.SomeBool);
            Assert.AreEqual(50L, checkEntity.SomeLong);          
        }

        [Test]
        public void TestIssue128CannotSetFloatValueBelow1()
        {
            // Create an entity
            var entity = _myEntityContext.Entities.Create();
            // Set the properties that allow fractional values to values < 1.0
            entity.SomeDecimal = 0.14m;
            entity.SomeDouble = 0.14;
            entity.SomeFloat = 0.14F;
            // Persist the changes
            _myEntityContext.SaveChanges();
            var entityId = entity.Id;

            // Create a new context connection so that we don't get a locally cached value from the context
            var newContext = new MyEntityContext(_connectionString);
            // Retrieve the previously created entity
            var checkEntity = newContext.Entities.FirstOrDefault(e => e.Id.Equals(entityId));

            // Assert that the entity was found and the values we set are set to the values we originally provided
            Assert.IsNotNull(checkEntity);
            Assert.IsNotNull(checkEntity.SomeDecimal);
            Assert.IsNotNull(checkEntity.SomeDouble);
            Assert.IsNotNull(checkEntity.SomeFloat);
            Assert.AreEqual(0.14m, checkEntity.SomeDecimal);
            Assert.AreEqual(0.14, checkEntity.SomeDouble);
            Assert.AreEqual(0.14F, checkEntity.SomeFloat);
        }

        [Test]
        public void TestCreateAndSetCollections()
        {
{'fraction_non_alphanumeric': 0.08766180566934295, 'fraction_numerical': 0.012289038177945273, 'mean_word_length': 2.18580375782881, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '6887445', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1545, 'n_words': 299}