public void IntegrationTest() { var connection = TestSession.GetConnection(); connection.Open(); #region good insertion and select by id test ProductDocumentModel inserted = new ProductDocumentModel(); inserted.ProductID = TestSession.Random.Next(); inserted.DocumentNode = Microsoft.SqlServer.Types.SqlHierarchyId.Null; //TODO define how to generate random hierarchy id in test session; inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Insert(connection, new[] { inserted }); var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new ProductDocumentModelPrimaryKey() { ProductID = inserted.ProductID, DocumentNode = inserted.DocumentNode, }); CollectionAssert.IsNotEmpty(selectedAfterInsertion); var selectedAfterInsert = selectedAfterInsertion.Single(); Assert.AreEqual(inserted.ProductID, selectedAfterInsert.ProductID); Assert.AreEqual(inserted.DocumentNode, selectedAfterInsert.DocumentNode); Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate); #endregion #region update and select by id test inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Update(connection, new[] { inserted }); var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new ProductDocumentModelPrimaryKey() { ProductID = inserted.ProductID, DocumentNode = inserted.DocumentNode, }); CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss); var selectedAfterUpdate = selectedAfterUpdateAddresss.Single(); Assert.AreEqual(inserted.ProductID, selectedAfterUpdate.ProductID); Assert.AreEqual(inserted.DocumentNode, selectedAfterUpdate.DocumentNode); Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate); #endregion #region delete test _tested.Delete(connection, new[] { inserted }); var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new ProductDocumentModelPrimaryKey() { ProductID = inserted.ProductID, DocumentNode = inserted.DocumentNode, }); CollectionAssert.IsEmpty(selectedAfterDeleteAddresss); #endregion connection.Close(); }
public static int CreateProduct (int id, int productId, XmlDocument document) { ProductDocumentModel productdocument = new ProductDocumentModel { Id = id, ProductId = productId, Document = document }; string sql = @"insert into dbo.ProductDocument (Id, ProductId, Document) values (@Id, @ProductId, @Document);"; return(SQLDataAccess.SaveData(sql, productdocument)); }
public static void CreateProductDocumentInSearchIndex(string searchPartitionName, string searchIndexName, ProductDocumentModel productDocumentModel) { //Get from cache first var accountSearchIndex = Common.MemoryCacheManager.SearchIndexCache[searchIndexName] as ISearchIndexClient; if (accountSearchIndex == null) { //Not in cache, create: ---------------------------- //SearchServiceClient searchServiceClient = Settings.Azure.Search.AccountsSearchServiceClient; SearchServiceClient searchServiceClient = Settings.Azure.Search.GetSearchPartitionClient(searchPartitionName); accountSearchIndex = searchServiceClient.Indexes.GetClient(searchIndexName); //Store in cache: --------------------- Common.MemoryCacheManager.SearchIndexCache.Set(searchIndexName, accountSearchIndex, new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(Common.MemoryCacheManager.SearchIndexClientCacheTimeInMinutes) }); } //SearchServiceClient searchServiceClient = Settings.Azure.Search.AccountsSearchServiceClient; //var searchServiceClient = Settings.Azure.Search.GetSearchPartitionClient(searchPartitionName); //var searchIndexClient = searchServiceClient.Indexes.GetClient(searchIndexName); //Microsoft.Azure.Search.Models.DocumentIndexResult documentIndexResult = null; #region Convert to list of search documents to add/update dynamic productSearchModel = new ProductSearchModel() { id = productDocumentModel.Id, //AccountID = document.AccountID, //AccountNameKey = document.AccountNameKey, //DocumentType = document.DocumentType, fullyQualifiedName = productDocumentModel.FullyQualifiedName, locationPath = productDocumentModel.LocationPath, categoryName = productDocumentModel.CategoryName, subcategoryName = productDocumentModel.SubcategoryName, subsubcategoryName = productDocumentModel.SubsubcategoryName, subsubsubcategoryName = productDocumentModel.SubsubsubcategoryName, categoryNameKey = productDocumentModel.CategoryNameKey, subcategoryNameKey = productDocumentModel.SubcategoryNameKey, subsubcategoryNameKey = productDocumentModel.SubsubcategoryNameKey, subsubsubcategoryNameKey = productDocumentModel.SubsubsubcategoryNameKey, name = productDocumentModel.Name, nameKey = productDocumentModel.NameKey, orderId = productDocumentModel.OrderID, //OrderID = document.OrderID, //title = productDocumentModel.Title, visible = productDocumentModel.Visible, dateCreated = productDocumentModel.DateCreated }; #endregion var searchUpdateBatch = new List <dynamic>(); searchUpdateBatch.Add(productSearchModel); var uploadOrMergeAction = IndexBatch.MergeOrUpload(searchUpdateBatch.ToArray()); Microsoft.Azure.Search.Models.DocumentIndexResult documentIndexResult = null; documentIndexResult = accountSearchIndex.Documents.Index(uploadOrMergeAction); }