public async Task GetReportsTest()
        {
            //Arrange
            const string tick = "tick";
            var dateTime = new DateTime(2013, 03, 25, 2, 35, 10);
            
            var repositoryFactory = new Mock<IRepositoryFactory>();
            var valueConverter = new Mock<ITableValueConverter>();
            var mapper = new Mock<IReportMapper>();

            var reportEntity = new StandardReportV3Entity() { Tick = tick };
            var domainReport = new DomainReport();
            var reportEntities = new List<StandardReportV3Entity>() { new StandardReportV3Entity(), reportEntity };
            var domainReports = new List<DomainReport>() { domainReport };

            var fakeRepository = new FakeRepository<StandardReportV3Entity>(reportEntities);

            valueConverter.Setup(m => m.DateTimeToTick(dateTime)).Returns(tick);
            repositoryFactory.Setup(m => m.Create<StandardReportV3Entity>(Tables.StandardReportV3)).Returns(fakeRepository);
            mapper.Setup(m => m.ReportEntityToDomain(reportEntity)).Returns(domainReport);

            var reportService = new StandardReportService(repositoryFactory.Object, valueConverter.Object, mapper.Object);

            //Act
            var reports = await reportService.GetReports(dateTime);

            //Assert
            Assert.AreEqual(1, reports.Count);
            Assert.AreEqual(domainReports[0], reports[0]);
        }
        public async Task WriteReportsTest()
        {
            //Arrange
            const string tick = "tick";
            var dateTime = new DateTime(2013, 03, 25, 2, 35, 10);

            var repositoryFactory = new Mock<IRepositoryFactory>();
            var valueConverter = new Mock<ITableValueConverter>();
            var mapper = new Mock<IReportMapper>();

            var reportEntity1 = new StandardReportV3Entity();
            var reportEntity2 = new StandardReportV3Entity();
            var domainReport1 = new DomainReport();
            var domainReport2 = new DomainReport();
            var reportEntities = new List<StandardReportV3Entity>();
            var domainReports = new List<DomainReport>() {domainReport1, domainReport2};

            var fakeRepository = new FakeRepository<StandardReportV3Entity>(reportEntities);

            valueConverter.Setup(m => m.DateTimeToTick(dateTime)).Returns(tick);
            repositoryFactory.Setup(m => m.Create<StandardReportV3Entity>(Tables.StandardReportV3)).Returns(fakeRepository);
            mapper.Setup(m => m.DomainReportToEntity(domainReport1, tick)).Returns(reportEntity1);
            mapper.Setup(m => m.DomainReportToEntity(domainReport2, tick)).Returns(reportEntity2);

            var reportService = new StandardReportService(repositoryFactory.Object, valueConverter.Object, mapper.Object);

            //Act
            await reportService.WriteReports(domainReports, dateTime);

            //Assert
            Assert.AreEqual(2, reportEntities.Count);
            CollectionAssert.Contains(reportEntities, reportEntity1);
            CollectionAssert.Contains(reportEntities, reportEntity2);
        }
        public async Task   DeleteReportsTest()
        {
            //Arrange
            const string tick = "tick";
            var dateTime = new DateTime(2013, 03, 25, 2, 35, 10);

            var repositoryFactory = new Mock<IRepositoryFactory>();
            var valueConverter = new Mock<ITableValueConverter>();
            var mapper = new Mock<IReportMapper>();

            var reportEntity1 = new StandardReportV3Entity();
            var reportEntity2 = new StandardReportV3Entity();
            var domainReport1 = new DomainReport();
            var domainReport2 = new DomainReport();
            var domainReports = new List<DomainReport>() { domainReport1, domainReport2 };

            var repository = new Mock<IRepository<StandardReportV3Entity>>();
            
            valueConverter.Setup(m => m.DateTimeToTick(dateTime)).Returns(tick);
            repositoryFactory.Setup(m => m.Create<StandardReportV3Entity>(Tables.StandardReportV3)).Returns(repository.Object);
            repository.Setup(m => m.DeleteAsync(It.IsAny<IEnumerable<StandardReportV3Entity>>(), It.IsAny<CancellationToken>())).Returns(async () => { });
            mapper.Setup(m => m.DomainReportToEntity(domainReport1, tick)).Returns(reportEntity1);
            mapper.Setup(m => m.DomainReportToEntity(domainReport2, tick)).Returns(reportEntity2);

            var reportService = new StandardReportService(repositoryFactory.Object, valueConverter.Object, mapper.Object);

            //Act
            await reportService.DeleteReports(domainReports, dateTime);

            //Assert
            repository.Verify(m => m.DeleteAsync(It.Is<IEnumerable<StandardReportV3Entity>>(c => c.Contains(reportEntity1)), It.IsAny<CancellationToken>()), Times.Once());
            repository.Verify(m => m.DeleteAsync(It.Is<IEnumerable<StandardReportV3Entity>>(c => c.Contains(reportEntity2)), It.IsAny<CancellationToken>()), Times.Once());
        }
        public async Task GetLastAllDaysReportTest()
        {
            //Arrange
            var domainReport = new DomainReport();
            var reportEntityAll = new StandardReportV3Entity() { Interval = "All" };
            var repository = new Mock<IRepository<StandardReportV3Entity>>();

            var repositoryFactory = new Mock<IRepositoryFactory>();
            var valueConverter = new Mock<ITableValueConverter>();
            var mapper = new Mock<IReportMapper>();
            
            repositoryFactory.Setup(m => m.Create<StandardReportV3Entity>(Tables.StandardReportV3)).Returns(repository.Object);
            repository.Setup(m => m.GetLastReport(It.Is<ReportQueryObject>(p => p.Interval == "All"))).Returns(async () => reportEntityAll);
            mapper.Setup(m => m.ReportEntityToDomain(reportEntityAll)).Returns(domainReport);

            var standardReportService = new StandardReportService(repositoryFactory.Object,valueConverter.Object,mapper.Object);

            //Act
            var report = await standardReportService.GetLastAllDaysReport();

            //Assert
            Assert.AreEqual(domainReport, report);
        }
        public void GetDayReportsTest()
        {
            //Arrange
            var startDate = new DateTime(123214);
            var finishDate = new DateTime(234567);
            var interval = new Interval() {Start = startDate, Finish = finishDate};

            var repositoryFactory = new Mock<IRepositoryFactory>();
            var tableValueConverter = new Mock<ITableValueConverter>();
            var mapper = new Mock<IReportMapper>();

            var reportEntity1_1 = new StandardReportV3Entity() { Tick = Tick1, Interval = "1" };
            var reportEntity2_1 = new StandardReportV3Entity() { Tick = Tick2, Interval = "1" };

            var domainReport1 = new DomainReport();
            var domainReport2 = new DomainReport();

            var reportEntities = new List<StandardReportV3Entity>()
                {
                    reportEntity1_1,
                    reportEntity2_1,
                };

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

            repository.Setup(m => m.GetReportEntities(It.Is<ReportQueryObject>(p => p.StartInterval == Tick2 &&
                                                                                    p.EndInterval == Tick1 &&
                                                                                    p.IsStartInclude == true &&
                                                                                    p.IsEndInclude == false &&
                                                                                    p.Interval == "1")))
                                                                                    .Returns(reportEntities);
            tableValueConverter.Setup(m => m.DateTimeToTick(startDate)).Returns(Tick2);
            tableValueConverter.Setup(m => m.DateTimeToTick(finishDate)).Returns(Tick1);
            repositoryFactory.Setup(m => m.Create<StandardReportV3Entity>(Tables.StandardReportV3)).Returns(repository.Object);
            mapper.Setup(m => m.ReportEntityToDomain(reportEntity1_1)).Returns(domainReport1);
            mapper.Setup(m => m.ReportEntityToDomain(reportEntity2_1)).Returns(domainReport2);

            var reportService = new StandardReportService(repositoryFactory.Object, tableValueConverter.Object, mapper.Object);

            //Act
            var reports = reportService.GetDayReports(interval).ToList();

            //Assert
            Assert.AreEqual(2, reports.Count);
            CollectionAssert.Contains(reports, domainReport1);
            CollectionAssert.Contains(reports, domainReport2);
        }
