public async Task MakeDonationHandler_Handle_CharityActionDonation_AsAnonymous_Return_Correct() { DonationsContext.OpenInMemoryConnection(); try { MakeDonationResponse response; var charity = new Charity() { CharityKey = Guid.NewGuid(), Name = "TestName", CoverImage = "TestImage", ThankYou = "ThankYou" }; var charityAction = new CharityAction() { ActionEndDateTime = DateTime.UtcNow, Name = "TestName", CharityActionKey = Guid.NewGuid(), Charity = charity, CoverImage = "TestImage", ThankYou = "ThankYou" }; var makeDonationRequest = new MakeDonationRequest { CharityKey = charity.CharityKey, CharityActionKey = charityAction.CharityActionKey, Amount = 10m, IsAnonymous = false }; using (var context = DonationsContext.GetInMemoryContext()) { context.Charities.Add(charity); context.CharityActions.Add(charityAction); await context.SaveChangesAsync(); var handler = new MakeDonationRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(makeDonationRequest); } using (var context = DonationsContext.GetInMemoryContext()) { Assert.AreEqual(1, context.CharityActionDonations.Count()); Assert.IsTrue(response.IsSuccess); Assert.AreEqual(makeDonationRequest.Amount, context.CharityActionDonations.First().Amount); Assert.AreEqual(makeDonationRequest.IsAnonymous, context.CharityActionDonations.First().IsAnonymous); Assert.AreEqual(charityAction.ThankYou, response.ThankYou); Assert.AreEqual(charityAction.CoverImage, response.CoverImage); } } finally { DonationsContext.CloseInMemoryConnection(); } }
public async Task MakeDonationHandler_Handle_Return_CharityActionNotFound() { DonationsContext.OpenInMemoryConnection(); try { MakeDonationResponse response; var user = new User { UserKey = Guid.NewGuid(), ProfileImage = "PrettyImage", UserName = "******" }; var charity = new Charity() { CharityKey = Guid.NewGuid(), Name = "TestName", CoverImage = "TestImage", ThankYou = "ThankYou" }; var charityAction = new CharityAction() { ActionEndDateTime = DateTime.UtcNow, Name = "TestName", CharityActionKey = Guid.NewGuid(), Charity = charity, CoverImage = "TestImage", ThankYou = "ThankYou" }; var makeDonationRequest = new MakeDonationRequest { CharityKey = charity.CharityKey, CharityActionKey = charityAction.CharityActionKey, Amount = 10m, UserKey = user.UserKey, IsAnonymous = false }; using (var context = DonationsContext.GetInMemoryContext()) { context.Charities.Add(charity); context.Users.Add(user); await context.SaveChangesAsync(); var handler = new MakeDonationRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(makeDonationRequest); } using (var context = DonationsContext.GetInMemoryContext()) { Assert.IsFalse(context.CharityDonations.Any()); Assert.IsFalse(context.CharityActionDonations.Any()); Assert.AreEqual(ErrorType.CharityActionNotFound, response.ErrorType); Assert.IsFalse(response.IsSuccess); } } finally { DonationsContext.CloseInMemoryConnection(); } }