当前位置: 首页>>代码示例>>C#>>正文


C# UnitOfWork.Attach方法代码示例

本文整理汇总了C#中UnitOfWork.Attach方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.Attach方法的具体用法?C# UnitOfWork.Attach怎么用?C# UnitOfWork.Attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnitOfWork的用法示例。


在下文中一共展示了UnitOfWork.Attach方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AttachShouldIgnoreOldValues

        public void AttachShouldIgnoreOldValues()
        {
            var player = new User("Egor", "qwerty", "HUID", true, 24, "http://pushuri", "Belarus");

            using (var dc1 = new UnitOfWork())
            {
                dc1.UsersRepository.Add(player);
                player.Friends.Add(new User("Friend1", "2", "HUID2", true, 25, "http://pushuri2", "Norway"));
                dc1.SaveChanges();
            }

            //these changes should not be saved into db 
            player.ChangeName("ThisNameShouldNotBeSavedToDbOnNextSaveChanges");

            using (var dc2 = new UnitOfWork())
            {
                dc2.Attach(player);
                player.Friends.Add(new User("Friend2", "3", "HUID3", true, 26, "http://pushuri3", "Norway"));
                player.ChangeCountry("USA");
                dc2.SaveChanges();
            }

            using (var dc3 = new UnitOfWork())
            {
                User persistedUser = dc3.UsersRepository.FirstMatching(UserSpecification.Id(player.Id));
                Assert.AreEqual("Egor", persistedUser.Name);
                Assert.AreEqual("USA", persistedUser.Country);
                Assert.AreEqual(2, persistedUser.Friends.Count);

                persistedUser.Friends.Add(new User("Friend3", "4", "HUID4", true, 27, "http://pushuri4", "Norway"));
                dc3.SaveChanges();
            }

            //using (var dc4 = new UnitOfWork())
            //{
            //    dc4.Attach(player);
            //    Assert.AreEqual(3, player.Friends.Count);
            //}
        }
开发者ID:jorik041,项目名称:CrossChat,代码行数:39,代码来源:EfTrackingTests.cs

示例2: SetUp

 public void SetUp()
 {
     _model = new Model();
     _root = SnapshotableAggregateRootEntityStub.Factory();
     _unitOfWork = new UnitOfWork();
     _unitOfWork.Attach(new Aggregate(_model.KnownIdentifier, 0, _root));
     _sut = new RepositoryScenarioBuilder().
         WithUnitOfWork(_unitOfWork).
         ScheduleSnapshots(new Snapshot(_model.KnownIdentifier, 100, new object())).
         BuildForSnapshotableRepository();
 }
开发者ID:EsbenSkovPedersen,项目名称:AggregateSource,代码行数:11,代码来源:SnapshotableRepositoryTests.cs

示例3: SetUp

 public void SetUp()
 {
     _root = AggregateRootEntityStub.Factory();
     _unitOfWork = new UnitOfWork();
     _unitOfWork.Attach(new Aggregate(Model.KnownIdentifier, 0, _root));
     _sut = new Repository<AggregateRootEntityStub>(AggregateRootEntityStub.Factory, _unitOfWork,
                                                    new EmptyEventStreamReader());
 }
开发者ID:jen20,项目名称:AggregateSource,代码行数:8,代码来源:RepositoryTests.cs

示例4: Setup

 public void Setup()
 {
     _aggregate = AggregateStubs.Stub1;
     _sut = new UnitOfWork();
     _sut.Attach(_aggregate);
 }
开发者ID:EsbenSkovPedersen,项目名称:AggregateSource,代码行数:6,代码来源:UnitOfWorkTests.cs

示例5: SetUp

 public void SetUp()
 {
     EmbeddedEventStore.Instance.Connection.DeleteAllStreams();
     _model = new Model();
     _root = SnapshotableAggregateRootEntityStub.Factory();
     _unitOfWork = new UnitOfWork();
     _unitOfWork.Attach(new Aggregate(_model.KnownIdentifier, 0, _root));
     _resolver = A.Fake<IStreamNameResolver>();
     _reader = A.Fake<ISnapshotReader>();
     _state = new object();
     A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier);
     A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier);
     A.CallTo(() => _reader.ReadOptional(_model.KnownIdentifier))
      .Returns(new Optional<Snapshot>(new Snapshot(100, _state)));
     A.CallTo(() => _reader.ReadOptional(_model.UnknownIdentifier))
      .Returns(new Optional<Snapshot>(new Snapshot(100, _state)));
     _sut = new SnapshotableRepository<SnapshotableAggregateRootEntityStub>(
         SnapshotableAggregateRootEntityStub.Factory,
         _unitOfWork,
         EmbeddedEventStore.Instance.Connection,
         EventReaderConfigurationFactory.CreateWithResolver(_resolver),
         _reader);
 }
开发者ID:jen20,项目名称:AggregateSource,代码行数:23,代码来源:SnapshotableRepositoryTests.cs

示例6: SetUp

 public void SetUp()
 {
     _aggregate = new Aggregate(Guid.NewGuid(), Aggregate.InitialVersion, new DummyAggregateRootEntity());
     _sut = new UnitOfWork();
     _sut.Attach(_aggregate);
 }
开发者ID:jfloodnet,项目名称:AggregateSource,代码行数:6,代码来源:UnitOfWorkTests.cs


注:本文中的UnitOfWork.Attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。