Example #1
0
        public void DeleteItemFromCacheById_Id_ItemIsNoLongerInResultSet()
        {
            PalasoTestItem itemToDelete = dataMapper.CreateItem();

            itemToDelete.StoredString = "Item 6";
            dataMapper.SaveItem(itemToDelete);

            //_results = dataMapper.GetItemsMatching(_queryToCache);
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            resultSetCacheUnderTest.DeleteItemFromCache(itemToDelete);

            //Would be a better test but ResultSets don't support equality checks
            //Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

            Assert.AreEqual(6, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
        }
Example #2
0
        public void UpdateItemInCache_ItemExists_ResultSetIsUpdatedAndSorted()
        {
            PalasoTestItem itemToModify = dataMapper.CreateItem();

            itemToModify.StoredString = "Item 6";
            dataMapper.SaveItem(itemToModify);

            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            itemToModify.StoredString = "Item 7";
            dataMapper.SaveItem(itemToModify);
            resultSetCacheUnderTest.UpdateItemInCache(itemToModify);

            Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
            Assert.AreEqual("Item 7", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
        }
Example #3
0
        public void UpdateItemInCache_ItemHasNotChanged_ResultSetIsNotChanged()
        {
            PalasoTestItem unmodifiedItem = dataMapper.CreateItem();

            unmodifiedItem.StoredString = "Item 6";
            dataMapper.SaveItem(unmodifiedItem);

            //_results = dataMapper.GetItemsMatching(_queryToCache);
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            resultSetCacheUnderTest.UpdateItemInCache(unmodifiedItem);

            //Would be a better test but ResultSets don't support equality checks
            //Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

            Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
            Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
        }
Example #4
0
        public void MultipleQueries_QueriedFieldsAreIdentical_ReturnsOnlyOneRecordToken()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            PalasoTestItem itemCreatedAfterCache = dataMapper.CreateItem();

            itemCreatedAfterCache.StoredString       = "Item 6";
            itemCreatedAfterCache.Child.StoredString = "Item 6";
            dataMapper.SaveItem(itemCreatedAfterCache);
            resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

            Assert.AreEqual(7, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
            Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
        }
Example #5
0
        public void UpdateItemInCache_ItemDoesNotExistInCacheButDoesInRepository_ItemIsAddedToResultSetAndSortedCorrectly()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            PalasoTestItem itemCreatedAfterCache = dataMapper.CreateItem();

            itemCreatedAfterCache.StoredString = "Item 6";
            dataMapper.SaveItem(itemCreatedAfterCache);
            resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

            Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
            Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
        }
Example #6
0
 private QueryBase GetQueryFilter(
     ListFilter listFilter
     ) =>
 QueryAdapter
 .CreateQuerySelect(
     GetTableName()
     , listFilter
     );
Example #7
0
 private QueryBase GetQueryKey(
     object keyValue
     ) =>
 QueryAdapter
 .CreateQueryGet(
     GetTableName()
     , GetPrimaryKey()
     , keyValue
     );
Example #8
0
 private QueryBase GetQueryFilter(
     ListFilter listFilter
     , OrderList orderList
     ) =>
 QueryAdapter
 .CreateQuerySelect(
     GetTableName()
     , listFilter
     , orderList
     );
Example #9
0
		public void Setup()
		{
			_repository = new MemoryRepository<TestItem>();
			PopulateRepositoryWithItemsForQuerying(_repository);
			_queryToCache = new QueryAdapter<TestItem>();
			_queryToCache.Show("StoredString");
			_results = _repository.GetItemsMatching(_queryToCache);
			_sortDefinitions = new SortDefinition[1];
			_sortDefinitions[0] = new SortDefinition("StoredString", Comparer<string>.Default);
		}
Example #10
0
 public void Setup()
 {
     dataMapper = new MemoryDataMapper <PalasoTestItem>();
     PopulateRepositoryWithItemsForQuerying(dataMapper);
     _queryToCache = new QueryAdapter <PalasoTestItem>();
     _queryToCache.ShowEach("StoredList");
     _results            = dataMapper.GetItemsMatching(_queryToCache);
     _sortDefinitions    = new SortDefinition[1];
     _sortDefinitions[0] = new SortDefinition("StoredList", Comparer <string> .Default);
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            SqlResult sqlResult = QueryAdapter.GetSql("Audits").Where("TableName", "Test").Compile();

            var a = MonoFrame.DataBase.DataAccess.Query(sqlResult);

            Console.ReadLine();
        }
Example #12
0
        public void Add_QueryNull_Throws()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            Assert.Throws <ArgumentNullException>(() => resultSetCacheUnderTest.Add(results, null));
        }
