Beispiel #1
0
        public void TestInvoiceListing()
        {
            var infoList = new List <InvoiceInfo>
            {
                GetValidInvoiceInfo(),
                GetValidInvoiceInfo()
            };

            ServicesMockHelper.MockInvoiceListResponse(infoList, nextPage: 2, totalPages: 2, totalCount: 4);
            var pagination = Invoice.List();

            Assert.Equal(2, pagination.Items.Count);

            Assert.Equal(infoList[0].Amount, pagination.Items[0].Amount);
            Assert.Equal(infoList[0].Currency, pagination.Items[0].Currency);
            Assert.Equal(infoList[0].ExpiredAt, pagination.Items[0].ExpiredAt);

            Assert.Equal(1, pagination.CurrentPage);
            Assert.Equal(2, pagination.NextPage);
            Assert.Equal(2, pagination.TotalPages);
            Assert.Equal(4, pagination.TotalCount);

            ServicesMockHelper.MockInvoiceListResponse(infoList, 2, prevPage: 1, totalPages: 2, totalCount: 4);
            pagination = pagination.GetNextPage();

            Assert.Equal(2, pagination.CurrentPage);
            Assert.Equal(1, pagination.PreviousPage);
        }
Beispiel #2
0
        public void TestFetchInvoice()
        {
            var info    = GetValidInvoiceInfo();
            var payInfo = PaymentTest.GetValidPaymentInfoVisa();

            ServicesMockHelper.MockInvoiceResponse(info, new List <PaymentInfo>
            {
                payInfo,
                payInfo
            });

            var invoice = Invoice.Fetch("some-random-id");

            Assert.Equal(info.Amount, invoice.Amount);
            Assert.Equal(info.Currency, invoice.Currency);
            Assert.Equal(info.Description, invoice.Description);
            Assert.Equal(info.ExpiredAt, invoice.ExpiredAt);
            Assert.Equal(info.CallbackUrl, invoice.CallbackUrl);

            Assert.Equal(2, invoice.Payments.Count);

            Assert.Equal(payInfo.Amount, invoice.Payments[0].Amount);
            Assert.Equal(payInfo.Currency, invoice.Payments[0].Currency);
            Assert.Equal(payInfo.Description, invoice.Payments[0].Description);
        }
Beispiel #3
0
            private IMembershipService GetMembershipService()
            {
                var roles = GetDummyRoles(new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                });
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetRole(
                                     It.Is <string>(name =>
                                                    roles.Any(
                                                        role => role.Name.Equals(
                                                            name, StringComparison.OrdinalIgnoreCase
                                                            )
                                                        )
                                                    )
                                     )
                                 ).Returns <string>(name =>
                                                    roles.FirstOrDefault(
                                                        role => role.Name.Equals(
                                                            name, StringComparison.OrdinalIgnoreCase
                                                            )
                                                        )
                                                    );

                return(mockMemSrv.Object);
            }
Beispiel #4
0
        public void TestPaymentListing()
        {
            var infoList = new List <PaymentInfo>
            {
                GetValidPaymentInfoVisa(),
                GetValidPaymentInfoSadadAccount()
            };

            ServicesMockHelper.MockPaymentListResponse(infoList, nextPage: 2, totalPages: 2, totalCount: 4);
            var pagination = Payment.List();

            Assert.IsType <CreditCard>(pagination.Items[0].Source);
            Assert.IsType <Sadad>(pagination.Items[1].Source);

            Assert.Equal(1, pagination.CurrentPage);
            Assert.Equal(2, pagination.NextPage);
            Assert.Equal(2, pagination.TotalPages);
            Assert.Equal(4, pagination.TotalCount);

            ServicesMockHelper.MockPaymentListResponse(infoList, 2, prevPage: 1, totalPages: 2, totalCount: 4);
            pagination = pagination.GetNextPage();

            Assert.Equal(2, pagination.CurrentPage);
            Assert.Equal(1, pagination.PreviousPage);
        }
