本文整理汇总了C#中User.ChangeEmail方法的典型用法代码示例。如果您正苦于以下问题:C# User.ChangeEmail方法的具体用法?C# User.ChangeEmail怎么用?C# User.ChangeEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.ChangeEmail方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanSaveAndLoadAggregate
public void CanSaveAndLoadAggregate()
{
var store = CreateStore();
var user = new User();
user.Register("[email protected]", "password", Guid.NewGuid());
user.ChangePassword("NewPassword");
user.ChangeEmail("NewEmail");
using (var session = OpenSession(store))
{
session.Save(user);
session.SaveChanges();
}
using (var session = OpenSession(store))
{
var loadedUser = session.Get<User>(user.Id);
Assert.That(loadedUser.Id, Is.EqualTo(user.Id));
Assert.That(loadedUser.Email, Is.EqualTo(user.Email));
Assert.That(loadedUser.Password, Is.EqualTo(user.Password));
}
}
示例2: After_migrated_should_get_ordinal_events
public void After_migrated_should_get_ordinal_events()
{
var user = new User();
user.Register("[email protected]", "password", Guid.NewGuid());
using (var session = OpenSession(CreateStore(withMigrations:false)))
{
session.Save(user);
user.ChangeEmail($"[email protected]");
user.ChangeEmail($"[email protected]");
user.ChangeEmail($"[email protected]");
session.SaveChanges();
}
using (var session = OpenSession(CreateStore()))
{
var reader = session as IEventStoreReader;
var history = reader.GetHistory(user.Id);
user = session.Get<User>(user.Id);
user.ChangePassword("NewPassword");
user.ChangePassword("NewPassword1");
user.ChangePassword("NewPassword2");
user.ChangePassword("NewPassword3");
session.SaveChanges();
}
using (var session = OpenSession(CreateStore()))
{
var reader = session as IEventStoreReader;
var history1 = reader.GetHistory(user.Id);
var history2 = reader.GetHistory(user.Id);
var history3 = reader.GetHistory(user.Id);
history1.Count().Should().Be(history2.Count());
history2.Count().Should().Be(history3.Count());
}
}
示例3: VersionIncreasesWithEachAppliedEvent
public void VersionIncreasesWithEachAppliedEvent()
{
var user = new User();
Assert.That(user.Version, Is.EqualTo(0));
user.Register("email", "password", Guid.NewGuid());
Assert.That(user.Version, Is.EqualTo(1));
user.ChangeEmail("NewEmail");
Assert.That(user.Version, Is.EqualTo(2));
user.ChangePassword("NewPassword");
Assert.That(user.Version, Is.EqualTo(3));
}
示例4: GetChangesReturnsEmptyListAfterAcceptChangesCalled
public void GetChangesReturnsEmptyListAfterAcceptChangesCalled()
{
var user = new User();
var userAseventStored = user as IEventStored;
Assert.That(user.Version, Is.EqualTo(0));
user.Register("email", "password", Guid.NewGuid());
userAseventStored.AcceptChanges();
Assert.That(userAseventStored.GetChanges(), Is.Empty);
user.ChangeEmail("NewEmail");
userAseventStored.AcceptChanges();
Assert.That(userAseventStored.GetChanges(), Is.Empty);
user.ChangePassword("NewPassword");
userAseventStored.AcceptChanges();
Assert.That(userAseventStored.GetChanges(), Is.Empty);
}
示例5: User
public void Serializes_access_to_an_aggregate_so_that_concurrent_transactions_succeed_even_if_history_has_been_read_outside_of_modifying_transactions()
{
var user = new User();
user.Register("[email protected]", "password", Guid.NewGuid());
using (var session = OpenSession(CreateStore()))
{
session.Save(user);
user.ChangeEmail($"[email protected]");
session.SaveChanges();
}
Action updateEmail = () =>
{
using (var session = OpenSession(CreateStore()))
{
var prereadHistory = ((IEventStoreReader)session).GetHistory(user.Id);
using (var transaction = new TransactionScope())
{
var userToUpdate = session.Get<User>(user.Id);
userToUpdate.ChangeEmail($"newemail_{userToUpdate.Version}@somewhere.not");
Thread.Sleep(100);
session.SaveChanges();
transaction.Complete();
}//Sql duplicate key (AggregateId, Version) Exception would be thrown here if history was not serialized
}
};
var tasks = 1.Through(20).Select(_ => Task.Factory.StartNew(updateEmail)).ToArray();
Task.WaitAll(tasks);
using (var session = OpenSession(CreateStore()))
{
var userHistory = ((IEventStoreReader)session).GetHistory(user.Id).ToArray();//Reading the aggregate will throw an exception if the history is invalid.
userHistory.Length.Should().Be(22);//Make sure that all of the transactions completed
}
}
示例6: CreateStore
public void When_fetching_history_from_the_same_instance_after_updating_an_aggregate_the_fetched_history_includes_the_new_events()
{
var store = CreateStore();
var userId = Guid.NewGuid();
using (var session = OpenSession(store))
{
var user = new User();
user.Register("[email protected]", "Password1", userId);
session.Save(user);
session.SaveChanges();
}
using (var session = OpenSession(store))
{
var user = session.Get<User>(userId);
user.ChangeEmail("[email protected]");
session.SaveChanges();
var history = ((IEventStoreReader)session).GetHistory(user.Id);
Assert.That(history.Count(), Is.EqualTo(2));
}
}
示例7: DeletingAnAggregateDoesNotPreventEventsForItFromBeingRaised
public void DeletingAnAggregateDoesNotPreventEventsForItFromBeingRaised()
{
var store = CreateStore();
var user1 = new User();
user1.Register("[email protected]", "password", Guid.NewGuid());
var user2 = new User();
user2.Register("[email protected]", "password", Guid.NewGuid());
using (var session = OpenSession(store))
{
session.Save(user1);
session.Save(user2);
session.SaveChanges();
}
Bus.Reset();
using (var session = OpenSession(store))
{
user1 = session.Get<User>(user1.Id);
user1.ChangeEmail("new_email");
session.Delete(user1.Id);
session.SaveChanges();
var published = Bus.Published.ToList();
Assert.That(published.Count, Is.EqualTo(1));
Assert.That(published[0], Is.InstanceOf<UserChangedEmail>());
}
}
示例8: EventsArePublishedOnSaveChangesAndThisInteractsWithUnitOfWorkParticipations
public void EventsArePublishedOnSaveChangesAndThisInteractsWithUnitOfWorkParticipations()
{
var bus = new MockServiceBus();
var store = new MockEventStore();
var users = 1.Through(9).Select(i => { var u = new User(); u.Register(i + "@test.com", "abcd", Guid.NewGuid()); u.ChangeEmail("new" + i + "@test.com"); return u; }).ToList();
using (var session = new EventStoreSession(bus, store, new SingleThreadUseGuard()))
{
var uow = new UnitOfWork(new SingleThreadUseGuard());
uow.AddParticipant(session);
users.Take(3).ForEach(u => session.Save(u));
Assert.That(bus.Published.Count, Is.EqualTo(0));
session.SaveChanges();
Assert.That(bus.Published.Count, Is.EqualTo(6));
users.Skip(3).Take(3).ForEach(u => session.Save(u));
Assert.That(bus.Published.Count, Is.EqualTo(6));
session.SaveChanges();
Assert.That(bus.Published.Count, Is.EqualTo(12));
users.Skip(6).Take(3).ForEach(u => session.Save(u));
Assert.That(bus.Published.Count, Is.EqualTo(12));
Assert.That(store.SavedEvents.Count, Is.EqualTo(0));
uow.Commit();
Assert.That(bus.Published.Count, Is.EqualTo(18));
Assert.That(bus.Published.Select(e => e.EventId).Distinct().Count(), Is.EqualTo(18));
Assert.That(bus.Published, Is.EquivalentTo(store.SavedEvents));
}
}
示例9: DoesNotExplodeWhenSavingMoreThan10Events
public void DoesNotExplodeWhenSavingMoreThan10Events()
{
var store = CreateStore();
var user = new User();
user.Register("OriginalEmail", "password", Guid.NewGuid());
1.Through(100).ForEach(index => user.ChangeEmail("email" + index));
using (var session = OpenSession(store))
{
session.Save(user);
session.SaveChanges();
}
}