Example #13
0
        public int Delete(object keyValue)
        {
            var keyName = GetPrimaryKey();
            var q       =
                QueryAdapter
                .CreateQueryDelete(
                    GetTableName()
                    , keyName
                    );

            q.Parameters.Add(keyName, keyValue);
            return(QueryAdapter.Execute(q));
        }
Example #14
0
        public void DeleteAllItemsFromCache_AllItemsAreDeleted()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            resultSetCacheUnderTest.DeleteAllItemsFromCache();
            Assert.AreEqual(0, resultSetCacheUnderTest.GetResultSet().Count);
        }
        public IEnumerable <WeatherForecast> Get()
        {
            SqlResult sqlResult = QueryAdapter.GetSql("Audits").Where("TableName", "Test").Compile();

            var a   = ITGalax.DataBase.DataAccess.Query(sqlResult);
            var rng = new Random();

            return(Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
                   .ToArray());
        }
Example #16
0
        public List <Factura> Select(DateTime fecha)
        {
            var dr =
                QueryAdapter
                .GetDataReader(
                    new SqlQuery(
                        @"
						SELECT * 
						FROM Facturas F 
						WHERE F.Fecha = @fecha
						;

						SELECT DF.* 
						FROM Facturas F 
							INNER JOIN DetalleFactura DF ON
								F.IdFactura = DF.IdFactura 
						WHERE F.Fecha = @fecha
						;
						"
                        , new SqlParameterList {
                { "fecha", fecha }
            }
                        )
                    );

            var l =
                GetEnumerable(dr, false)
                .ToList();

            dr.NextResult();

            var ld =
                GetEnumerable <DetalleFactura>(dr)
                .ToList();

            l.ForEach(
                f =>
                f.ListaDetalle =
                    ld.Where(
                        d => d.IdFactura == f.IdFactura
                        )
                    .ToList()
                );

            ld = null;

            return(l);
        }
Example #17
0
        public void GetResultsOnQuery_AtLeastOneWithShow_OneItem()
        {
            // In the query below AtLeastOne and Show are siblings,
            // both are children of 'all'.
            QueryAdapter <PalasoTestItem> all = new QueryAdapter <PalasoTestItem>();

            all.AtLeastOne().Show("StoredString");
            List <IDictionary <string, object> > results = new List <IDictionary <string, object> >
                                                           (
                all.GetResults(item)
                                                           );

            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(null, results[0]["StoredString"]);
        }
Example #18
0
        public List <Cliente> Select(int idZona, int desde, int hasta)
        {
            var dr =
                QueryAdapter.GetDataReader(
                    new SqlQuery(
                        @"
						SELECT C.* 
						FROM Clientes C 
						WHERE C.IdAreaResponsabilidad = @idZona 
							AND C.Estatus = 1
						;
						SELECT K.* 
						FROM Clientes C 
							INNER JOIN Consumos K ON
								C.IdCliente = K.IdCliente
									AND K.Mes >= @desde
									AND K.Mes <= @hasta
						WHERE C.IdAreaResponsabilidad = @idZona 
							AND C.Estatus = 1
						;
						"                        , new SqlParameterList {
                { "idZona", idZona }
                , { "desde", desde }
                , { "hasta", hasta }
            }
                        )
                    );

            var lista = GetEnumerable(dr, false).ToList();

            dr.NextResult();

            var sublista = GetEnumerable <Consumo>(dr).ToList();

            //foreach (var i in lista)
            //{
            //	i.Consumos =
            //		sublista
            //		.Where(c => c.IdCliente == i.IdCliente)
            //		.ToList();
            //}

            sublista = null;

            return(lista);
        }
Example #19
0
        public void ResultSetContainsIdenticalRecordTokens_Throws()
        {
            PalasoTestItem itemFromWhichToCreateIdenticalRecordTokens = dataMapper.CreateItem();

            itemFromWhichToCreateIdenticalRecordTokens.StoredString = "Get me twice!";

            QueryAdapter <PalasoTestItem> query1 = new QueryAdapter <PalasoTestItem>();

            query1.Show("StoredString");
            QueryAdapter <PalasoTestItem> query2 = new QueryAdapter <PalasoTestItem>();

            query2.Show("StoredString");

            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions);

            resultSetCacheUnderTest.Add(dataMapper.GetItemsMatching(query1), query1);
            Assert.Throws <ArgumentException>(() => resultSetCacheUnderTest.Add(dataMapper.GetItemsMatching(query2), query2));
        }
Example #20
0
        protected T GetEntity(
            QueryBase query
            )
        {
            var dr =
                QueryAdapter
                .GetDataReader(
                    query
                    );

            T e = null;

            if (dr.Read())
            {
                e = GetEntity <T>(dr);
            }
            dr.Close();
            return(e);
        }
