public async Task CharityActionUpdatedEventHandler_Handle_Returns_Success() { DonationsContext.OpenInMemoryConnection(); try { var charity = new DAL.Charity { CharityKey = Guid.NewGuid(), Name = "Test", ChartityActions = new List <CharityAction>(), }; var charityAction = new CharityAction() { ActionEndDateTime = DateTime.UtcNow, Name = "TestName", CharityActionKey = Guid.NewGuid(), Charity = charity }; var updatedCharityActionEvent = new CharityActionUpdatedEvent() { CharityActionKey = charityAction.CharityActionKey, CoverImage = "pretty image", Name = "Pretty CharityAction Name", ThankYou = "ThankYouVeryMuch" }; using (var context = DonationsContext.GetInMemoryContext()) { context.CharityActions.Add(charityAction); context.SaveChanges(); } using (var context = DonationsContext.GetInMemoryContext()) { var handler = new CharityActionUpdatedEventHandler(context); await handler.ConsumeAsync(updatedCharityActionEvent); } using (var context = DonationsContext.GetInMemoryContext()) { Assert.AreEqual(1, context.CharityActions.Count()); Assert.AreEqual(updatedCharityActionEvent.ActionEndDateTime, context.CharityActions.Single().ActionEndDateTime); Assert.AreEqual(updatedCharityActionEvent.CoverImage, context.CharityActions.Single().CoverImage); Assert.AreEqual(updatedCharityActionEvent.ThankYou, context.CharityActions.Single().ThankYou); Assert.AreEqual(updatedCharityActionEvent.Name, context.CharityActions.Single().Name); } } finally { DonationsContext.CloseInMemoryConnection(); } }
public async Task CharityActionCreatedEventHandler_Handle_Returns_Success() { DonationsContext.OpenInMemoryConnection(); try { var Charity = new DAL.Charity { CharityKey = Guid.NewGuid(), Name = "Test", ChartityActions = new List <DAL.CharityAction>(), }; var Event = new CharityActionCreatedEvent { Category = Core.Enums.Category.EnvironmentAndNatureConservation, CharityActionKey = Guid.NewGuid(), CoverImage = "No image given", IBAN = "NotReallyAnIBAN", Description = "This is a very good testing description", CharityKey = Charity.CharityKey, Name = "TestNameAction", UserKeys = new List <UserKey> { new UserKey { Key = Guid.NewGuid() } }, ThankYou = "ThankYou" }; using (var context = DonationsContext.GetInMemoryContext()) { context.Charities.Add(Charity); await context.SaveChangesAsync(); var handler = new CharityActionCreatedEventHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); await handler.ConsumeAsync(Event); } using (var context = DonationsContext.GetInMemoryContext()) { Assert.AreEqual(1, context.CharityActions.Count()); Assert.AreEqual(Event.CharityActionKey, context.CharityActions.Single().CharityActionKey); Assert.AreEqual(Event.ActionEndDateTime, context.CharityActions.Single().ActionEndDateTime); Assert.AreEqual(Event.ThankYou, context.CharityActions.Single().ThankYou); Assert.AreEqual(Event.CoverImage, context.CharityActions.Single().CoverImage); Assert.AreEqual(Event.Name, context.CharityActions.Single().Name); } } finally { DonationsContext.CloseInMemoryConnection(); } }