Esempio n. 6
0
 public DomainReport ReportEntityToDomain(StandardReportV3Entity entity)
 {
     return new DomainReport
     {
         Tick = _tableValueConverter.TickToDateTime(entity.Tick),
         Interval = entity.Interval,
         AllRegistrations = entity.AllRegistrations,
         CicIPadDeletions = entity.CicIPadDeletions,
         CicIPadRegistrations = entity.CicIPadRegistrations,
         CicIPadSuccessfulUploads = entity.CicIPadSuccessfulUploads,
         CicIPadUploadCancels = entity.CicIPadUploadCancels,
         CicMacDeletions = entity.CicMacDeletions,
         CicMacRegistrations = entity.CicMacRegistrations,
         CicMacSuccessfulUploads = entity.CicMacSuccessfulUploads,
         CicMacUploadCancels = entity.CicMacUploadCancels,
         CicPcDeletions = entity.CicPcDeletions,
         CicPcRegistrations = entity.CicPcRegistrations,
         CicPcSuccessfulUploads = entity.CicPcSuccessfulUploads,
         CicPcUploadCancels = entity.CicPcUploadCancels,
         EmailRegistrations = entity.EmailRegistrations,
         EmbeddedViews = entity.EmbeddedViews,
         FacebookRegistrations = entity.FacebookRegistrations,
         GoogleRegistrations = entity.GoogleRegistrations,
         TaggerIPhoneDeletions = entity.TaggerIPhoneDeletions,
         TaggerIPhoneRegistrations = entity.TaggerIPhoneRegistrations,
         TaggerIPhoneUploads = entity.TaggerIPhoneSuccessfulUploads,
         TaggerIPhoneUploadCancels = entity.TaggerIPhoneUploadCancels,
         TotalViews = entity.TotalViews,
         WindowsLiveRegistrations = entity.WindowsLiveRegistrations,
         YahooRegistrations = entity.YahooRegistrations,
         ImageShackDeletions = entity.ImageShackDeletions,
         ImageShackRegistrations = entity.ImageShackRegistrations,
         ImageShackSuccessfulUploads = entity.ImageShackSuccessfulUploads,
         ImageShackUploadCancels = entity.ImageShackUploadCancels,
         TwitterRegistrations = entity.TwitterRegistrations,
         OdnoklassnikiRegistrations = entity.OdnoklassnikiRegistrations,
         BrowserRegistrations = entity.BrowserRegistrations,
         OtherRegistrations = entity.OtherRegistrations,
         PlayerDeletions = entity.PlayerDeletions,
         PlayerRegistrations = entity.PlayerRegistrations,
         PlayerSuccessfulUploads = entity.PlayerSuccessfulUploads,
         PlayerUploadCancels = entity.PlayerUploadCancels,
         StandaloneDeletions = entity.StandaloneDeletions,
         StandaloneRegistrations = entity.StandaloneRegistrations,
         StandaloneSuccessfulUploads = entity.StandaloneSuccessfulUploads,
         StandaloneUploadCancels = entity.StandaloneUploadCancels,
         TaggerAndroidDeletions = entity.TaggerAndroidDeletions,
         TaggerAndroidRegistrations = entity.TaggerAndroidRegistrations,
         TaggerAndroidSuccessfulUploads = entity.TaggerAndroidSuccessfulUploads,
         TaggerAndroidUploadCancels = entity.TaggerAndroidUploadCancels,
         DailyMotionDeletions = entity.DailyMotionDeletions,
         DailyMotionRegistrations = entity.DailyMotionRegistrations,
         DailyMotionSuccessfulUploads = entity.DailyMotionSuccessfulUploads,
         DailyMotionUploadCancels = entity.DailyMotionUploadCancels,
         VkRegistrations = entity.VkRegistrations,
         JwPlayerDeletions = entity.JwPlayerDeletions,
         JwPlayerRegistrations = entity.JwPlayerRegistrations,
         JwPlayerSuccessfulUploads = entity.JwPlayerSuccessfulUploads,
         JwPlayerUploadCancels = entity.JwPlayerUploadCancels
     };
 }
