Esempio n. 1
0
 private static bool CanSafelyPruneMerge(IdentifyingInfo idInfo, ILexEntry entry)
 {
     return(entry != null &&
            entry.DateModified == idInfo.modificationTime &&
            entry.DateModified.Kind != DateTimeKind.Unspecified &&
            idInfo.modificationTime.Kind != DateTimeKind.Unspecified);
 }
Esempio n. 2
0
        public void GetFetchSqlTest()
        {
            var id    = HelperObjectFactory.GetRandomInt(0, 100);
            var value = new IdentifyingInfo
            {
                Id = id
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new GenreTable();
            var expected   = $"SELECT * FROM {TableFactory<Genre>.GetTable<GenreTable>().TableName} WHERE {GenreTable.IdColumnName} = @{GenreTable.IdColumnName};";

            Assert.AreEqual(expected, table.GetFetchSql(value, ref parameters));
            Assert.AreEqual(1, parameters.Count);
            parameters.Clear();

            value = new IdentifyingInfo
            {
                Name = StringExtensions.GetRandomStringAsync(25).Result
            };

            expected = $"SELECT * FROM {TableFactory<Genre>.GetTable<GenreTable>().TableName} WHERE {GenreTable.NameColumnName} = @{GenreTable.NameColumnName};";

            Assert.AreEqual(expected, table.GetFetchSql(value, ref parameters));
            Assert.AreEqual(1, parameters.Count);
        }
Esempio n. 3
0
        public ILexExampleSentence GetOrMakeExample(ILexSense sense, IdentifyingInfo idInfo)
        {
            //nb, has no guid or dates
            ILexExampleSentence x = new LexExampleSentence();

            sense.ExamplesOS.Append(x);
            return(x);
        }
Esempio n. 4
0
        private static IdentifyingInfo CreateFullIdInfo(Guid g)
        {
            IdentifyingInfo idInfo = new IdentifyingInfo();

            idInfo.id = g.ToString();
            idInfo    = AddDates(idInfo);
            return(idInfo);
        }
Esempio n. 5
0
        public void NewEntryWithGuid()
        {
            IdentifyingInfo idInfo = new IdentifyingInfo();

            idInfo.id = Guid.NewGuid().ToString();
            ILexEntry e = _merger.GetOrMakeEntry(idInfo);

            Assert.AreEqual(idInfo.id, e.Guid.ToString());
        }
Esempio n. 6
0
        public void GetHashCodeTest()
        {
            var swc1 = HelperObjectFactory.MakeIdentifyingInfo();
            var swc2 = HelperObjectFactory.MakeIdentifyingInfo();
            var swc3 = new IdentifyingInfo(swc1);

            Assert.AreEqual(swc1.GetHashCode(), swc1.GetHashCode());
            Assert.AreEqual(swc1.GetHashCode(), swc3.GetHashCode());
            Assert.AreNotEqual(swc1.GetHashCode(), swc2.GetHashCode());
        }
Esempio n. 7
0
        public void NewEntryTakesGivenDates()
        {
            IdentifyingInfo idInfo = new IdentifyingInfo();

            idInfo = AddDates(idInfo);

            ILexEntry e = _merger.GetOrMakeEntry(idInfo);

            Assert.AreEqual(idInfo.creationTime, e.DateCreated);
            Assert.AreEqual(idInfo.modificationTime, e.DateModified);;
        }
Esempio n. 8
0
        private ILexSense CreateSense(ILexEntry entry, ref IdentifyingInfo idInfo, ref Guid guid)
        {
            ILexSense s = new LexSense();

            entry.SensesOS.Append(s);
            if (guid != Guid.Empty)
            {
                SetGuid(s, guid);
            }
            return(s);
        }
Esempio n. 9
0
        [Test] public void NewEntryWithTextIdIgnoresIt()
        {
            IdentifyingInfo idInfo = new IdentifyingInfo();

            idInfo.id = "hello";
            ILexEntry e = _merger.GetOrMakeEntry(idInfo);

            //no attempt is made to use that id
            Assert.IsNotNull(e.Guid);
            Assert.AreNotSame(Guid.Empty, e.Guid);
        }
Esempio n. 10
0
        public void GetDeleteAlbumsByArtistSqlExceptionTest()
        {
            var value = new IdentifyingInfo
            {
                Id = null
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();

            Assert.That(() => table.GetDeleteAlbumsByArtistSql(value, ref parameters), Throws.ArgumentException);
        }
Esempio n. 11
0
        public void GetIdFromNameExceptionTest()
        {
            var id    = HelperObjectFactory.GetRandomInt(0, 100);
            var value = new IdentifyingInfo
            {
                Id = id
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();

            Assert.That(() => table.GetIdFromNameSql(value, ref parameters), Throws.ArgumentException);
        }
Esempio n. 12
0
        public void GetIdFromNameTest()
        {
            var value = new IdentifyingInfo
            {
                Name = StringExtensions.GetRandomStringAsync(25).Result
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();
            var expected   = $"SELECT {ArtistTable.IdColumnName} FROM {table.TableName} WHERE {ArtistTable.NameColumnName} = @{ArtistTable.NameColumnName};";

            Assert.AreEqual(expected, table.GetIdFromNameSql(value, ref parameters));
            Assert.AreEqual(1, parameters.Count);
        }
Esempio n. 13
0
        public void GetDeleteAlbumsByArtistSqlTest()
        {
            var id    = HelperObjectFactory.GetRandomInt(0, 100);
            var value = new IdentifyingInfo
            {
                Id = id
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();
            var expected   = $"DELETE FROM {TableFactory<Album>.GetTable<AlbumTable>().TableName} WHERE {AlbumTable.ArtistIdColumnName} = @{AlbumTable.ArtistIdColumnName};";

            Assert.AreEqual(expected, table.GetDeleteAlbumsByArtistSql(value, ref parameters));
            Assert.AreEqual(1, parameters.Count);
        }
Esempio n. 14
0
        /// <summary>
        ///     Creates a SQL query string to fetch a value from the database table based on criteria relevant to the type of
        ///     value.
        /// </summary>
        /// <param name="value">The value to use for data or criteria.</param>
        /// <param name="parameters">
        ///     A <see cref="List{T}" /> of <see cref="SQLiteParameter" /> populated with the values need to
        ///     complete the query.
        /// </param>
        public virtual string GetFetchSql(IdentifyingInfo value, ref List <SQLiteParameter> parameters)
        {
            if (value.Id.HasValue)
            {
                var idParameter = SqliteExtensions.Create(IdColumnName, DbType.Int32, value.Id.Value);
                parameters.Add(idParameter);
            }
            else if (!value.Name.IsNullOrEmpty())
            {
                var nameParameter = SqliteExtensions.Create(NameColumnName, DbType.String, value.Name);
                parameters.Add(nameParameter);
            }

            return($"SELECT * FROM {TableName} {GenerateWhereString(GenerateWhereClauses(parameters))};");
        }
Esempio n. 15
0
        public void GetCountSqlTest()
        {
            var id    = HelperObjectFactory.GetRandomInt(0, 100);
            var value = new IdentifyingInfo
            {
                Id = id
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new GenreTable();
            var expected   = $"SELECT COUNT(*) FROM {TableFactory<Genre>.GetTable<GenreTable>().TableName} WHERE {GenreTable.IdColumnName} = @{GenreTable.IdColumnName};";

            Assert.AreEqual(expected, table.GetCountSql(value, ref parameters));
            Assert.AreEqual(1, parameters.Count);
        }
Esempio n. 16
0
        public void EqualsTest()
        {
            var swc1 = HelperObjectFactory.MakeIdentifyingInfo();
            var swc2 = HelperObjectFactory.MakeIdentifyingInfo();
            var swc3 = new IdentifyingInfo(swc1);

            Assert.IsFalse(swc1.Equals((object)null));
            Assert.IsFalse(swc1.Equals(null));

            Assert.IsTrue(swc1.Equals((object)swc1));
            Assert.IsTrue(swc1.Equals(swc1));

            Assert.IsFalse(swc1.Equals(swc2));
            Assert.IsTrue(swc1.Equals(swc3));
        }
Esempio n. 17
0
        public ILexSense GetOrMakeSense(ILexEntry entry, IdentifyingInfo idInfo)
        {
            Guid      guid = GetGuidOrEmptyFromIdString(idInfo.id);
            bool      canPrune;
            ILexSense sense = TryToFindMatchingSense(guid, idInfo, out canPrune);

            if (canPrune)
            {
                return(null);
            }
            if (sense != null)
            {
                return(sense);
            }
            return(CreateSense(entry, ref idInfo, ref guid));
        }
Esempio n. 18
0
        [Test] public void ChangedEntryFound()
        {
            Guid            g      = Guid.NewGuid();
            IdentifyingInfo idInfo = CreateFullIdInfo(g);

            LexEntry e = new LexEntry();

            this.Cache.LangProject.LexDbOA.EntriesOC.Add(e);
            e.Guid         = g;
            e.DateCreated  = idInfo.creationTime;
            e.DateModified = new DateTime(e.DateCreated.Ticks + 100);

            ILexEntry found = _merger.GetOrMakeEntry(idInfo);

            Assert.AreEqual(idInfo.creationTime, found.DateCreated);
        }
Esempio n. 19
0
        public ILexEntry GetOrMakeEntry(IdentifyingInfo idInfo)
        {
            Guid      guid = GetGuidOrEmptyFromIdString(idInfo.id);
            bool      canPrune;
            ILexEntry entry = TryToFindMatchingEntry(guid, idInfo, out canPrune);

            if (canPrune)
            {
                return(null);
            }
            if (entry != null)
            {
                return(entry);
            }
            return(CreateEntry(ref idInfo, ref guid));
        }
Esempio n. 20
0
        public string GetDeleteAlbumsByArtistSql(IdentifyingInfo value, ref List <SQLiteParameter> parameters)
        {
            SQLiteParameter idParameter;

            if (value.Id.HasValue)
            {
                idParameter = SqliteExtensions.Create(AlbumTable.ArtistIdColumnName, DbType.Int32, value.Id.Value);
                parameters.Add(idParameter);
            }
            else
            {
                throw new ArgumentException(Resources.IdOrNameNotProvided, nameof(value));
            }

            return($"DELETE FROM {_albumTable.TableName} WHERE {AlbumTable.ArtistIdColumnName} = {idParameter.ParameterName};");
        }
Esempio n. 21
0
        /// <summary>
        ///     Creates a SQL query string to fetch the id of an item from its name
        /// </summary>
        /// <param name="value">The value to use for data or criteria.</param>
        /// <param name="parameters">
        ///     A <see cref="List{T}" /> of <see cref="SQLiteParameter" /> populated with the values need to
        ///     complete the query.
        /// </param>
        public virtual string GetIdFromNameSql(IdentifyingInfo value, ref List <SQLiteParameter> parameters)
        {
            SQLiteParameter nameParameter;

            if (!value.Name.IsNullOrEmpty())
            {
                nameParameter = SqliteExtensions.Create(NameColumnName, DbType.String, value.Name);
                parameters.Add(nameParameter);
            }
            else
            {
                throw new ArgumentException(Resources.IdOrNameNotProvided, nameof(value));
            }

            return($"SELECT {IdColumnName} FROM {TableName} WHERE {NameColumnName} = {nameParameter.ParameterName};");
        }
Esempio n. 22
0
        private ILexSense TryToFindMatchingSense(Guid guid, IdentifyingInfo idInfo, out bool canPrune)
        {
            canPrune = false;             //no date info avail on senses
            ILexSense sense = null;

            if (guid != Guid.Empty)
            {
                int hvo = _cache.GetIdFromGuid(guid);
                if (hvo > 0)
                {
                    sense = LexSense.CreateFromDBObject(_cache, hvo);
                }
                return(sense);
            }
            return(null);
        }
Esempio n. 23
0
        public void ConstructorAndPropertiesTests()
        {
            int?         id         = HelperObjectFactory.GetRandomInt();
            const string filterText = "filter text";
            var          name       = StringExtensions.GetRandomStringAsync(25).Result;

            var ii = HelperObjectFactory.MakeIdentifyingInfo(id, filterText, name);

            Assert.AreEqual(id, ii.Id);
            Assert.AreEqual(filterText, ii.FilterText);
            Assert.AreEqual(name, ii.Name);

            var ii2 = new IdentifyingInfo(ii);

            Assert.AreEqual(id, ii2.Id);
            Assert.AreEqual(filterText, ii2.FilterText);
            Assert.AreEqual(name, ii2.Name);
        }
Esempio n. 24
0
        private ILexEntry TryToFindMatchingEntry(Guid guid, IdentifyingInfo idInfo, out bool canPrune)
        {
            ILexEntry entry = null;

            if (guid != Guid.Empty)
            {
                int hvo = _cache.GetIdFromGuid(guid);
                if (hvo > 0)
                {
                    entry = LexEntry.CreateFromDBObject(_cache, hvo);
                }

                canPrune = CanSafelyPruneMerge(idInfo, entry);
                return(entry);
            }
            canPrune = false;
            return(null);
        }
Esempio n. 25
0
        /// <summary>
        ///     Creates a SQL query string to delete the rows meeting the criteria relevant to the type of value.
        /// </summary>
        /// <param name="value">The value to use for data or criteria.</param>
        /// <param name="parameters">
        ///     A <see cref="List{T}" /> of <see cref="SQLiteParameter" /> populated with the values need to
        ///     complete the query.
        /// </param>
        /// <exception cref="ArgumentException">Thrown if the id and name are both null.</exception>
        public virtual string GetDeleteSql(IdentifyingInfo value, ref List <SQLiteParameter> parameters)
        {
            if (value.Id.HasValue)
            {
                var idParameter = SqliteExtensions.Create(IdColumnName, DbType.Int32, value.Id.Value);
                parameters.Add(idParameter);
            }
            else if (!value.Name.IsNullOrEmpty())
            {
                var idParameter = SqliteExtensions.Create(NameColumnName, DbType.String, value.Name);
                parameters.Add(idParameter);
            }
            else
            {
                throw new ArgumentException(Resources.IdOrNameNotProvided, nameof(value));
            }

            return($"DELETE FROM {TableName} {GenerateWhereString(GenerateWhereClauses(parameters))};");
        }
Esempio n. 26
0
        private ILexEntry CreateEntry(ref IdentifyingInfo idInfo, ref Guid guid)
        {
            ILexEntry entry = new LexEntry();

            //entry.Guid = guid;  not avail yet
            _cache.LangProject.LexDbOA.EntriesOC.Add(entry);
            SetGuid(entry, guid);

            if (idInfo.creationTime > DateTime.MinValue)
            {
                entry.DateCreated = idInfo.creationTime;
            }

            if (idInfo.modificationTime > DateTime.MinValue)
            {
                entry.DateModified = idInfo.modificationTime;
            }
            return(entry);
        }
Esempio n. 27
0
        private ILexEntry MakeSimpleEntry()
        {
            IdentifyingInfo idInfo = new IdentifyingInfo();

            return(_merger.GetOrMakeEntry(idInfo));
        }
Esempio n. 28
0
		[Test] public void NewEntryWithTextIdIgnoresIt()
		{
			IdentifyingInfo idInfo = new IdentifyingInfo();
			idInfo.id = "hello";
			ILexEntry e = _merger.GetOrMakeEntry(idInfo);
			//no attempt is made to use that id
			Assert.IsNotNull(e.Guid);
			Assert.AreNotSame(Guid.Empty, e.Guid);
		}
Esempio n. 29
0
		public void NewEntryTakesGivenDates()
		{
			IdentifyingInfo idInfo = new IdentifyingInfo();
			idInfo = AddDates(idInfo);

			ILexEntry e = _merger.GetOrMakeEntry(idInfo);
			Assert.AreEqual(idInfo.creationTime, e.DateCreated );
			Assert.AreEqual(idInfo.modificationTime, e.DateModified);;
		}
Esempio n. 30
0
		private static IdentifyingInfo AddDates(IdentifyingInfo idInfo)
		{
			idInfo.creationTime = DateTime.Parse("2003-08-07T08:42:42+07:00");
			idInfo.modificationTime = DateTime.Parse("2005-01-01T01:11:11+01:00");
			return idInfo;
		}
Esempio n. 31
0
		private ILexEntry MakeSimpleEntry()
		{
			IdentifyingInfo idInfo = new IdentifyingInfo();
			return _merger.GetOrMakeEntry(idInfo);
		}
Esempio n. 32
0
 private static IdentifyingInfo AddDates(IdentifyingInfo idInfo)
 {
     idInfo.creationTime     = DateTime.Parse("2003-08-07T08:42:42+07:00");
     idInfo.modificationTime = DateTime.Parse("2005-01-01T01:11:11+01:00");
     return(idInfo);
 }
Esempio n. 33
0
		public void NewEntryWithGuid()
		{
			IdentifyingInfo idInfo = new IdentifyingInfo();
			idInfo.id = Guid.NewGuid().ToString();
			ILexEntry e = _merger.GetOrMakeEntry(idInfo);
			Assert.AreEqual(idInfo.id, e.Guid.ToString());
		}
Esempio n. 34
0
		private static IdentifyingInfo CreateFullIdInfo(Guid g)
		{
			IdentifyingInfo idInfo = new IdentifyingInfo();
			idInfo.id = g.ToString();
			idInfo = AddDates(idInfo);
			return idInfo;
		}