public void CreateFromDictionary_DataDictionaryIsNotNull_TypeDictionaryNotPresent_ReturnsNewDynamicTypeDescriptorInstance()
        {
            var data       = new Dictionary <string, object>();
            var descriptor = DynamicDescriptor.CreateFromDictionary(data);

            descriptor.Should().NotBeNull();
        }
        public void TestSettingNullsInPaymentRequestModel()
        {
            var urlDetails = new UrlDetails {
                BackUrl = null, FailureUrl = null, NotificationUrl = null, PendingUrl = null, SuccessUrl = null
            };
            var userDetails = new CashierUserDetails {
                FirstName = null, LastName = null, Address = null, City = null, Country = null, Email = null, County = null, DateOfBirth = null, Phone = null, State = null, Zip = null
            };
            var userAddress = new UserAddress {
                FirstName = null, LastName = null, Address = null, City = null, Country = null, Email = null, Cell = null, County = null, Phone = null, State = null, Zip = null
            };
            var browserDetails = new DeviceDetails {
                Browser = null, DeviceName = null, DeviceOS = null, DeviceType = null, IpAddress = null
            };
            var dynamicDescriptor = new DynamicDescriptor {
                MerchantName = null, MerchantPhone = null
            };

            _ = new PaymentRequest(merchantInfo, sessionToken, currency, amount, paymentOptionCard)
            {
                AmountDetails        = null,
                BillingAddress       = userAddress,
                CustomData           = null,
                CustomSiteName       = null,
                DeviceDetails        = browserDetails,
                DynamicDescriptor    = dynamicDescriptor,
                ProductId            = null,
                RelatedTransactionId = null,
                UrlDetails           = urlDetails,
                UserDetails          = userDetails,
                Items = null
            };

            Assert.Pass();
        }
Example #3
0
        public void GetProperties_SingleAttribute_ReturnsPropertiesWithThatAttribute()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);
            var properties = descriptor.GetProperties(new Attribute[] { new AttributeOne() });

            bool containsProperty1 = false, containsProperty2 = false, containsProperty3 = false, containsProperty4 = false;

            foreach (PropertyDescriptor property in properties)
            {
                if (property.Name == "Property1")
                {
                    containsProperty1 = true;
                }
                if (property.Name == "Property2")
                {
                    containsProperty2 = true;
                }
                if (property.Name == "Property3")
                {
                    containsProperty3 = true;
                }
                if (property.Name == "Property4")
                {
                    containsProperty4 = true;
                }
            }

            containsProperty1.Should().BeTrue();
            containsProperty2.Should().BeFalse();
            containsProperty3.Should().BeTrue();
            containsProperty4.Should().BeFalse();
        }
        public void CreateFromInstance_InstanceIsNotNull_ReturnsNewDynamicTypeDescriptorInstance()
        {
            var instance   = new object();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            descriptor.Should().NotBeNull();
        }
        public void CreateFromDescriptor_DescriptorIsNotNull_ReturnsNewDynamicTypeDescriptorInstance()
        {
            var baseDescriptor = new MockCustomTypeDescriptor();
            var descriptor     = DynamicDescriptor.CreateFromDescriptor(baseDescriptor);

            descriptor.Should().NotBeNull();
        }
        public void CreateFromDescriptor_DescriptorIsNull_ThrowsArgumentNullException()
        {
            const string message = "instance should not be null.\r\nParameter name: instance";
            Action       act     = () => DynamicDescriptor.CreateFromDescriptor(null);

            act.ShouldThrow <ArgumentNullException>().WithMessage(message);
        }
Example #7
0
        public void GetProperties_ReturnsNormalProperties()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);
            var properties = descriptor.GetProperties();

            bool containsProperty1 = false, containsProperty2 = false, containsProperty3 = false, containsProperty4 = false;

            foreach (PropertyDescriptor property in properties)
            {
                if (property.Name == "Property1")
                {
                    containsProperty1 = true;
                }
                if (property.Name == "Property2")
                {
                    containsProperty2 = true;
                }
                if (property.Name == "Property3")
                {
                    containsProperty3 = true;
                }
                if (property.Name == "Property4")
                {
                    containsProperty4 = true;
                }
            }

            containsProperty1.Should().BeTrue();
            containsProperty2.Should().BeTrue();
            containsProperty3.Should().BeTrue();
            containsProperty4.Should().BeTrue();
        }