Esempio n. 7
0
        public void ReportEntityToDomainTest()
        {
            //Arrange
            var dateTime = new DateTime(664245234232223465);

            var reportEntity = new StandardReportV3Entity()
                {
                    Tick="35467568756658785",
                    Interval = "interval",
                    AllRegistrations = 12,
                    CicIPadDeletions = 23,
                    CicIPadRegistrations = 34,
                    CicIPadSuccessfulUploads = 45,
                    CicIPadUploadCancels = 445,
                    CicMacDeletions = 56,
                    CicMacRegistrations = 67,
                    CicMacSuccessfulUploads = 78,
                    CicMacUploadCancels = 778,
                    CicPcDeletions = 89,
                    CicPcRegistrations = 90,
                    CicPcSuccessfulUploads = 123,
                    CicPcUploadCancels = 1123,
                    EmailRegistrations = 234,
                    EmbeddedViews = 345,
                    FacebookRegistrations = 456,
                    GoogleRegistrations = 567,
                    TaggerIPhoneDeletions = 678,
                    TaggerIPhoneRegistrations = 789,
                    TaggerIPhoneSuccessfulUploads = 890,
                    TaggerIPhoneUploadCancels = 990,
                    TotalViews = 901,
                    WindowsLiveRegistrations = 1234,
                    YahooRegistrations = 2345,
                    ImageShackDeletions = 11,
                    ImageShackRegistrations = 22,
                    ImageShackSuccessfulUploads = 33,
                    ImageShackUploadCancels = 44,
                    TwitterRegistrations = 111,
                    BrowserRegistrations = 112,
                    OtherRegistrations = 113,
                    PlayerDeletions = 114,
                    PlayerRegistrations = 115,
                    PlayerSuccessfulUploads = 116,
                    PlayerUploadCancels = 117,
                    StandaloneDeletions = 118,
                    StandaloneRegistrations = 119,
                    StandaloneSuccessfulUploads = 221,
                    StandaloneUploadCancels = 223,
                    TaggerAndroidDeletions = 224,
                    TaggerAndroidRegistrations = 225,
                    TaggerAndroidSuccessfulUploads = 226,
                    TaggerAndroidUploadCancels = 227,
                    DailyMotionDeletions = 228,
                    DailyMotionRegistrations = 229,
                    DailyMotionSuccessfulUploads = 331,
                    DailyMotionUploadCancels = 332,
                    VkRegistrations=333,
                    JwPlayerDeletions=334,
                    JwPlayerRegistrations=335,
                    JwPlayerSuccessfulUploads=336,
                    JwPlayerUploadCancels=337,
                    OdnoklassnikiRegistrations = 448
                };

            _tableValueConverter.Setup(m => m.TickToDateTime(reportEntity.Tick)).Returns(dateTime);

            var mapper = new ReportMapper(_tableValueConverter.Object);

            //Act
            var domainReport = mapper.ReportEntityToDomain(reportEntity);
            
            //Assert
            Assert.AreEqual(dateTime, domainReport.Tick);
            Assert.AreEqual(reportEntity.Interval, domainReport.Interval);
            Assert.AreEqual(reportEntity.AllRegistrations, domainReport.AllRegistrations);
            Assert.AreEqual(reportEntity.CicIPadDeletions, domainReport.CicIPadDeletions);
            Assert.AreEqual(reportEntity.CicIPadRegistrations, domainReport.CicIPadRegistrations);
            Assert.AreEqual(reportEntity.CicIPadSuccessfulUploads, domainReport.CicIPadSuccessfulUploads);
            Assert.AreEqual(reportEntity.CicIPadUploadCancels, domainReport.CicIPadUploadCancels);
            Assert.AreEqual(reportEntity.CicMacDeletions, domainReport.CicMacDeletions);
            Assert.AreEqual(reportEntity.CicMacRegistrations, domainReport.CicMacRegistrations);
            Assert.AreEqual(reportEntity.CicMacSuccessfulUploads, domainReport.CicMacSuccessfulUploads);
            Assert.AreEqual(reportEntity.CicMacUploadCancels, domainReport.CicMacUploadCancels);
            Assert.AreEqual(reportEntity.CicPcDeletions, domainReport.CicPcDeletions);
            Assert.AreEqual(reportEntity.CicPcRegistrations, domainReport.CicPcRegistrations);
            Assert.AreEqual(reportEntity.CicPcSuccessfulUploads, domainReport.CicPcSuccessfulUploads);
            Assert.AreEqual(reportEntity.CicPcUploadCancels, domainReport.CicPcUploadCancels);
            Assert.AreEqual(reportEntity.EmailRegistrations, domainReport.EmailRegistrations);
            Assert.AreEqual(reportEntity.EmbeddedViews, domainReport.EmbeddedViews);
            Assert.AreEqual(reportEntity.FacebookRegistrations, domainReport.FacebookRegistrations);
            Assert.AreEqual(reportEntity.GoogleRegistrations, domainReport.GoogleRegistrations);
            Assert.AreEqual(reportEntity.TaggerIPhoneDeletions, domainReport.TaggerIPhoneDeletions);
            Assert.AreEqual(reportEntity.TaggerIPhoneRegistrations, domainReport.TaggerIPhoneRegistrations);
            Assert.AreEqual(reportEntity.TaggerIPhoneSuccessfulUploads, domainReport.TaggerIPhoneUploads);
            Assert.AreEqual(reportEntity.TaggerIPhoneUploadCancels, domainReport.TaggerIPhoneUploadCancels);
            Assert.AreEqual(reportEntity.TotalViews, domainReport.TotalViews);
            Assert.AreEqual(reportEntity.WindowsLiveRegistrations, domainReport.WindowsLiveRegistrations);
            Assert.AreEqual(reportEntity.YahooRegistrations, domainReport.YahooRegistrations);
            Assert.AreEqual(reportEntity.ImageShackDeletions, domainReport.ImageShackDeletions);
            Assert.AreEqual(reportEntity.ImageShackRegistrations, domainReport.ImageShackRegistrations);
            Assert.AreEqual(reportEntity.ImageShackSuccessfulUploads, domainReport.ImageShackSuccessfulUploads);
            Assert.AreEqual(reportEntity.ImageShackUploadCancels, domainReport.ImageShackUploadCancels);
            Assert.AreEqual(reportEntity.TwitterRegistrations, domainReport.TwitterRegistrations);
            Assert.AreEqual(reportEntity.OdnoklassnikiRegistrations, domainReport.OdnoklassnikiRegistrations);

            Assert.AreEqual(reportEntity.BrowserRegistrations, domainReport.BrowserRegistrations);
            Assert.AreEqual(reportEntity.OtherRegistrations, domainReport.OtherRegistrations);
            Assert.AreEqual(reportEntity.TaggerAndroidDeletions, domainReport.TaggerAndroidDeletions);
            Assert.AreEqual(reportEntity.TaggerAndroidRegistrations, domainReport.TaggerAndroidRegistrations);
            Assert.AreEqual(reportEntity.TaggerAndroidSuccessfulUploads, domainReport.TaggerAndroidSuccessfulUploads);
            Assert.AreEqual(reportEntity.TaggerAndroidUploadCancels, domainReport.TaggerAndroidUploadCancels);
            Assert.AreEqual(reportEntity.StandaloneDeletions, domainReport.StandaloneDeletions);
            Assert.AreEqual(reportEntity.StandaloneRegistrations, domainReport.StandaloneRegistrations);
            Assert.AreEqual(reportEntity.StandaloneSuccessfulUploads, domainReport.StandaloneSuccessfulUploads);
            Assert.AreEqual(reportEntity.StandaloneUploadCancels, domainReport.StandaloneUploadCancels);
            Assert.AreEqual(reportEntity.PlayerDeletions, domainReport.PlayerDeletions);
            Assert.AreEqual(reportEntity.PlayerRegistrations, domainReport.PlayerRegistrations);
            Assert.AreEqual(reportEntity.PlayerSuccessfulUploads, domainReport.PlayerSuccessfulUploads);
            Assert.AreEqual(reportEntity.PlayerUploadCancels, domainReport.PlayerUploadCancels);
            Assert.AreEqual(reportEntity.DailyMotionDeletions, domainReport.DailyMotionDeletions);
            Assert.AreEqual(reportEntity.DailyMotionRegistrations, domainReport.DailyMotionRegistrations);
            Assert.AreEqual(reportEntity.DailyMotionSuccessfulUploads, domainReport.DailyMotionSuccessfulUploads);
            Assert.AreEqual(reportEntity.DailyMotionUploadCancels, domainReport.DailyMotionUploadCancels);
            Assert.AreEqual(reportEntity.VkRegistrations, domainReport.VkRegistrations);
            Assert.AreEqual(reportEntity.JwPlayerDeletions, domainReport.JwPlayerDeletions);
            Assert.AreEqual(reportEntity.JwPlayerRegistrations, domainReport.JwPlayerRegistrations);
            Assert.AreEqual(reportEntity.JwPlayerSuccessfulUploads, domainReport.JwPlayerSuccessfulUploads);
            Assert.AreEqual(reportEntity.JwPlayerUploadCancels, domainReport.JwPlayerUploadCancels);
        }