Example #21
0
        public int Insert(
            T entity
            )
        {
            var fields =
                entity
                .GetFields()
                .Where(p => !p.IsIdentity)
                .ToList();

            return
                (QueryAdapter
                 .Execute(
                     QueryAdapter
                     .CreateQueryInsert(
                         GetTableName()
                         , fields
                         )
                     ));
        }
Example #22
0
        public int Update(
            T row
            , IDbTransaction transaction
            )
        {
            var fields =
                row
                .GetFields()
                .ToList();

            return
                (QueryAdapter
                 .Execute(
                     QueryAdapter
                     .CreateQueryUpdate(
                         GetTableName()
                         , fields
                         , transaction
                         )
                     ));
        }
Example #23
0
 public IEnumerable <T> SelectAll(
     ) =>
 GetEnumerable(
     QueryAdapter.CreateQuerySelect(GetTableName())
     );
Example #24
0
		public void ResultSetContainsIdenticalRecordTokens_Throws()
		{
			TestItem itemFromWhichToCreateIdenticalRecordTokens = _repository.CreateItem();

			itemFromWhichToCreateIdenticalRecordTokens.StoredString = "Get me twice!";

			QueryAdapter<TestItem> query1 = new QueryAdapter<TestItem>();
			query1.Show("StoredString");
			QueryAdapter<TestItem> query2 = new QueryAdapter<TestItem>();
			query2.Show("StoredString");

			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions);
			resultSetCacheUnderTest.Add(_repository.GetItemsMatching(query1), query1);
			resultSetCacheUnderTest.Add(_repository.GetItemsMatching(query2), query2);
		}
Example #25
0
		public void DeleteAllItemsFromCache_AllItemsAreDeleted()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();
			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			resultSetCacheUnderTest.DeleteAllItemsFromCache();
			Assert.AreEqual(0, resultSetCacheUnderTest.GetResultSet().Count);
		}
Example #26
0
		public void DeleteItemFromCacheById_Id_ItemIsNoLongerInResultSet()
		{
			TestItem itemToDelete = _repository.CreateItem();
			itemToDelete.StoredString = "Item 6";
			_repository.SaveItem(itemToDelete);

			//_results = _repository.GetItemsMatching(_queryToCache);
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			resultSetCacheUnderTest.DeleteItemFromCache(itemToDelete);

			//Would be a better test but ResultSets don't support equality checks
			//Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

			Assert.AreEqual(6, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
		}
Example #27
0
		public void UpdateItemInCache_ItemHasNotChanged_ResultSetIsNotChanged()
		{
			TestItem unmodifiedItem = _repository.CreateItem();
			unmodifiedItem.StoredString = "Item 6";
			_repository.SaveItem(unmodifiedItem);

			//_results = _repository.GetItemsMatching(_queryToCache);
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			resultSetCacheUnderTest.UpdateItemInCache(unmodifiedItem);

			//Would be a better test but ResultSets don't support equality checks
			//Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

			Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
			Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
		}
Example #28
0
		public void UpdateItemInCache_ItemExists_ResultSetIsUpdatedAndSorted()
		{
			TestItem itemToModify = _repository.CreateItem();
			itemToModify.StoredString = "Item 6";
			_repository.SaveItem(itemToModify);

			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			itemToModify.StoredString = "Item 7";
			_repository.SaveItem(itemToModify);
			resultSetCacheUnderTest.UpdateItemInCache(itemToModify);

			Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
			Assert.AreEqual("Item 7", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
		}
Example #29
0
		public void UpdateItemInCache_ItemDoesNotExistInCacheButDoesInRepository_ItemIsAddedToResultSetAndSortedCorrectly()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			TestItem itemCreatedAfterCache = _repository.CreateItem();
			itemCreatedAfterCache.StoredString = "Item 6";
			_repository.SaveItem(itemCreatedAfterCache);
			resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

			Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
			Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
		}
Example #30
0
		public void MultipleQueries_QueriedFieldsAreIdentical_ReturnsOnlyOneRecordToken()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			TestItem itemCreatedAfterCache = _repository.CreateItem();
			itemCreatedAfterCache.StoredString = "Item 6";
			itemCreatedAfterCache.Child.StoredString = "Item 6";
			_repository.SaveItem(itemCreatedAfterCache);
			resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

			Assert.AreEqual(7, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
			Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
		}
Example #31
0
		public void Add_QueryNull_Throws()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, null);
		}
Example #32
0
 protected IEnumerable <T> GetEnumerable(
     QueryBase query
     ) =>
 GetEnumerable <T>(
     QueryAdapter.GetDataReader(query)
     );
Example #33
0
 public void BulkInsert(
     IEnumerable <BulkCliente> listaClientes
     )
 {
     QueryAdapter.BulkCopy(listaClientes.ToDataTable(), "Test", 1);
 }