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 CharityActionUpdatedEventHandler_Handle_Returns_Success() { SearchContext.OpenInMemoryConnection(); try { var content = new Content() { Category = Core.Enums.Category.EnvironmentAndNatureConservation, CharityKey = Guid.NewGuid(), Image = "No image given", CharityName = "TestName", CharityActionName = "TestName", Description = "This is a very good testing slogan", Type = Core.Enums.SearchContentType.CharityAction }; var updatedCharityActionEvent = new CharityActionUpdatedEvent() { CharityActionKey = content.CharityActionKey, CoverImage = "pretty image", Name = "Pretty CharityAction Name", Category = content.Category, Description = content.Description, }; using (var context = SearchContext.GetInMemoryContext()) { context.Content.Add(content); context.SaveChanges(); } using (var context = SearchContext.GetInMemoryContext()) { var handler = new CharityActionUpdatedEventHandler(context); await handler.ConsumeAsync(updatedCharityActionEvent); } using (var context = SearchContext.GetInMemoryContext()) { Assert.AreEqual(1, context.Content.Count()); Assert.AreEqual(content.CharityKey, context.Content.Single().CharityKey); Assert.AreEqual(updatedCharityActionEvent.CoverImage, context.Content.Single().Image); Assert.AreEqual(content.Category, context.Content.Single().Category); Assert.AreEqual(content.Description, context.Content.Single().Description); Assert.AreEqual(Core.Enums.SearchContentType.CharityAction, context.Content.Single().Type); Assert.AreEqual(updatedCharityActionEvent.Name, context.Content.Single().CharityActionName); } } finally { SearchContext.CloseInMemoryConnection(); } }