public void MapNullProductWillThrow(ContractMapper sut)
 {
     // Fixture setup
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.Map((Product)null));
     // Teardown
 }
Пример #2
0
 public void MapNullProductsWillThrow(ContractMapper sut)
 {
     // Fixture setup
     // Exercise system and verify outcome
     Assert.Throws <ArgumentNullException>(() =>
                                           sut.Map((IEnumerable <Product>)null).ToList());
     // Teardown
 }
Пример #3
0
 public void MapNullMoneyContractWillThrow(ContractMapper sut)
 {
     // Fixture setup
     // Exercise system and verify outcome
     Assert.Throws <ArgumentNullException>(() =>
                                           sut.Map((MoneyContract)null));
     // Teardown
 }
 public void MapMoneyContractWillReturnCorrectResult(MoneyContract contract, ContractMapper sut)
 {
     // Fixture setup
     var expectedMoney = new Money(contract.Amount, contract.CurrencyCode);
     // Exercise system
     Money result = sut.Map(contract);
     // Verify outcome
     Assert.Equal(expectedMoney, result);
     // Teardown
 }
 public void MapMoneyWillReturnCorrectResult(Money money, ContractMapper sut)
 {
     // Fixture setup
     var expectedContract = money.AsSource().OfLikeness<MoneyContract>();
     // Exercise system
     MoneyContract result = sut.Map(money);
     // Verify outcome
     Assert.True(expectedContract.Equals(result));
     // Teardown
 }
 public void MapProductWillReturnCorrectResult(Product product, ContractMapper sut)
 {
     // Fixture setup
     var expectedContract = product.AsSource().OfLikeness<ProductContract>()
         .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.AsSource().OfLikeness<MoneyContract>().Equals(d.UnitPrice));
     // Exercise system
     ProductContract result = sut.Map(product);
     // Verify outcome
     Assert.True(expectedContract.Equals(result));
     // Teardown
 }
Пример #7
0
        public void MapMoneyContractWillReturnCorrectResult(MoneyContract contract, ContractMapper sut)
        {
            // Fixture setup
            var expectedMoney = new Money(contract.Amount, contract.CurrencyCode);
            // Exercise system
            Money result = sut.Map(contract);

            // Verify outcome
            Assert.Equal(expectedMoney, result);
            // Teardown
        }
Пример #8
0
        public void MapMoneyWillReturnCorrectResult(Money money, ContractMapper sut)
        {
            // Fixture setup
            var expectedContract = money.AsSource().OfLikeness <MoneyContract>();
            // Exercise system
            MoneyContract result = sut.Map(money);

            // Verify outcome
            Assert.True(expectedContract.Equals(result));
            // Teardown
        }
Пример #9
0
        public async Task Poll(string exchangeName, TimeSpan timeout)
        {
            var       tokenSource     = new CancellationTokenSource(timeout);
            var       watch           = new Stopwatch();
            var       requestDuration = 0;
            Exception exception       = null;
            ExchangeHealthControlReportType type;

            //request positions state
            try
            {
                watch.Start();

                var requestResult =
                    await _exchangeConnectorService.GetOpenedPositionAsync(exchangeName, tokenSource.Token);

                requestDuration = (int)watch.ElapsedMilliseconds;
                type            = requestResult == null
                    ? ExchangeHealthControlReportType.NoPositionData
                    : ExchangeHealthControlReportType.Ok;
            }
            catch (OperationCanceledException ex)
            {
                exception = ex;
                type      = ExchangeHealthControlReportType.ExceptionRased;
            }
            catch (Exception ex)
            {
                exception = ex;
                type      = ExchangeHealthControlReportType.ExceptionRased;

                if (!_warningCache.TryGetValue(exchangeName, out var lastWarning) ||
                    DateTime.UtcNow.Subtract(lastWarning).TotalSeconds > _failMessageThrottlingPeriodSec)
                {
                    _warningCache.AddOrUpdate(exchangeName, DateTime.UtcNow, (e, t) => DateTime.UtcNow);
                    await _log.WriteWarningAsync(nameof(ExchangeHealthControlService), nameof(Poll),
                                                 $"Exception occured while polling {exchangeName}.", ex, DateTime.UtcNow);
                }
            }

            var report = new ExchangeHealthControlResult(
                exchangeName,
                requestDuration,
                type.ToString(),
                exception,
                type == ExchangeHealthControlReportType.Ok);

            //push result to the rabbit (to be consumed by Hedging)
            await _exchangeHealthControlReportPublisher.Publish(ContractMapper.Map <ExchangeHealthControlReport>(report));

            //write statistic to table
            await _exchangeHealthControlResultRepository.InsertOrUpdateAsync(report);
        }
Пример #10
0
        public void MapProductWillReturnCorrectResult(Product product, ContractMapper sut)
        {
            // Fixture setup
            var expectedContract = product.AsSource().OfLikeness <ProductContract>()
                                   .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.AsSource().OfLikeness <MoneyContract>().Equals(d.UnitPrice));
            // Exercise system
            ProductContract result = sut.Map(product);

            // Verify outcome
            Assert.True(expectedContract.Equals(result));
            // Teardown
        }