Example #1
0
        public void Test_that_coins_to_receive_should_be_numbers_in_a_row_starting_from_zero(string coinsToReceiveNumbers, bool shouldThrow)
        {
            var coinToSpend = new CoinToSpend
                              (
                new CoinId("1", 1),
                new Asset("KIN"),
                UMoney.Create(100, 3),
                "A"
                              );
            var coinsToReceive = coinsToReceiveNumbers
                                 .Split(',')
                                 .Select(x => new CoinToReceive
                                         (
                                             int.Parse(x),
                                             new Asset("KIN"),
                                             UMoney.Create(1, 3),
                                             "B"
                                         ))
                                 .ToArray();

            if (shouldThrow)
            {
                Assert.Throws <RequestValidationException>(() => TransactionCoinsValidator.Validate(new[] { coinToSpend }, coinsToReceive));
            }
            else
            {
                Assert.DoesNotThrow(() => TransactionCoinsValidator.Validate(new[] { coinToSpend }, coinsToReceive));
            }
        }
Example #2
0
        public void Test_that_empty_collections_are_not_allowed()
        {
            // Arrange

            var coinToSpend = new CoinToSpend
                              (
                new CoinId("1", 1),
                new Asset("KIN"),
                UMoney.Create(100, 3),
                "A"
                              );
            var coinToReceive = new CoinToReceive
                                (
                0,
                new Asset("KIN"),
                UMoney.Create(100, 3),
                "A"
                                );

            // Act, Throw

            Assert.Throws <RequestValidationException>
            (
                () => TransactionCoinsValidator.Validate(null, new[] { coinToReceive })
            );

            Assert.Throws <RequestValidationException>
            (
                () => TransactionCoinsValidator.Validate(Array.Empty <CoinToSpend>(), new[] { coinToReceive })
            );

            Assert.Throws <RequestValidationException>
            (
                () => TransactionCoinsValidator.Validate(new[] { coinToSpend }, null)
            );

            Assert.Throws <RequestValidationException>
            (
                () => TransactionCoinsValidator.Validate(new[] { coinToSpend }, Array.Empty <CoinToReceive>())
            );
        }
Example #3
0
        public void Test_that_sum_of_coins_to_send_equal_or_greater_than_sum_to_receive_for_each_assets(string assetsToSpend, string assetsToReceive, bool shouldThrow)
        {
            // Arrange

            var coinsToSpend = assetsToSpend
                               .Split(',')
                               .Select(x => x.Split(':'))
                               .Select(x => new CoinToSpend
                                       (
                                           new CoinId("1", 1),
                                           new Asset(x[0]),
                                           UMoney.Create(int.Parse(x[1]), 3),
                                           "A"
                                       ))
                               .ToArray();
            var coinsToReceive = assetsToReceive
                                 .Split(',')
                                 .Select(x => x.Split(':'))
                                 .Select((x, i) => new CoinToReceive
                                         (
                                             i,
                                             new Asset(x[0]),
                                             UMoney.Create(int.Parse(x[1]), 3),
                                             "A"
                                         ))
                                 .ToArray();

            // Act, Throw

            if (shouldThrow)
            {
                Assert.Throws <RequestValidationException>(() => TransactionCoinsValidator.Validate(coinsToSpend, coinsToReceive));
            }
            else
            {
                Assert.DoesNotThrow(() => TransactionCoinsValidator.Validate(coinsToSpend, coinsToReceive));
            }
        }
Example #4
0
        public void Test_that_sets_of_assets_should_match(string assetsToSpend, string assetsToReceive, bool shouldThrow)
        {
            // Arrange

            var coinsToSpend = assetsToSpend
                               .Split(',')
                               .Select(asset => new CoinToSpend
                                       (
                                           new CoinId("1", 1),
                                           new Asset(asset),
                                           UMoney.Create(100, 3),
                                           "A"
                                       ))
                               .ToArray();
            var coinsToReceive = assetsToReceive
                                 .Split(',')
                                 .Select((asset, i) => new CoinToReceive
                                         (
                                             i,
                                             new Asset(asset),
                                             UMoney.Create(100, 3),
                                             "A"
                                         ))
                                 .ToArray();

            // Act, Throw

            if (shouldThrow)
            {
                Assert.Throws <RequestValidationException>(() => TransactionCoinsValidator.Validate(coinsToSpend, coinsToReceive));
            }
            else
            {
                Assert.DoesNotThrow(() => TransactionCoinsValidator.Validate(coinsToSpend, coinsToReceive));
            }
        }