public void CallTest()
        {
            //Arrange
            const string portalUrl = "portalUrl";

            var domainReport = new DomainReport();
            var domainStatWatching1 = new DomainStatWatching();
            var domainStatWatching2 = new DomainStatWatching() { UrlReferrer = "UrlReferrer" };
            var domainStatWatching3 = new DomainStatWatching() { UrlReferrer = portalUrl };

            var statWatchingFilter = new Mock<IStatWatchingFilter>();

            var embedViewsFilter = new EmbeddedViewsFilter(portalUrl);
            embedViewsFilter.Set(statWatchingFilter.Object);

            //Act
            embedViewsFilter.Call(domainStatWatching1, domainReport);
            embedViewsFilter.Call(domainStatWatching2, domainReport);
            embedViewsFilter.Call(domainStatWatching3, domainReport);

            //Assert
            Assert.AreEqual(1, domainReport.EmbeddedViews);
            statWatchingFilter.Verify(m => m.Call(domainStatWatching1, domainReport), Times.Once());
            statWatchingFilter.Verify(m => m.Call(domainStatWatching2, domainReport), Times.Once());
            statWatchingFilter.Verify(m => m.Call(domainStatWatching3, domainReport), Times.Once());
        }
Пример #2
0
        public void CompileReportTest()
        {
            //Arrange
            const string projectId1 = "projectId1";
            const string projectId2 = "projectId2";
            const int days = 3;
            var startDate = new DateTime(3452345234);
            var finishDate = startDate.Add(TimeSpan.FromDays(days));
            var interval = new Interval() { Start = startDate, Finish = finishDate };
            
            var watching1 = new DomainStatWatching();
            var watching2 = new DomainStatWatching();
            var registration1 = new DomainStatUserRegistration();
            var registration2 = new DomainStatUserRegistration();
            var uploading1 = new DomainStatProjectUploading() { ProjectId = projectId1 };
            var uploading2 = new DomainStatProjectUploading() { ProjectId = projectId2 };
            var deletion1 = new DomainStatProjectDeletion() {ProjectId = projectId1};
            var deletion2 = new DomainStatProjectDeletion() {ProjectId = projectId2};
            var projectState1 = new DomainStatProjectState();
            var projectState2 = new DomainStatProjectState();

            var watchings = new List<DomainStatWatching>(){watching1,watching2};
            var registratios = new List<DomainStatUserRegistration>(){registration1,registration2};
            var uploadings = new List<DomainStatProjectUploading>(){uploading1,uploading2};
            var deletions = new List<DomainStatProjectDeletion>(){deletion1,deletion2};

            var filtersManager = new Mock<IFiltersManager>();
            var statisticsService = new Mock<IStatisticsService>();

            var compiler = new StatisticsCompiler(filtersManager.Object, statisticsService.Object, interval);

            statisticsService.Setup(m => m.GetWatchings(interval)).Returns(watchings);
            statisticsService.Setup(m => m.GetUserRegistrations(interval)).Returns(registratios);
            statisticsService.Setup(m => m.GetProjectUploadings(interval)).Returns(uploadings);
            statisticsService.Setup(m => m.GetProjectDeletions(interval)).Returns(deletions);
            statisticsService.Setup(m => m.GetProjectState(projectId1)).Returns(projectState1);
            statisticsService.Setup(m => m.GetProjectState(projectId2)).Returns(projectState2);

            //Act
            var report = compiler.CompileReport();

            //Assert
            Assert.AreEqual(days.ToString(CultureInfo.InvariantCulture), report.Interval);
            filtersManager.Verify(m => m.FilterStatWatching(watching1, report), Times.Once());
            filtersManager.Verify(m => m.FilterStatWatching(watching2, report), Times.Once());
            filtersManager.Verify(m => m.FilterStatUserRegistration(registration1, report), Times.Once());
            filtersManager.Verify(m => m.FilterStatUserRegistration(registration2, report), Times.Once());
            filtersManager.Verify(m => m.FilterStatProjectUploading(projectState1, report), Times.Once());
            filtersManager.Verify(m => m.FilterStatProjectUploading(projectState2, report), Times.Once());
            filtersManager.Verify(m => m.FilterStatProjectDeletion(projectState1, report), Times.Once());
            filtersManager.Verify(m => m.FilterStatProjectDeletion(projectState2, report), Times.Once());
            filtersManager.Verify(m => m.FilterStatProjectCancellation(projectState1, report), Times.Once());
            filtersManager.Verify(m => m.FilterStatProjectCancellation(projectState2, report), Times.Once());
        }
