本文整理汇总了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);
//}
}
示例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();
}
示例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());
}
示例4: Setup
public void Setup()
{
_aggregate = AggregateStubs.Stub1;
_sut = new UnitOfWork();
_sut.Attach(_aggregate);
}
示例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);
}
示例6: SetUp
public void SetUp()
{
_aggregate = new Aggregate(Guid.NewGuid(), Aggregate.InitialVersion, new DummyAggregateRootEntity());
_sut = new UnitOfWork();
_sut.Attach(_aggregate);
}