Beispiel #1
0
        public async void should_create_a_homestats()
        {
            //arrange
            var model = new HomeStatsModel
            {
                ApplicationCount = 1,
                DeveloperCount = 2,
                TranslatorCount = 3,
                KeyCount = 4,
                TranslationCount = 5
            };

            var userRepository = new Mock<IRepository<User>>();
            userRepository.Setup(x => x.Count(y => y.RoleId != SetLocaleRole.Developer.Value))
                          .Returns(2);

            userRepository.Setup(x => x.Count(y => y.RoleId == SetLocaleRole.Translator.Value))
                          .Returns(3);

            var wordRepository = new Mock<IRepository<Word>>();
            wordRepository.Setup(x => x.Count(It.IsAny<Expression<Func<Word, bool>>>()))
                          .Returns(4);

            wordRepository.Setup(x => x.FindAll(It.IsAny<Expression<Func<Word, bool>>>()))
                         .Returns(new List<Word> { new Word { TranslationCount = 1 }, new Word { TranslationCount = 1 }, new Word { TranslationCount = 1 }, new Word { TranslationCount = 2 }, }.AsQueryable());

            var appRepository = new Mock<IRepository<App>>();
            appRepository.Setup(x => x.Count(It.IsAny<Expression<Func<App, bool>>>()))
                         .Returns(1);

            //act
            var sut = new ReportServiceBuilder().WithUserRepository(userRepository.Object)
                                                .WithWordRepository(wordRepository.Object)
                                                .WithAppRepository(appRepository.Object)
                                                .Build();
            var homestats = await sut.GetHomeStats();

            //assert
            Assert.AreEqual(model.ApplicationCount, homestats.ApplicationCount);
            Assert.AreEqual(model.DeveloperCount, homestats.DeveloperCount);
            Assert.AreEqual(model.TranslatorCount, homestats.TranslatorCount);
            Assert.AreEqual(model.KeyCount, homestats.KeyCount);
            Assert.AreEqual(model.TranslationCount, homestats.TranslationCount);

            appRepository.Verify(x => x.Count(It.IsAny<Expression<Func<App, bool>>>()), Times.AtLeastOnce);
            userRepository.Verify(x => x.Count(It.IsAny<Expression<Func<User, bool>>>()), Times.AtLeastOnce);
            wordRepository.Verify(x => x.Count(It.IsAny<Expression<Func<Word, bool>>>()), Times.AtLeastOnce);
            wordRepository.Verify(x => x.FindAll(It.IsAny<Expression<Func<Word, bool>>>()), Times.AtLeastOnce);
        }
Beispiel #2
0
        public Task<HomeStatsModel> GetHomeStats()
        {
            var developerCount = _userRepository.Count(x => x.RoleId != SetLocaleRole.Developer.Value);
            var translatorCount = _userRepository.Count(x => x.RoleId == SetLocaleRole.Translator.Value);
            var keyCount = _wordRepository.Count();
            var appCount = _appRepository.Count();
            var translationCount = _wordRepository.FindAll().Sum(x => x.TranslationCount);

            var model = new HomeStatsModel
            {
                ApplicationCount = appCount,
                DeveloperCount = developerCount,
                TranslatorCount = translatorCount,
                KeyCount = keyCount,
                TranslationCount = translationCount
            };
            
            return Task.FromResult(model);
        }
Beispiel #3
0
        public ViewResult Index()
        {
            var model = new HomeStatsModel
            {
                ApplicationCount = 5,
                DeveloperCount = 3,
                TranslatorCount = 2,
                KeyCount = 154,
                TranslationCount = 654
            };

            model.Summary = string.Format(_htmlHelper.LocalizationString("home_summary"),
                model.DeveloperCount,
                model.ApplicationCount,
                model.TranslatorCount,
                model.KeyCount,
                model.TranslationCount);

            return View(model);
        }