Пример #3
0
        public void CallWhenNotSetFelterTest()
        {
            //Arrange
            var domainStatWatching = new DomainStatWatching();
            var domainReport = new DomainReport();
            
            var allViewsFilter = new TotalViewsFilter();

            //Act
            allViewsFilter.Call(domainStatWatching, domainReport);
            allViewsFilter.Call(domainStatWatching, domainReport);
            
            //Assert
            Assert.AreEqual(2, domainReport.TotalViews);
        }
        public void CallWhenNotSetFelterTest()
        {
            //Arrange
            const string portalUrl = "portalUrl";

            var domainStatWatching = new DomainStatWatching() { UrlReferrer = "UrlReferrer" }; ;
            var domainReport = new DomainReport();

            var embedViewsFilter = new EmbeddedViewsFilter(portalUrl);

            //Act
            embedViewsFilter.Call(domainStatWatching, domainReport);
            embedViewsFilter.Call(domainStatWatching, domainReport);

            //Assert
            Assert.AreEqual(2, domainReport.EmbeddedViews);
        }
Пример #5
0
        public void CallTest()
        {
            //Arrange
            var domainStatWatching = new DomainStatWatching();
            var domainReport = new DomainReport();

            var statWatchingFilter = new Mock<IStatWatchingFilter>();

            var allViewsFilter = new TotalViewsFilter();
            allViewsFilter.Set(statWatchingFilter.Object);

            //Act
            allViewsFilter.Call(domainStatWatching, domainReport);

            //Assert
            Assert.AreEqual(1, domainReport.TotalViews);
            statWatchingFilter.Verify(m=>m.Call(domainStatWatching, domainReport), Times.Once());
        }
Пример #6
0
        public void FilterStatWatchingTest()
        {
            //Arrange
            var domainStatWatching = new DomainStatWatching();

            var statWatchingFilters = new List<IStatWatchingFilter>();
            var filter = new Mock<IStatWatchingFilter>();

            _filtersFactory.Setup(m => m.CreateStatWatchingFilters()).Returns(statWatchingFilters);
            _filtersChainBuilder.Setup(m => m.BuildStatWatchingFilter(statWatchingFilters)).Returns(filter.Object);

            var filtersManager = new FiltersManager(_filtersFactory.Object, _filtersChainBuilder.Object);

            //Act
            filtersManager.FilterStatWatching(domainStatWatching, _domainReport);

            //Assert
            filter.Verify(m=>m.Call(domainStatWatching, _domainReport), Times.Once());
        }
Пример #7
0
        public void GetWatchingsTest()
        {
            //Arrange
            var domain1 = new DomainStatWatching();
            var domain2 = new DomainStatWatching();

            var entity1 = new StatWatchingV2Entity() { Tick = Tick1 };
            var entity2 = new StatWatchingV2Entity() { Tick = Tick2 };
            var entities = new List<StatWatchingV2Entity>() { entity1, entity2 };

            var repository = new Mock<IRepository<StatWatchingV2Entity>>();

            var repositoryFactory = new Mock<IRepositoryFactory>();
            var tableValueConverter = new Mock<ITableValueConverter>();
            var statMapper = new Mock<IStatMapper>();

            repositoryFactory.Setup(m => m.Create<StatWatchingV2Entity>(Tables.StatWatchingV2)).Returns(repository.Object);
            repository.Setup(m => m.GetStatEntities(It.Is<StatQueryObject>(p => p.StartInterval == Tick2 &&
                                                                                p.EndInterval == Tick1 &&
                                                                                p.IsStartInclude == false &&
                                                                                p.IsEndInclude == false)))
                .Returns(entities);

            tableValueConverter.Setup(m => m.DateTimeToComparerTick(_startDate)).Returns(Tick2);
            tableValueConverter.Setup(m => m.DateTimeToComparerTick(_finishDate)).Returns(Tick1);
            statMapper.Setup(m => m.StatWatchingToDomain(entity1)).Returns(domain1);
            statMapper.Setup(m => m.StatWatchingToDomain(entity2)).Returns(domain2);

            var statisticsService = new StatisticsService(repositoryFactory.Object, tableValueConverter.Object, statMapper.Object);

            //Act
            var result = statisticsService.GetWatchings(_interval).ToList();

            //Assert
            Assert.AreEqual(2, result.Count);
            CollectionAssert.Contains(result, domain1);
            CollectionAssert.Contains(result, domain2);
        }
Пример #8
0
 public void FilterStatWatching(DomainStatWatching domainStatWatching, DomainReport domainReport)
 {
     _statWatchingFilter.Call(domainStatWatching, domainReport);
 }