public async Task GetHitsCountForEmptyHitsCountTest()
        {
            //Arrange
            const string projectId1 = "projectId1";
            const string lastTick3  = "13tick";
            const long   hitsCount  = 2342;

            var hitsCountEntities     = new List <HitsCountEntity>();
            var hitsCountUpdateEntity = new HitsCountUpdateEntity()
            {
                ProjectId = projectId1,
                Tick      = lastTick3,
                Count     = hitsCount
            };

            _hitsCountsRepository
            .Setup(m => m.GetHitsCounts(It.Is <HitsCountQueryObject>(p => p.ProjectId == projectId1)))
            .Returns(hitsCountEntities);
            _hitsCountUpdateRepository
            .Setup(m => m.GetLastHitsCountUpdate(It.Is <HitsCountQueryObject>(p => p.ProjectId == projectId1)))
            .Returns(hitsCountUpdateEntity);
            _hitsCountUpdateRepository
            .Setup(m => m.AddAsync(It.IsAny <HitsCountUpdateEntity>(), It.IsAny <CancellationToken>()))
            .Returns(async() => new HitsCountUpdateEntity());

            var hitsCounterService = new HitsCounterService(_repositoryFactory.Object, _valueConverter.Object);

            //Act
            var result = await hitsCounterService.GetHitsCount(projectId1);

            //Assert
            Assert.AreEqual(hitsCount, result);
            _hitsCountUpdateRepository
            .Verify(m => m.AddAsync(It.IsAny <HitsCountUpdateEntity>(), It.IsAny <CancellationToken>()), Times.Never());
        }
        public async Task GetHitsCountTest()
        {
            //Arrange
            const string projectId1 = "projectId1";
            const string lastTick1  = "11tick";
            const string lastTick2  = "12tick";
            const string updateTick = "updateTick";
            const string tickPart   = "tickPart";
            const long   hitsCount  = 2342;

            var hitsCountEntities = new List <HitsCountEntity>()
            {
                new HitsCountEntity()
                {
                    ProjectId = projectId1, Tick = lastTick1
                },
                new HitsCountEntity()
                {
                    ProjectId = projectId1, Tick = lastTick2
                }
            };
            var hitsCountUpdateEntity = new HitsCountUpdateEntity()
            {
                ProjectId = projectId1,
                Tick      = lastTick1,
                Count     = hitsCount
            };

            _valueConverter.Setup(m => m.ChangeGuidPart(lastTick1)).Returns(updateTick);
            _valueConverter.Setup(m => m.GetTickPart(lastTick1)).Returns(tickPart);
            _hitsCountsRepository
            .Setup(m => m.GetHitsCounts(It.Is <HitsCountQueryObject>(p => p.ProjectId == projectId1 &&
                                                                     p.Tick == tickPart)))
            .Returns(hitsCountEntities);
            _hitsCountUpdateRepository
            .Setup(m => m.GetLastHitsCountUpdate(It.Is <HitsCountQueryObject>(p => p.ProjectId == projectId1)))
            .Returns(hitsCountUpdateEntity);
            _hitsCountUpdateRepository
            .Setup(m => m.AddAsync(It.IsAny <HitsCountUpdateEntity>(), It.IsAny <CancellationToken>()))
            .Returns(async() => new HitsCountUpdateEntity());

            var hitsCounterService = new HitsCounterService(_repositoryFactory.Object, _valueConverter.Object);

            //Act
            var result = await hitsCounterService.GetHitsCount(projectId1);

            //Assert
            Assert.AreEqual(hitsCount + 2, result);
            _hitsCountUpdateRepository
            .Verify(m => m.AddAsync(It.Is <HitsCountUpdateEntity>(p => p.ProjectId == projectId1 &&
                                                                  p.Tick == updateTick &&
                                                                  p.Count == hitsCount + 2), It.IsAny <CancellationToken>()),
                    Times.Once());
        }
        public async Task GetHitsCountForEmptyHitsCountTest()
        {
            //Arrange
            const string projectId1 = "projectId1";
            const string lastTick3 = "13tick";
            const long hitsCount = 2342;

            var hitsCountEntities = new List<HitsCountEntity>();
            var hitsCountUpdateEntity = new HitsCountUpdateEntity()
            {
                ProjectId = projectId1,
                Tick = lastTick3,
                Count = hitsCount
            };

            _hitsCountsRepository
                .Setup(m => m.GetHitsCounts(It.Is<HitsCountQueryObject>(p => p.ProjectId == projectId1)))
                .Returns(hitsCountEntities);
            _hitsCountUpdateRepository
                .Setup(m => m.GetLastHitsCountUpdate(It.Is<HitsCountQueryObject>(p => p.ProjectId == projectId1)))
                .Returns(hitsCountUpdateEntity);
            _hitsCountUpdateRepository
                .Setup(m => m.AddAsync(It.IsAny<HitsCountUpdateEntity>(), It.IsAny<CancellationToken>()))
                .Returns(async () => new HitsCountUpdateEntity());
            
            var hitsCounterService = new HitsCounterService(_repositoryFactory.Object, _valueConverter.Object);

            //Act
            var result = await hitsCounterService.GetHitsCount(projectId1);

            //Assert
            Assert.AreEqual(hitsCount, result);
            _hitsCountUpdateRepository
                .Verify(m => m.AddAsync(It.IsAny<HitsCountUpdateEntity>(), It.IsAny<CancellationToken>()), Times.Never());
        }
        public async Task GetHitsCountTest()
        {
            //Arrange
            const string projectId1 = "projectId1";
            const string lastTick1 = "11tick";
            const string lastTick2 = "12tick";
            const string updateTick = "updateTick";
            const string tickPart = "tickPart";
            const long hitsCount = 2342;

            var hitsCountEntities = new List<HitsCountEntity>()
                {
                    new HitsCountEntity() {ProjectId = projectId1, Tick = lastTick1},
                    new HitsCountEntity() {ProjectId = projectId1, Tick = lastTick2}
                };
            var hitsCountUpdateEntity = new HitsCountUpdateEntity()
            {
                ProjectId = projectId1,
                Tick = lastTick1,
                Count = hitsCount
            };

            _valueConverter.Setup(m => m.ChangeGuidPart(lastTick1)).Returns(updateTick);
            _valueConverter.Setup(m => m.GetTickPart(lastTick1)).Returns(tickPart);
            _hitsCountsRepository
               .Setup(m => m.GetHitsCounts(It.Is<HitsCountQueryObject>(p => p.ProjectId == projectId1 &&
                                                                                      p.Tick == tickPart)))
               .Returns(hitsCountEntities);
            _hitsCountUpdateRepository
                .Setup(m => m.GetLastHitsCountUpdate(It.Is<HitsCountQueryObject>(p => p.ProjectId == projectId1)))
                .Returns(hitsCountUpdateEntity);
            _hitsCountUpdateRepository
                .Setup(m => m.AddAsync(It.IsAny<HitsCountUpdateEntity>(), It.IsAny<CancellationToken>()))
                .Returns(async () => new HitsCountUpdateEntity());

            var hitsCounterService = new HitsCounterService(_repositoryFactory.Object, _valueConverter.Object);

            //Act
            var result = await hitsCounterService.GetHitsCount(projectId1);

            //Assert
            Assert.AreEqual(hitsCount + 2, result);
            _hitsCountUpdateRepository
               .Verify(m => m.AddAsync(It.Is<HitsCountUpdateEntity>(p => p.ProjectId == projectId1 &&
                                                                         p.Tick == updateTick &&
                                                                         p.Count == hitsCount + 2), It.IsAny<CancellationToken>()),
                   Times.Once());
        }