public bool DoPayment(Payment payment, CharityContext context) { // get object of user that is making the payment var userThatPays = context.user.Where(x => x.Id == payment.userSenderId).Single(); // get object of organization that receives the payment var orgThatReceives = context.organization.Where(x => x.Id == payment.organizationReceiverId).Single(); // get their credit card objects try { var creditCardThatPays = context.card.Where(x => x.Id == userThatPays.creditCardId).Single(); var creditCardThatReceives = context.card.Where(x => x.Id == orgThatReceives.creditCardNumber).Single(); if (creditCardThatPays.amount >= payment.amount && payment.amount > 0) // payment is possible { creditCardThatPays.amount -= payment.amount; creditCardThatReceives.amount += payment.amount; context.Add(payment); context.SaveChanges(); return(true); } else { return(false); } } catch (Exception) { return(false); } }
public async Task GetCharityByKeyRequest_Handle_Returns_Charity() { CharityContext.OpenInMemoryConnection(); try { //Arrange var key = Guid.NewGuid(); using (var context = CharityContext.GetInMemoryContext()) { var charity = new Charity { CharityKey = key, Name = "testNameCharity", OwnerUserName = "******", Email = "*****@*****.**", Category = Core.Enums.Category.None, KVKNumber = "", IBAN = "0-IBAN", CoverImage = "", Slogan = "Test" }; context.Add(charity); context.SaveChanges(); } var request = new GetCharityByKeyRequest() { CharityKey = key }; GetCharityByKeyResponse response; //Act using (var context = CharityContext.GetInMemoryContext()) { var handler = new GetCharityByKeyRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(request); } //Assert using (var context = CharityContext.GetInMemoryContext()) { Assert.AreEqual(response.Charity.CharityKey, request.CharityKey); Assert.AreEqual(response.Charity.Name, context.Charities.Single().Name); Assert.AreEqual(response.Charity.OwnerUserName, context.Charities.Single().OwnerUserName); Assert.AreEqual(response.Charity.Email, context.Charities.Single().Email); Assert.AreEqual(response.Charity.Category, context.Charities.Single().Category); Assert.AreEqual(response.Charity.KVKNumber, context.Charities.Single().KVKNumber); Assert.AreEqual(response.Charity.IBAN, context.Charities.Single().IBAN); Assert.AreEqual(response.Charity.CoverImage, context.Charities.Single().CoverImage); Assert.AreEqual(response.Charity.Slogan, context.Charities.Single().Slogan); Assert.IsTrue(response.IsSuccess); } } finally { CharityContext.CloseInMemoryConnection(); } }
public ActionResult Show() { var db = new CharityContext(); //LINQ - Language INtegrated Query var members = from m in db.Members orderby m.Name select m; return(View("Show", members.ToList())); }
public async Task ApproveCharityRequest_Handle_Returns_AlreadyActive() { CharityContext.OpenInMemoryConnection(); try { var busMock = new Mock <IBus>(); busMock.Setup(m => m.PublishAsync(It.IsAny <CharityCreatedEvent>())).Returns(Task.FromResult(true)); ApproveCharityResponse response; var request = new ApproveCharityRequest { CharityKey = Guid.NewGuid() }; var charity = new Charity { CharityKey = request.CharityKey, IsApproved = true, Name = "0", OwnerUserName = "******", Email = "testEmail", Category = Category.AnimalProtection, KVKNumber = "1", IBAN = "1111-1111", CoverImage = "x", Slogan = "Test2" }; using (var context = CharityContext.GetInMemoryContext()) { context.Charities.Add(charity); context.SaveChanges(); } using (var context = CharityContext.GetInMemoryContext()) { var handler = new ApproveCharityRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile()), busMock.Object); response = await handler.Handle(request); } using (var context = CharityContext.GetInMemoryContext()) { Assert.IsTrue(context.Charities.Single().IsApproved); Assert.IsFalse(response.IsSuccess); Assert.AreEqual(ErrorType.AlreadyActive, response.ErrorType); } busMock.Verify(m => m.PublishAsync(It.Is <CharityCreatedEvent>(e => e.CharityKey == request.CharityKey)), Times.Never); } finally { CharityContext.CloseInMemoryConnection(); } }
public async Task GetCharityByUrlRequest_Handle_Returns_Null() { CharityContext.OpenInMemoryConnection(); try { //Arrange using (var context = CharityContext.GetInMemoryContext()) { var charity = new Charity { CharityKey = Guid.NewGuid(), Name = "testNameCharity", OwnerUserName = "******", Email = "*****@*****.**", Category = Core.Enums.Category.None, KVKNumber = "", IBAN = "0-IBAN", CoverImage = "", Slogan = "Test", Url = "test", IsApproved = true }; context.Add(charity); context.SaveChanges(); } var request = new GetCharityByUrlRequest { Url = "WeirdUrl" }; GetCharityByUrlResponse response; //Act using (var context = CharityContext.GetInMemoryContext()) { var handler = new GetCharityByUrlRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(request); } //Assert Assert.IsFalse(response.IsSuccess); } finally { CharityContext.CloseInMemoryConnection(); } }
public async Task CreateCharityRequest_Handle_Returns_Success() { CharityContext.OpenInMemoryConnection(); try { CreateCharityResponse response; var request = new CreateCharityRequest { CharityKey = Guid.NewGuid(), Name = "testName", OwnerUserName = "******", Email = "*****@*****.**", Category = Category.None, KVKNumber = "", IBAN = "0-IBAN", CoverImage = "", Slogan = "Test" }; using (var context = CharityContext.GetInMemoryContext()) { var handler = new CreateCharityRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(request); } using (var context = CharityContext.GetInMemoryContext()) { Assert.AreEqual(request.CharityKey, context.Charities.Single().CharityKey); Assert.AreEqual(request.Name, context.Charities.Single().Name); Assert.AreEqual(request.OwnerUserName, context.Charities.Single().OwnerUserName); Assert.AreEqual(request.Email, context.Charities.Single().Email); Assert.AreEqual(request.Category, context.Charities.Single().Category); Assert.AreEqual(request.KVKNumber, context.Charities.Single().KVKNumber); Assert.AreEqual(request.IBAN, context.Charities.Single().IBAN); Assert.AreEqual(request.CoverImage, context.Charities.Single().CoverImage); Assert.AreEqual(request.Slogan, context.Charities.Single().Slogan); Assert.IsFalse(context.Charities.Single().IsApproved); Assert.IsTrue(response.IsSuccess); } } finally { CharityContext.CloseInMemoryConnection(); } }
public async Task PopulateAll(CharityContext db) { var query = db.Charities .FilterDeletedItems() .OrderBy(x => x.CharityName); var items = await query .Skip(Offset) .Take(Count) .ToListAsync(); Total = await query.CountAsync(); Items = items .Select(CharityModel.FromEntity) .ToList(); }
public ActionResult Test() { var db = new CharityContext(); var t1 = new TeamMember { Registered = DateTime.Today, Name = "Heather C", CharityPage = "https://example.com/hc", Token = "heatherc" }; var t2 = new TeamMember { Registered = DateTime.Today, Name = "Heather A", CharityPage = "https://example.com/ha", Token = "heathera" }; var t3 = new TeamMember { Registered = DateTime.Today, Name = "Heather B", CharityPage = "https://example.com/hb", Token = "heatherb" }; var t4 = new TeamMember { Registered = DateTime.Today, Name = "Donald Trump", CharityPage = "https://example.com/trump", Token = "TheDonald" }; var t5 = new TeamMember { Registered = DateTime.Today, Name = "Tom Hanks", CharityPage = "https://example.com/tom", Token = "hanks" }; var t6 = new TeamMember { Registered = DateTime.Today, Name = "Bill Gates", CharityPage = "https://example.com/gate", Token = "billyg" }; var t7 = new TeamMember { Registered = DateTime.Today, Name = "Colonel Sanders", CharityPage = "https://example.com/sanders", Token = "TheColonel" }; var t8 = new TeamMember { Registered = DateTime.Today, Name = "Oprah", CharityPage = "https://example.com/harpo", Token = "oprah" }; db.Members.Add(t1); db.Members.Add(t2); db.Members.Add(t3); db.Members.Add(t4); db.Members.Add(t5); db.Members.Add(t6); db.Members.Add(t7); db.Members.Add(t8); db.SaveChanges(); return(View("Test")); }
public async Task UserUpdatedEventHandler_Consume_Updates_Name() { CharityContext.OpenInMemoryConnection(); try { var userUpdatedEvent = new UserUpdatedEvent { UserKey = Guid.NewGuid(), FirstName = "Ellen", LastName = "Doe", EmailAddress = "*****@*****.**" }; var charity = new Charity { OwnerUserKey = userUpdatedEvent.UserKey, OwnerUserName = "******" }; using (var context = CharityContext.GetInMemoryContext()) { context.Charities.Add(charity); context.SaveChanges(); } using (var context = CharityContext.GetInMemoryContext()) { var handler = new UserUpdatedEventHandler(context); await handler.ConsumeAsync(userUpdatedEvent); } using (var context = CharityContext.GetInMemoryContext()) { Assert.AreEqual("Ellen Doe", context.Charities.Single().OwnerUserName); } } finally { CharityContext.CloseInMemoryConnection(); } }
public async Task CreateCharityRequest_Handle_Returns_InvalidKey() { CharityContext.OpenInMemoryConnection(); try { CreateCharityResponse response; var request = new CreateCharityRequest { CharityKey = Guid.Empty, Name = "testName", OwnerUserName = "******", Email = "*****@*****.**", Category = Category.None, KVKNumber = "", IBAN = "0-IBAN", CoverImage = "", Slogan = "Test" }; using (var context = CharityContext.GetInMemoryContext()) { var handler = new CreateCharityRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(request); } using (var context = CharityContext.GetInMemoryContext()) { Assert.IsFalse(context.Charities.Any()); Assert.AreEqual(ErrorType.InvalidKey, response.ErrorType); Assert.IsFalse(response.IsSuccess); } } finally { CharityContext.CloseInMemoryConnection(); } }
public async Task GetCharitiesRequestHandlerTests_Handle_Returns_Charities() { CharityContext.OpenInMemoryConnection(); try { using (var context = CharityContext.GetInMemoryContext()) { for (var i = 0; i < 25; i++) { context.Charities.Add(new Charity { CharityKey = Guid.NewGuid() }); } context.SaveChanges(); } GetCharitiesResponse response; using (var context = CharityContext.GetInMemoryContext()) { var handler = new GetCharitiesRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(new GetCharitiesRequest { PageNumber = 2, PageSize = 20 }); } Assert.AreEqual(25, response.TotalNumberOfResults); Assert.AreEqual(5, response.Results.Count); } finally { CharityContext.CloseInMemoryConnection(); } }
public async Task Search(CharityContext db, string search) { if (string.IsNullOrEmpty(search)) { await PopulateAll(db); return; } var query = db.Charities .FilterDeletedItems() .Where(x => x.CharityName.StartsWith(search)); var items = await query .Skip(Offset) .Take(Count) .ToListAsync(); Total = await query.CountAsync(); Items = items .Select(CharityModel.FromEntity) .ToList(); }
public async Task GetCharityActionsRequestHandlerTests_Handle_Returns_Filtered_Charities() { CharityContext.OpenInMemoryConnection(); try { var charityKey = Guid.NewGuid(); using (var context = CharityContext.GetInMemoryContext()) { for (var i = 0; i < 25; i++) { context.Charities.Add(new Charity { CharityKey = Guid.NewGuid(), Name = "this is a charity for john", Description = "doe", Category = Category.EducationAndResearch | Category.Culture }); } for (var i = 0; i < 15; i++) { if (i % 2 == 0) { if (i % 4 == 0) { context.Charities.Add(new Charity { CharityKey = charityKey, Name = "this is a charity for john", Description = "doe", Category = Category.EducationAndResearch | Category.Culture }); } else { context.Charities.Add(new Charity { CharityKey = charityKey, Name = "this is a charity for john", Description = "doe", Category = Category.EducationAndResearch | Category.Health }); } } else { context.Charities.Add(new Charity { CharityKey = charityKey }); } } context.SaveChanges(); } GetCharitiesResponse response; using (var context = CharityContext.GetInMemoryContext()) { var handler = new GetCharitiesRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(new GetCharitiesRequest { Category = Category.EducationAndResearch | Category.Culture, Keywords = new List <string> { "john", "doe" }, PageNumber = 3, PageSize = 10 }); } Assert.AreEqual(29, response.TotalNumberOfResults); Assert.AreEqual(9, response.Results.Count); Assert.IsTrue(response.Results.All(r => r.Category == (Category.EducationAndResearch | Category.Culture))); } finally { CharityContext.CloseInMemoryConnection(); } }
public HomeController(CharityContext context) { _context = context; }
public AccountsController(CharityContext context) { _context = context; }
public ItemsController(CharityContext context) { _context = context; }
public ApproveCharityRequestHandler(CharityContext context, IMapper mapper, IBus bus) { _context = context; _mapper = mapper; _bus = bus; }
public CharityActionsController(CharityContext context) { _context = context; }
public AdminService(CharityContext context) { _context = context; }
public InstitutionSerwice(CharityContext context) { _context = context; }
public DonationService(CharityContext context) { _context = context; }
public OrganizationsController(CharityContext context) { _context = context; }
public CreateCharityRequestHandler(CharityContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public async Task UpdateCharityRequest_Handle_Returns_Success() { CharityContext.OpenInMemoryConnection(); try { var busMock = new Mock <IBus>(); busMock.Setup(m => m.PublishAsync(It.IsAny <CharityUpdatedEvent>())).Returns(Task.FromResult(true)); UpdateCharityResponse response; var newKey = Guid.NewGuid(); var request = new UpdateCharityRequest() { CharityKey = newKey, Name = "0", OwnerUserName = "******", Email = "0", Category = Core.Enums.Category.None, KVKNumber = "", IBAN = "0-IBAN", CoverImage = "", Slogan = "0" }; using (var context = CharityContext.GetInMemoryContext()) { context.Charities.Add(new Charity { CharityKey = newKey, Name = "0", OwnerUserName = "******", Email = "testEmail", Category = Category.AnimalProtection, KVKNumber = "1", IBAN = "1111-1111", CoverImage = "x", Slogan = "Test2" }); context.SaveChanges(); } using (var context = CharityContext.GetInMemoryContext()) { var handler = new UpdateCharityRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile()), busMock.Object); response = await handler.Handle(request); } using (var context = CharityContext.GetInMemoryContext()) { Assert.AreEqual(request.CharityKey, context.Charities.Single().CharityKey); Assert.AreEqual(request.Name, context.Charities.Single().Name); Assert.AreEqual(request.OwnerUserName, context.Charities.Single().OwnerUserName); Assert.AreEqual(request.Email, context.Charities.Single().Email); Assert.AreEqual(request.Category, context.Charities.Single().Category); Assert.AreEqual(request.KVKNumber, context.Charities.Single().KVKNumber); Assert.AreEqual(request.IBAN, context.Charities.Single().IBAN); Assert.AreEqual(request.CoverImage, context.Charities.Single().CoverImage); Assert.AreEqual(request.Slogan, context.Charities.Single().Slogan); Assert.IsTrue(response.IsSuccess); } busMock.Verify(m => m.PublishAsync(It.Is <CharityUpdatedEvent>(e => e.CharityKey == request.CharityKey && e.Name == request.Name)), Times.Once); } finally { CharityContext.CloseInMemoryConnection(); } }
public InstitutionService(CharityContext context) { this._context = context; }
public UsersController(CharityContext context) { _context = context; }
public CategoryService(CharityContext context) { this._context = context; }
public GetCharitiesRequestHandler(CharityContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public CharityController(CharityContext db, IIntegrationEventQueue queue, IRequestContext requestContext) { _db = db; _queue = queue; _requestContext = requestContext; }
public PaymentsController(CharityContext context) { _context = context; }