Example #8
0
        public void GetDynamicProperty_PropertyNameDoesNotMatchAProperty_ReturnsNull()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            descriptor.GetDynamicProperty(null).Should().BeNull();
            descriptor.GetDynamicProperty("NotAValidPropertyName").Should().BeNull();
        }
Example #9
0
        public void GetProperties_NullOrEmptyAttributeArray_ReturnsSameValueAsGetPropertiesWithoutAttributesSpecified()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            descriptor.GetProperties(null).Should().BeEquivalentTo(descriptor.GetProperties());
            descriptor.GetProperties(Array.Empty <Attribute>()).Should().BeEquivalentTo(descriptor.GetProperties());
        }
Example #10
0
        public async Task <Authorize3dResponse> Authorize3d(
            string currency,
            string amount,
            PaymentOption paymentOption,
            string relatedTransactionId,
            List <Item> items                   = null,
            string userTokenId                  = null,
            string clientUniqueId               = null,
            string clientRequestId              = null,
            int?isRebilling                     = null,
            AmountDetails amountDetails         = null,
            DeviceDetails deviceDetails         = null,
            CashierUserDetails userDetails      = null,
            UserAddress shippingAddress         = null,
            UserAddress billingAddress          = null,
            DynamicDescriptor dynamicDescriptor = null,
            MerchantDetails merchantDetails     = null,
            Addendums addendums                 = null,
            UrlDetails urlDetails               = null,
            string customSiteName               = null,
            string productId                    = null,
            string customData                   = null,
            string transactionType              = null,
            bool autoPayment3D                  = default,
            string userId                 = null,
            string rebillingType          = null,
            string authenticationTypeOnly = null,
            SubMerchant subMerchant       = null)
        {
            var request = new Authorize3dRequest(merchantInfo, sessionToken, currency, amount, paymentOption, relatedTransactionId)
            {
                Items                  = items,
                UserTokenId            = userTokenId,
                ClientRequestId        = clientRequestId,
                ClientUniqueId         = clientUniqueId,
                IsRebilling            = isRebilling,
                AmountDetails          = amountDetails,
                DeviceDetails          = deviceDetails,
                UserDetails            = userDetails,
                ShippingAddress        = shippingAddress,
                BillingAddress         = billingAddress,
                DynamicDescriptor      = dynamicDescriptor,
                MerchantDetails        = merchantDetails,
                Addendums              = addendums,
                UrlDetails             = urlDetails,
                CustomSiteName         = customSiteName,
                ProductId              = productId,
                CustomData             = customData,
                TransactionType        = transactionType,
                AutoPayment3D          = autoPayment3D,
                UserId                 = userId,
                RebillingType          = rebillingType,
                AuthenticationTypeOnly = authenticationTypeOnly,
                SubMerchant            = subMerchant
            };

            return(await safechargeRequestExecutor.Authorize3d(request));
        }
Example #11
0
        public void GetDynamicProperty_ExpressionRefersToAValueTypeProperty_ReturnsDynamicPropertyDescriptorForThatProperty()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            var propertyDescriptor = descriptor.GetDynamicProperty((ExampleType o) => o.Property4);

            propertyDescriptor.Should().NotBeNull();
            propertyDescriptor.Name.Should().Be("Property4");
        }
Example #12
0
        public void GetDynamicProperty_PropertyNameMatchesAProperty_ReturnsDynamicPropertyDescriptorForThatProperty()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            var propertyDescriptor = descriptor.GetDynamicProperty("Property1");

            propertyDescriptor.Should().NotBeNull();
            propertyDescriptor.Name.Should().Be("Property1");
        }
Example #13
0
        public void GetProperties_NoPropertyOrderSet_ReturnsPropertiesInAlphabeticalOrder()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            var properties = descriptor.GetProperties();

            properties[0].Name.Should().Be("Property1");
            properties[1].Name.Should().Be("Property2");
            properties[2].Name.Should().Be("Property3");
            properties[3].Name.Should().Be("Property4");
        }
        public void CreateFromDictionary_DataDictionaryIsNull_ThrowsArgumentNullException()
        {
            const string message = "data should not be null.\r\nParameter name: data";

            Action act1 = () => DynamicDescriptor.CreateFromDictionary(null);

            act1.ShouldThrow <ArgumentNullException>().WithMessage(message);

            Action act2 = () => DynamicDescriptor.CreateFromDictionary(null, null);

            act2.ShouldThrow <ArgumentNullException>().WithMessage(message);
        }
