public async Task Synchronize()
        {
            var currencyReader = new Mock <ICurrencyReader>();

            currencyReader.Setup(_ => _.ReadAllAsync())
            .ReturnsAsync(new List <Currency>
            {
                new Currency("CAD", Rate.Full, DateTime.UtcNow.Date),
                new Currency("USD", Rate.Full, DateTime.UtcNow.Date)
            });

            var currencyWriter = new Mock <ICurrencyWriter>();

            var synchronizer = new CurrencySynchronizer(currencyReader.Object, currencyWriter.Object);
            await synchronizer.SyncAsync();

            currencyWriter.Verify(_ =>
                                  _.WriteAsync(It.IsAny <Currency>()),
                                  Times.Exactly(2));

            currencyWriter.Verify(_ =>
                                  _.WriteAsync(It.Is <Currency>(c => c.Code == "CAD")),
                                  Times.Once);

            currencyWriter.Verify(_ =>
                                  _.WriteAsync(It.Is <Currency>(c => c.Code == "USD" && c.Rate == Rate.Full)),
                                  Times.Once);
        }
예제 #2
0
        public async Task <IActionResult> Sync()
        {
            try
            {
                var user = await AuthenticationClient.AuthenticateAsync(HttpContext.Request);

                foreach (var connection in await ConnectionReader.ReadByUserIdAsync(user.Id))
                {
                    await ConnectionSynchronizer.SyncAsync(connection);
                }

                await CurrencySynchronizer.SyncAsync();

                return(NoContent());
            }
            catch (ErrorException ex)
            {
                return(BadRequest(new
                {
                    message = ex.Message
                }));
            }
        }