Beispiel #5
0
        public void TestUpdateInvoice()
        {
            var info    = GetValidInvoiceInfo();
            var payInfo = PaymentTest.GetValidPaymentInfoVisa();

            ServicesMockHelper.MockInvoiceResponse(info, new List <PaymentInfo>
            {
                payInfo,
                payInfo
            });

            var invoice = Invoice.Fetch("some-random-id");

            info.Amount      = 1;
            info.Currency    = "USD";
            info.Description = "NEW";
            ServicesMockHelper.MockInvoiceResponse(info, new List <PaymentInfo>
            {
                payInfo,
                payInfo
            });

            invoice.Update();

            Assert.Equal(info.Amount, invoice.Amount);
            Assert.Equal(info.Currency, invoice.Currency);
            Assert.Equal(info.Description, invoice.Description);
        }
            private static ContainerBuilder GetInitialContainerbuilder()
            {
                var builder    = IntegrationTestHelper.GetEmptyContainerBuilder();
                var mockMemSrv = ServicesMockHelper.GetInitialMembershipServiceMock();

                builder.Register(c => mockMemSrv.Object).As <IMembershipService>().InstancePerRequest();
                return(builder);
            }
Beispiel #7
0
            private static IMembershipService GetMembershipService()
            {
                CryptoService cryptoService = new CryptoService();
                var           salt          = cryptoService.GenerateSalt();

                var users = GetDummyUsers(new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                });
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.CreateUser(
                                     It.IsAny <string>(), It.IsAny <string>(),
                                     It.IsAny <string>(), It.IsAny <string[]>()
                                     )
                                 ).Returns <string, string, string, string[]>(
                    (username, email, password, roles) =>

                    new OperationResult <UserWithRoles>(true)
                {
                    Entity = new UserWithRoles {
                        User = new User {
                            Key            = Guid.NewGuid(),
                            Name           = username,
                            Email          = email,
                            Salt           = salt,
                            HashedPassword = cryptoService.EncryptPassword(password, salt),
                            CreatedOn      = DateTime.Now,
                            IsLocked       = false
                        },
                        Roles = roles.Select(
                            roleName => new Role {
                            Key  = Guid.NewGuid(),
                            Name = roleName
                        }
                            )
                    }
                }
                    );

                mockMemSrv.Setup(ms => ms.CreateUser(
                                     It.Is <string>(
                                         userName =>
                                         users.Any(x =>
                                                   x.User.Name.Equals(
                                                       userName, StringComparison.OrdinalIgnoreCase
                                                       )
                                                   )
                                         ),
                                     It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string[]>()
                                     )
                                 ).Returns(new OperationResult <UserWithRoles>(false));

                return(mockMemSrv.Object);
            }
Beispiel #8
0
            private IMembershipService GetMembershipService()
            {
                var roles = GetDummyRoles(new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                });
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetRoles()).Returns(roles);

                return(mockMemSrv.Object);
            }
        Returns_200_And_Expected_User_For_The_Authed_User()
        {
            // Arrange
            var mockMemSrv = ServicesMockHelper
                             .GetInitialMembershipServiceMock();

            mockMemSrv.Setup(ms =>
                             ms.GetUser(Constants.ValidAffiliateUserName)
                             ).Returns <string>(
                userName => new UserWithRoles {
                User = new User {
                    Key           = Guid.NewGuid(),
                    Name          = userName,
                    Email         = "*****@*****.**",
                    IsLocked      = false,
                    CreatedOn     = DateTime.Now.AddDays(-10),
                    LastUpdatedOn = DateTime.Now.AddDays(-5)
                },
                Roles = new List <Role> {
                    new Role {
                        Key = Guid.NewGuid(), Name = "Affiliate"
                    }
                }
            }
                );

            var config = IntegrationTestHelper
                         .GetInitialIntegrationTestConfig(
                GetInitialServices(mockMemSrv.Object));

            var request = HttpRequestMessageHelper
                          .ConstructRequest(
                httpMethod: HttpMethod.Get,
                uri: string.Format(
                    "https://localhost/{0}", "api/auth"),
                mediaType: "application/json",
                username: Constants.ValidAffiliateUserName,
                password: Constants.ValidAffiliatePassword);

            // Act
            var user = await IntegrationTestHelper.GetResponseMessageBodyAsync <UserDto>(config, request, HttpStatusCode.OK);

            // Assert
            Assert.Equal(Constants.ValidAffiliateUserName, user.Name);
            Assert.True(user.Roles.Any(
                            role => role.Name.Equals(
                                "Affiliate",
                                StringComparison.OrdinalIgnoreCase
                                )
                            )
                        );
        }
Beispiel #10
0
        public void TestDeserializingPayment()
        {
            var paymentInfo = GetValidPaymentInfoVisa();

            ServicesMockHelper.MockPaymentResponse(paymentInfo);

            var payment = Payment.Fetch("some-random-id");

            Assert.Equal(paymentInfo.Amount, payment.Amount);
            Assert.Equal(paymentInfo.Currency, payment.Currency);
            Assert.Equal(paymentInfo.Description, payment.Description);
            Assert.Equal(paymentInfo.CallbackUrl, payment.CallbackUrl);

            Assert.IsType <CreditCard>(payment.Source);
            Assert.Equal(((CreditCardSource)paymentInfo.Source).Name, ((CreditCard)payment.Source).Name);
        }