Example #15
0
        public void GetDynamicProperties_AllPropertiesActive_ReturnsSequenceContainingAllDynamicProperties()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            var properties = descriptor.GetDynamicProperties().ToArray();

            properties.Should().HaveCount(4);
            properties[0].Name.Should().Be("Property1");
            properties[1].Name.Should().Be("Property2");
            properties[2].Name.Should().Be("Property3");
            properties[3].Name.Should().Be("Property4");
        }
Example #16
0
        public void GetDynamicProperty_ExpressionRefersToSomethingOtherThanAProperty_ReturnsNull()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            Action act1 = () => descriptor.GetDynamicProperty((ExampleType o) => o.field);

            act1.ShouldThrow <ArgumentException>().WithMessage("Expression 'o => o.field' refers to a field, not a property.");

            Action act2 = () => descriptor.GetDynamicProperty((ExampleType o) => o.Method());

            act2.ShouldThrow <ArgumentException>().WithMessage("Expression 'o => o.Method()' refers to a method, not a property.");
        }
Example #17
0
        public async Task <SettleTransactionResponse> SettleTransaction(
            string currency,
            string amount,
            string relatedTransactionId,
            string clientUniqueId               = null,
            string clientRequestId              = null,
            string userId                       = null,
            Addendums addendums                 = null,
            string descriptorMerchantName       = null,
            string descriptorMerchantPhone      = null,
            DynamicDescriptor dynamicDescriptor = null,
            UrlDetails urlDetails               = null,
            string authCode                     = null,
            string customData                   = null,
            string comment                      = null,
            string customSiteName               = null,
            string productId                    = null,
            DeviceDetails deviceDetails         = null,
            string rebillingType                = null,
            string authenticationTypeOnly       = null,
            SubMerchant subMerchant             = null)
        {
            var request = new SettleTransactionRequest(
                merchantInfo,
                sessionToken,
                currency,
                amount,
                relatedTransactionId)
            {
                AuthCode                = authCode,
                ClientUniqueId          = clientUniqueId,
                ClientRequestId         = clientRequestId,
                UserId                  = userId,
                Addendums               = addendums,
                DescriptorMerchantName  = dynamicDescriptor?.MerchantName ?? descriptorMerchantName,
                DescriptorMerchantPhone = dynamicDescriptor?.MerchantPhone ?? descriptorMerchantPhone,
                UrlDetails              = urlDetails,
                CustomData              = customData,
                Comment                 = comment,
                CustomSiteName          = customSiteName,
                ProductId               = productId,
                DeviceDetails           = deviceDetails,
                RebillingType           = rebillingType,
                AuthenticationTypeOnly  = authenticationTypeOnly,
                SubMerchant             = subMerchant
            };

            return(await safechargeRequestExecutor.SettleTransaction(request));
        }
Example #18
0
        public void GetProperties_SomePropertiesAreNotActive_ReturnsOnlyActiveProperties()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            descriptor.GetDynamicProperty("Property1").SetActive(true);
            descriptor.GetDynamicProperty("Property2").SetActive(false);
            descriptor.GetDynamicProperty("Property3").SetActive(true);
            descriptor.GetDynamicProperty("Property4").SetActive(false);

            var properties = descriptor.GetProperties();

            properties.Should().HaveCount(2);
            properties[0].Name.Should().Be("Property1");
            properties[1].Name.Should().Be("Property3");
        }
Example #19
0
        public void GetProperties_PropertyOrderSet_MultiplePropertiesHaveTheSameOrder_ReturnThosePropertiesInAlphabeticalOrder()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            descriptor.GetDynamicProperty("Property1").SetPropertyOrder(1);
            descriptor.GetDynamicProperty("Property2").SetPropertyOrder(1);
            descriptor.GetDynamicProperty("Property3").SetPropertyOrder(0);
            descriptor.GetDynamicProperty("Property4").SetPropertyOrder(0);

            var properties = descriptor.GetProperties();

            properties[0].Name.Should().Be("Property3");
            properties[1].Name.Should().Be("Property4");
            properties[2].Name.Should().Be("Property1");
            properties[3].Name.Should().Be("Property2");
        }
Example #20
0
        public void GetProperties_SomePropertyOrdersSet_ReturnsPropertiesInOrderSpecifiedByPropertyOrderThenOtherPropertiesInAlphabeticalOrder()
        {
            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            descriptor.GetDynamicProperty("Property1").SetPropertyOrder(null);
            descriptor.GetDynamicProperty("Property2").SetPropertyOrder(null);
            descriptor.GetDynamicProperty("Property3").SetPropertyOrder(1);
            descriptor.GetDynamicProperty("Property4").SetPropertyOrder(0);

            var properties = descriptor.GetProperties();

            properties[0].Name.Should().Be("Property4");
            properties[1].Name.Should().Be("Property3");
            properties[2].Name.Should().Be("Property1");
            properties[3].Name.Should().Be("Property2");
        }
