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 GetCharitiesRequestHandler_Handle_Returns_Charities() { DonationsContext.OpenInMemoryConnection(); try { using (var context = DonationsContext.GetInMemoryContext()) { for (var i = 0; i < 25; i++) { context.Charities.Add(new Charity { CharityKey = Guid.NewGuid(), Name = "charity" }); } context.SaveChanges(); } GetCharitiesResponse response; using (var context = DonationsContext.GetInMemoryContext()) { var handler = new GetCharitiesRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(new GetCharitiesRequest()); } Assert.AreEqual(25, response.Charities.Count); } finally { DonationsContext.CloseInMemoryConnection(); } }
public async Task GetCharityActionsRequestHandler_Handle_Returns_No_CharityActions() { DonationsContext.OpenInMemoryConnection(); try { var charity1 = new Charity { CharityKey = Guid.NewGuid(), ChartityActions = new List <CharityAction>() }; var charity2 = new Charity { CharityKey = Guid.NewGuid(), ChartityActions = new List <CharityAction>() }; using (var context = DonationsContext.GetInMemoryContext()) { for (var i = 0; i < 25; i++) { charity1.ChartityActions.Add(new CharityAction { CharityActionKey = Guid.NewGuid(), Name = "CharityAction" }); } for (var i = 0; i < 20; i++) { charity2.ChartityActions.Add(new CharityAction { CharityActionKey = Guid.NewGuid(), Name = "CharityAction" }); } context.AddRange(charity1, charity2); context.SaveChanges(); } GetCharityActionsResponse response; using (var context = DonationsContext.GetInMemoryContext()) { var handler = new GetCharityActionsRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(new GetCharityActionsRequest { CharityKey = Guid.NewGuid() }); } Assert.AreEqual(0, response.CharityActions.Count); } finally { DonationsContext.CloseInMemoryConnection(); } }
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(); } }
public async Task UserUpdatedEventHandler_Handle_Returns_Success() { DonationsContext.OpenInMemoryConnection(); try { var user = new User { UserKey = Guid.NewGuid(), ProfileImage = "PrettyImage", UserName = "******" }; var Event = new UserUpdatedEvent() { UserKey = user.UserKey, AddressLine1 = "AddressLine1", AddressLine2 = "AddressLine2", ProfileImage = "UglyImage", BirthDate = DateTime.UtcNow, City = "TestCity", Country = "TestCountry", EmailAddress = "*****@*****.**", FirstName = "FirstTest", LastName = "LastTest", PhoneNumber = "0600000000" }; using (var context = DonationsContext.GetInMemoryContext()) { context.Users.Add(user); await context.SaveChangesAsync(); var handler = new UserUpdatedEventHandler(context); await handler.ConsumeAsync(Event); } using (var context = DonationsContext.GetInMemoryContext()) { Assert.AreEqual(1, context.Users.Count()); Assert.AreEqual(Event.FirstName + " " + Event.LastName, context.Users.Single().UserName); Assert.AreEqual(Event.ProfileImage, context.Users.Single().ProfileImage); Assert.AreEqual(Event.UserKey, context.Users.Single().UserKey); } } finally { DonationsContext.CloseInMemoryConnection(); } }
public async Task CharityUpdatedEventHandler_Handle_Returns_Success() { DonationsContext.OpenInMemoryConnection(); try { var charity = new Charity() { CharityKey = Guid.NewGuid(), Name = "TestName", }; var updatedCharityEvent = new CharityUpdatedEvent() { CharityKey = charity.CharityKey, Name = "Pretty Charity Name", CoverImage = "new CoverImage", ThankYou = "ThankYou" }; using (var context = DonationsContext.GetInMemoryContext()) { context.Charities.Add(charity); context.SaveChanges(); } using (var context = DonationsContext.GetInMemoryContext()) { var handler = new CharityUpdatedEventHandler(context); await handler.ConsumeAsync(updatedCharityEvent); } using (var context = DonationsContext.GetInMemoryContext()) { Assert.AreEqual(1, context.Charities.Count()); Assert.AreEqual(updatedCharityEvent.Name, context.Charities.Single().Name); Assert.AreEqual(updatedCharityEvent.ThankYou, context.Charities.Single().ThankYou); Assert.AreEqual(updatedCharityEvent.CoverImage, context.Charities.Single().CoverImage); } } finally { DonationsContext.CloseInMemoryConnection(); } }
public async Task CharityCreatedEventHandler_Handle_Returns_Success() { DonationsContext.OpenInMemoryConnection(); try { var Event = new CharityCreatedEvent() { Category = Core.Enums.Category.EnvironmentAndNatureConservation, CharityKey = Guid.NewGuid(), CoverImage = "No image given", Email = "*****@*****.**", IBAN = "NotReallyAnIBAN", KVKNumber = "10", Name = "TestName", Url = "test", OwnerUserName = "******", Slogan = "This is a very good testing slogan", ThankYou = "ThankYou" }; using (var context = DonationsContext.GetInMemoryContext()) { var handler = new CharityCreatedEventHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); await handler.ConsumeAsync(Event); } using (var context = DonationsContext.GetInMemoryContext()) { Assert.AreEqual(1, context.Charities.Count()); Assert.AreEqual(Event.Name, context.Charities.Single().Name); Assert.AreEqual(Event.ThankYou, context.Charities.Single().ThankYou); Assert.AreEqual(Event.CoverImage, context.Charities.Single().CoverImage); } } finally { DonationsContext.CloseInMemoryConnection(); } }
public async Task GetCharityTotalRequestHandler_Handle_With_CharityActions_Return_NoDonationsFound() { DonationsContext.OpenInMemoryConnection(); try { GetCharityTotalResponse response; var user = new User { UserKey = Guid.NewGuid(), ProfileImage = "PrettyImage", UserName = "******" }; var charity = new Charity() { CharityKey = Guid.NewGuid(), Name = "TestName", }; var charityAction = new CharityAction() { ActionEndDateTime = DateTime.UtcNow, Name = "TestName", CharityActionKey = Guid.NewGuid(), Charity = charity }; var charityDonation = new CharityDonation { Amount = 1m, DateTimeStamp = DateTime.UtcNow.AddHours(-1), DonationType = DonationType.Once, IsAnonymous = false, Charity = charity, User = user }; var charityDonation1 = new CharityDonation { Amount = 5m, DateTimeStamp = DateTime.UtcNow.AddHours(-4), DonationType = DonationType.Once, IsAnonymous = false, Charity = charity, User = user }; var charityActionDonation = new CharityActionDonation { Amount = 10m, DateTimeStamp = DateTime.UtcNow.AddHours(-3), DonationType = DonationType.Once, IsAnonymous = false, CharityAction = charityAction }; var getCharityTotalRequest = new GetCharityTotalRequest { CharityKey = charity.CharityKey, From = DateTime.UtcNow.AddDays(-1), To = DateTime.UtcNow, IncludeCharityActions = true, NumberOfDonations = 3, SortOrder = SortOrder.Desc }; using (var context = DonationsContext.GetInMemoryContext()) { var handler = new GetCharityTotalRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(getCharityTotalRequest); } Assert.AreEqual(ErrorType.NoDonationsFound, response.ErrorType); Assert.IsFalse(response.IsSuccess); } finally { DonationsContext.CloseInMemoryConnection(); } }
public async Task GetCharityTotalRequestHandler_Handle_Without_To_And_From_Return_Correct() { DonationsContext.OpenInMemoryConnection(); try { GetCharityTotalResponse response; var user = new User { UserKey = Guid.NewGuid(), ProfileImage = "PrettyImage", UserName = "******" }; var charity = new Charity() { CharityKey = Guid.NewGuid(), Name = "TestName", }; var charityAction = new CharityAction() { ActionEndDateTime = DateTime.UtcNow, Name = "TestName", CharityActionKey = Guid.NewGuid(), Charity = charity }; var charityDonation = new CharityDonation { Amount = 1m, DateTimeStamp = DateTime.UtcNow.AddHours(-1), DonationType = DonationType.Once, IsAnonymous = false, Charity = charity, User = user }; var charityDonation1 = new CharityDonation { Amount = 5m, DateTimeStamp = DateTime.UtcNow.AddHours(-4), DonationType = DonationType.Once, IsAnonymous = false, Charity = charity, User = user }; var charityActionDonation = new CharityActionDonation { Amount = 10m, DateTimeStamp = DateTime.UtcNow.AddHours(-3), DonationType = DonationType.Once, IsAnonymous = false, CharityAction = charityAction }; var getCharityTotalRequest = new GetCharityTotalRequest { CharityKey = charity.CharityKey, IncludeCharityActions = false, NumberOfDonations = 3, SortOrder = SortOrder.Desc }; using (var context = DonationsContext.GetInMemoryContext()) { context.CharityDonations.Add(charityDonation); context.CharityDonations.Add(charityDonation1); context.CharityActionDonations.Add(charityActionDonation); context.SaveChanges(); var handler = new GetCharityTotalRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(getCharityTotalRequest); } Assert.AreEqual(2, response.NumberOfDonators); Assert.IsTrue(response.IsSuccess); Assert.AreEqual(charityDonation.Amount, response.Donations.First().Amount); Assert.AreEqual(charityDonation.DateTimeStamp, response.Donations.First().DateTimeStamp); Assert.AreEqual(charityDonation.User.ProfileImage, response.Donations.First().ProfileImage); Assert.AreEqual(charityDonation.User.UserName, response.Donations.First().UserName); Assert.AreEqual(charityDonation1.Amount, response.Donations.Last().Amount); Assert.AreEqual(charityDonation1.DateTimeStamp, response.Donations.Last().DateTimeStamp); Assert.AreEqual(charityDonation1.User.ProfileImage, response.Donations.Last().ProfileImage); Assert.AreEqual(charityDonation1.User.UserName, response.Donations.Last().UserName); Assert.AreEqual(charityDonation.Amount + charityDonation1.Amount, response.TotalDonatedAmount); } 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(); } }