コード例 #1
0
        public async Task <DnaStatsV1Dto> GetDnaStatsAsync()
        {
            try
            {
                DnaStats dnaStats = await _statsService.GetDnaStatsAsync();

                DnaStatsV1Dto dnaStatsDto = _autoMapper.Map <DnaStatsV1Dto>(dnaStats);
                return(dnaStatsDto);
            }
            catch (Exception ex)
            {
                //TODO: log exception
                throw ex;
            }
        }
コード例 #2
0
        public async Task StatsService_GetDnaStatsAsync_40MutantsAnd100Humans_Succeeds()
        {
            //Arrange
            StatsService service = GetStatsService();

            _memoryCacheServiceMock.Setup(x => x.GetAsync("mutantsCount", It.IsAny <Func <Task <int> > >())).ReturnsAsync(40).Verifiable();
            _memoryCacheServiceMock.Setup(x => x.GetAsync("humansCount", It.IsAny <Func <Task <int> > >())).ReturnsAsync(100).Verifiable();

            //Action
            DnaStats result = await service.GetDnaStatsAsync();

            //Asserts
            Assert.IsNotNull(result);
            Assert.AreEqual(40, result.CountMutantDna);
            Assert.AreEqual(100, result.CountHumanDna);
            Assert.AreEqual(0.4m, result.Ratio);
            _memoryCacheServiceMock.Verify(x => x.GetAsync("mutantsCount", It.IsAny <Func <Task <int> > >()), Times.Once);
            _memoryCacheServiceMock.Verify(x => x.GetAsync("humansCount", It.IsAny <Func <Task <int> > >()), Times.Once);
        }
コード例 #3
0
        public async Task StatsV1Controller_GetDnaStatsAsync_ReturnStatsFullyMapped_Succeeds()
        {
            //Arrange
            StatsV1Controller controller = GetStatsController();
            DnaStats          stats      = new DnaStats()
            {
                CountHumanDna  = 100,
                CountMutantDna = 40,
                Ratio          = 0.4m
            };

            _statsServiceMock.Setup(x => x.GetDnaStatsAsync()).ReturnsAsync(stats).Verifiable();

            //Action
            DnaStatsV1Dto result = await controller.GetDnaStatsAsync();

            //Asserts
            Assert.IsNotNull(result);
            Assert.AreEqual(100, result.CountHumanDna);
            Assert.AreEqual(40, result.CountMutantDna);
            Assert.AreEqual(0.4m, result.Ratio);
            _statsServiceMock.Verify(x => x.GetDnaStatsAsync(), Times.Once);
        }