コード例 #1
0
        public void SetUpUpdateCascadeSettings()
        {
            var setting = new UpdateCascadeSetting
            {
                ReferencedEntityName = "Categories",
                DenormalizedReferencePropertyNames = new List <string>
                {
                    "Name"
                },
                ReferencingCollections = new Dictionary <string, ReferencingCollectionSetting>
                {
                    {
                        "Products",
                        new ReferencingCollectionSetting
                        {
                            IndexName                         = "Products/ByCategoryId",
                            ReferencingEntityName             = "Products",
                            ReferencingPropertyPath           = "Category",
                            ReferencedEtagPropertyNameInIndex = "Etag",
                            ReferencedIdPropertyNameInIndex   = "CategoryId"
                        }
                    }
                }
            };

            using (var session = this.Store.OpenSession())
            {
                session.Store(setting);
                session.SaveChanges();

                var s = session.Advanced.DocumentStore.DatabaseCommands.Get(setting.Id);
            }
        }
コード例 #2
0
        public void UpdateCascadeShouldWork()
        {
            using (var session = this.Store.OpenSession())
            {
                var startedTime = DateTime.UtcNow;
                var category    = session.Load <Category>("Categories/1");
                var newName     = category.Name + " new Name";
                category.Name = newName;
                session.SaveChanges();
                category.Etag = session.Advanced.GetMetadataFor(category).Value <Guid>("@etag");
                UpdateCascadeOperation operation = null;

                var waitTaks = Task.Factory.StartNew(() =>
                {
                    operation = WaitOperationToComplete(category);
                });

                if (!waitTaks.Wait(TimeSpan.FromSeconds(20)))
                {
                    throw new TimeoutException("The cascade operation did not completed within the allotted time");
                }



                Assert.Equal(UpdateCascadeOperation.GetId(category.Id, category.Etag.Value), operation.Id);
                Assert.Equal(true, operation.IsCompleted);
                Assert.Equal(1, operation.CollectionOperations.Count);
                Assert.Equal(category.Etag, operation.ReferencedDocEtag);
                Assert.Equal(category.Id, operation.ReferencedDocId);
                Assert.Equal(UpdateCascadeOperationStatus.CompletedSuccessfully, operation.Status);
                Assert.Equal(UpdateCascadeSetting.GetId("Categories"), operation.UpdateCascadeSettingId);
                Assert.Equal(productsPerCategory, operation.UpdatedDocumentCount);
                Assert.InRange(operation.StartedDate.Value, startedTime, DateTime.UtcNow);
                Assert.InRange(operation.CompletedDate.Value, startedTime, DateTime.UtcNow);

                for (int productNumber = 1; productNumber <= productsPerCategory; productNumber++)
                {
                    var productId = category.Id + "/Products/" + productNumber.ToString();
                    var product   = session.Load <Product>(productId);
                    Assert.Equal(category.Name, product.Category.Name);
                    Assert.Equal(category.Etag, product.Category.Etag);
                }
            }
        }