Example #21
0
        public void PropertyReset_RaisesPropertyChangedEvent()
        {
            string propertyChanged = null;

            var instance   = new ExampleType();
            var descriptor = DynamicDescriptor.CreateFromInstance(instance);

            descriptor.PropertyChanged += (s, e) =>
            {
                propertyChanged = e.PropertyName;
            };

            var property = descriptor.GetDynamicProperty(nameof(instance.Property1));

            property.ResetValue(descriptor);

            instance.Property1.Should().BeNull();
            propertyChanged.Should().Be("Property1");
        }
Example #22
0
        public async Task <PayoutResponse> Payout(
            string userTokenId,
            string clientUniqueId,
            string amount,
            string currency,
            UserPaymentOption userPaymentOption,
            string comment = null,
            DynamicDescriptor dynamicDescriptor = null,
            MerchantDetails merchantDetails     = null,
            UrlDetails urlDetails       = null,
            DeviceDetails deviceDetails = null,
            CardData cardData           = null,
            string userId                 = null,
            string rebillingType          = null,
            string authenticationTypeOnly = null,
            SubMerchant subMerchant       = null,
            Addendums addendums           = null)
        {
            var request = new PayoutRequest(
                merchantInfo,
                sessionToken,
                userTokenId,
                clientUniqueId,
                amount,
                currency,
                userPaymentOption)
            {
                Comment                = comment,
                DynamicDescriptor      = dynamicDescriptor,
                MerchantDetails        = merchantDetails,
                UrlDetails             = urlDetails,
                DeviceDetails          = deviceDetails,
                CardData               = cardData,
                UserId                 = userId,
                RebillingType          = rebillingType,
                AuthenticationTypeOnly = authenticationTypeOnly,
                SubMerchant            = subMerchant,
                Addendums              = addendums
            };

            return(await safechargeRequestExecutor.Payout(request));
        }
Example #23
0
        public async Task <OpenOrderResponse> OpenOrder(

            string currency,
            string amount,
            List <Item> items = null,
            OpenOrderPaymentOption paymentOption = null,
            UserPaymentOption userPaymentOption  = null,
            string paymentMethod                = null,
            string userTokenId                  = null,
            string clientUniqueId               = null,
            string clientRequestId              = null,
            string userId                       = null,
            string authenticationTypeOnly       = null,
            AmountDetails amountDetails         = null,
            DeviceDetails deviceDetails         = null,
            CashierUserDetails userDetails      = null,
            UserAddress shippingAddress         = null,
            UserAddress billingAddress          = null,
            DynamicDescriptor dynamicDescriptor = null,
            MerchantDetails merchantDetails     = null,
            Addendums addendums                 = null,
            UrlDetails urlDetails               = null,
            string customSiteName               = null,
            string productId                    = null,
            string customData                   = null,
            string transactionType              = null,
            string isMoto                       = null,
            string isRebilling                  = null,
            string rebillingType                = null,
            SubMerchant subMerchant             = null)
        {
            var request = new OpenOrderRequest(merchantInfo, sessionToken, currency, amount)
            {
                Items                  = items,
                PaymentOption          = paymentOption,
                UserPaymentOption      = userPaymentOption,
                PaymentMethod          = paymentMethod,
                UserTokenId            = userTokenId,
                ClientRequestId        = clientRequestId,
                ClientUniqueId         = clientUniqueId,
                UserId                 = userId,
                AuthenticationTypeOnly = authenticationTypeOnly,
                AmountDetails          = amountDetails,
                DeviceDetails          = deviceDetails,
                UserDetails            = userDetails,
                ShippingAddress        = shippingAddress,
                BillingAddress         = billingAddress,
                DynamicDescriptor      = dynamicDescriptor,
                MerchantDetails        = merchantDetails,
                Addendums              = addendums,
                UrlDetails             = urlDetails,
                CustomSiteName         = customSiteName,
                ProductId              = productId,
                CustomData             = customData,
                TransactionType        = transactionType,
                IsMoto                 = isMoto,
                IsRebilling            = isRebilling,
                RebillingType          = rebillingType,
                SubMerchant            = subMerchant
            };

            return(await safechargeRequestExecutor.OpenOrder(request));
        }