public void Should_Write_History_For_Tracked_Entities_Update_Complex()
        {
            /* Blog has Audited attribute. */

            int blog1Id;
            var newValue = new BlogEx {
                BloggerName = "blogger-2"
            };
            BlogEx originalValue;

            using (var uow = Resolve <IUnitOfWorkManager>().Begin())
            {
                var blog1 = _blogRepository.Single(b => b.More.BloggerName == "blogger-1");
                blog1Id = blog1.Id;

                originalValue = new BlogEx {
                    BloggerName = blog1.More.BloggerName
                };
                blog1.More.BloggerName = newValue.BloggerName;
                _blogRepository.Update(blog1);

                uow.Complete();
            }

            Predicate <EntityChangeSet> predicate = s =>
            {
                s.EntityChanges.Count.ShouldBe(1);

                var entityChange = s.EntityChanges[0];
                entityChange.ChangeType.ShouldBe(EntityChangeType.Updated);
                entityChange.EntityId.ShouldBe(blog1Id.ToJsonString());
                entityChange.EntityTypeFullName.ShouldBe(typeof(Blog).FullName);
                entityChange.PropertyChanges.Count.ShouldBe(1);

                var propertyChange = entityChange.PropertyChanges.First();
                propertyChange.NewValue.ShouldBe(newValue.ToJsonString());
                propertyChange.OriginalValue.ShouldBe(originalValue.ToJsonString());
                propertyChange.PropertyName.ShouldBe(nameof(Blog.More));
                propertyChange.PropertyTypeFullName.ShouldBe(typeof(Blog).GetProperty(nameof(Blog.More)).PropertyType.FullName);

                return(true);
            };

            _entityHistoryStore.Received().SaveAsync(Arg.Is <EntityChangeSet>(s => predicate(s)));
        }
Esempio n. 2
0
        public void Should_Write_History_For_Audited_Entities_Update_Complex()
        {
            /* Blog has Audited attribute. */

            int blog1Id  = 0;
            var newValue = new BlogEx {
                BloggerName = "blogger-2"
            };
            BlogEx originalValue = null;

            WithUnitOfWork(() =>
            {
                var blog1 = _blogRepository.Single(b => b.More.BloggerName == "blogger-1");
                blog1Id   = blog1.Id;

                originalValue = new BlogEx {
                    BloggerName = blog1.More.BloggerName
                };
                blog1.More.BloggerName = newValue.BloggerName;
                _blogRepository.Update(blog1);
            });

            Predicate <EntityChangeSet> predicate = s =>
            {
                s.EntityChanges.Count.ShouldBe(1);

                var entityChange = s.EntityChanges.Single(ec => ec.EntityTypeFullName == typeof(Blog).FullName);
                entityChange.ChangeType.ShouldBe(EntityChangeType.Updated);
                entityChange.EntityId.ShouldBe(blog1Id.ToJsonString());
                entityChange.PropertyChanges.Count.ShouldBe(1);

                var propertyChange = entityChange.PropertyChanges.Single(pc => pc.PropertyName == nameof(Blog.More));
                propertyChange.NewValue.ShouldBe(newValue.ToJsonString());
                propertyChange.OriginalValue.ShouldBe(originalValue.ToJsonString());
                propertyChange.PropertyTypeFullName.ShouldBe(typeof(Blog).GetProperty(nameof(Blog.More)).PropertyType
                                                             .FullName);

                return(true);
            };

            _entityHistoryStore.Received().Save(Arg.Is <EntityChangeSet>(s => predicate(s)));
        }