Exemple #1
0
        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 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();
            }
        }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
        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();
            }
        }
Exemple #5
0
        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();
            }
        }