Beispiel #11
0
            private static IMembershipService GetMembershipService()
            {
                var users = GetDummyUsers(new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                });
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetUsers(
                                     It.IsAny <int>(), It.IsAny <int>()
                                     )
                                 ).Returns <int, int>((page, take) =>
                                                      users.AsQueryable()
                                                      .ToPaginatedList(page, take)
                                                      );

                return(mockMemSrv.Object);
            }
Beispiel #12
0
            private IMembershipService GetMembershipService(Guid[] keys)
            {
                var roles      = GetDummyRoles(keys);
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetRole(
                                     It.Is <Guid>(key =>
                                                  keys.Contains(key)
                                                  )
                                     )
                                 ).Returns <Guid>(key =>
                                                  roles.FirstOrDefault(
                                                      role => role.Key == key
                                                      )
                                                  );

                return(mockMemSrv.Object);
            }
Beispiel #13
0
            private static IMembershipService GetMembershipService(Guid[] keys)
            {
                var users      = GetDummyUsers(keys);
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetUser(
                                     It.Is <Guid>(
                                         key => keys.Contains(key)
                                         )
                                     )
                                 ).Returns <Guid>(key =>
                                                  users.FirstOrDefault(x =>
                                                                       x.User.Key == key
                                                                       )
                                                  );

                return(mockMemSrv.Object);
            }
Beispiel #14
0
        public void TestCancelInvoice()
        {
            var info    = GetValidInvoiceInfo();
            var payInfo = PaymentTest.GetValidPaymentInfoVisa();

            ServicesMockHelper.MockInvoiceResponse(info, new List <PaymentInfo>
            {
                payInfo,
                payInfo
            });

            var invoice = Invoice.Fetch("some-random-id");

            info.Amount = 1;
            ServicesMockHelper.MockInvoiceResponse(info, new List <PaymentInfo>
            {
                payInfo,
                payInfo
            });

            invoice.Cancel();
            Assert.Equal(info.Amount, invoice.Amount);
        }
Beispiel #15
0
        public async void RefundHigherAmountMustThrowException()
        {
            var paymentInfo = GetValidPaymentInfoVisa();

            ServicesMockHelper.MockPaymentResponse(paymentInfo);

            var payment = Payment.Fetch("some-id");
            var id      = payment.Id;
            var amount  = payment.Amount;

            ServicesMockHelper.MockPaymentResponse
            (
                paymentInfo,
                id: id,
                status: "refunded",
                refunded: amount
            );

            await Assert.ThrowsAsync <ValidationException>
            (
                async() => await Task.Run(() => payment.Refund(amount + 1))
            );
        }
Beispiel #16
0
            private static IMembershipService GetMembershipService(Guid[] keys)
            {
                var users      = GetDummyUsers(keys);
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetUser(
                                     It.Is <Guid>(
                                         key => keys.Contains(key)
                                         )
                                     )
                                 ).Returns <Guid>(key =>
                                                  users.FirstOrDefault(x =>
                                                                       x.User.Key == key
                                                                       )
                                                  );

                mockMemSrv.Setup(ms => ms.UpdateUser(
                                     It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>()
                                     )
                                 ).Returns <User, string, string>(
                    (user, username, email) => {
                    var roles = users
                                .FirstOrDefault(
                        x => x.User.Name.Equals(user.Name, StringComparison.OrdinalIgnoreCase)).Roles;

                    user.Name  = username;
                    user.Email = email;
                    return(new UserWithRoles {
                        User = user,
                        Roles = roles
                    });
                }
                    );

                return(mockMemSrv.Object);
            }
Beispiel #17
0
        public void TestRefundPayment()
        {
            var paymentInfo = GetValidPaymentInfoVisa();

            ServicesMockHelper.MockPaymentResponse(paymentInfo);

            var payment = Payment.Fetch("some-id");
            var id      = payment.Id;
            var amount  = payment.Amount;

            ServicesMockHelper.MockPaymentResponse
            (
                paymentInfo,
                id: id,
                status: "refunded",
                refunded: amount
            );

            payment.Refund();

            Assert.Equal(id, payment.Id);
            Assert.Equal("refunded", payment.Status);
            Assert.Equal(amount, payment.RefundedAmount);
        }