示例#1
0
        public void StatProjectUploadingToDomainTest()
        {
            //Arrange
            var uploadingEntity = new StatProjectUploadingV2Entity()
                {
                    Tick = "tick",
                    DateTime = new DateTime(23456345344),
                    UserId = "userId",
                    EventId = "eventId",
                    ProductName = "productName",
                    ProjectId = "projectId"
                };

            var statMapper = new StatMapper();

            //Act
            var domain = statMapper.StatProjectUploadingToDomain(uploadingEntity);

            //Assert
            Assert.AreEqual(uploadingEntity.Tick, domain.Tick);
            Assert.AreEqual(uploadingEntity.DateTime, domain.DateTime);
            Assert.AreEqual(uploadingEntity.EventId, domain.EventId);
            Assert.AreEqual(uploadingEntity.UserId, domain.UserId);
            Assert.AreEqual(uploadingEntity.ProductName, domain.ProductName);
            Assert.AreEqual(uploadingEntity.ProjectId, domain.ProjectId);
        }
示例#2
0
 public DomainStatProjectUploading StatProjectUploadingToDomain(StatProjectUploadingV2Entity entity)
 {
     return new DomainStatProjectUploading
     {
         DateTime = entity.DateTime,
         Tick = entity.Tick,
         UserId = entity.UserId,
         EventId = entity.EventId,
         ProductName = entity.ProductName,
         ProjectId = entity.ProjectId
     };
 }
        public async Task AddProjectUploadingTest()
        {
            const string eventId = "eventId";
            const string projectId = "projectId";
            const string projectName = "projectName";
            const ProjectType projectType = ProjectType.Tag;
            const ProjectSubtype projectSubtype = ProjectSubtype.Friend;

            var dateTime = new DateTime(2013, 2, 13);

            var domain = new DomainActionData();
            var httpMessageEntity = new StatHttpMessageV2Entity();
            var projectUploadingEntity = new StatProjectUploadingV2Entity();

            var guidWrapper = new Mock<IGuidWrapper>();
            var dateTimeWrapper = new Mock<IDateTimeWrapper>();
            var httpMessageRepository = new Mock<IRepository<StatHttpMessageV2Entity>>();
            var projectUploadingRepository = new Mock<IRepository<StatProjectUploadingV2Entity>>();
            var repositoryFactory = new Mock<IRepositoryFactory>();
            var statEntityFactory = new Mock<IStatEntityFactory>();

            guidWrapper.Setup(m => m.Generate()).Returns(eventId);
            dateTimeWrapper.Setup(m => m.CurrentDateTime()).Returns(dateTime);

            repositoryFactory.Setup(m => m.Create<StatHttpMessageV2Entity>(Tables.StatHttpMessageV2)).Returns(httpMessageRepository.Object);
            repositoryFactory.Setup(m => m.Create<StatProjectUploadingV2Entity>(Tables.StatProjectUploadingV2)).Returns(projectUploadingRepository.Object);

            statEntityFactory.Setup(m => m.CreateHttpMessageEntity(eventId, dateTime, domain)).Returns(httpMessageEntity);
            statEntityFactory.Setup(m => m.CreateProjectUploadingEntity(eventId, dateTime, domain, projectId, projectName, projectType,projectSubtype)).Returns(projectUploadingEntity);
            httpMessageRepository.Setup(m => m.AddAsync(httpMessageEntity, It.IsAny<CancellationToken>())).Returns(async () => httpMessageEntity);
            projectUploadingRepository.Setup(m => m.AddAsync(projectUploadingEntity, It.IsAny<CancellationToken>())).Returns(async () => projectUploadingEntity);

            var userRegistrationService = new StatProjectUploadingService(repositoryFactory.Object, statEntityFactory.Object, guidWrapper.Object, dateTimeWrapper.Object);

            //Act & Assert
            await userRegistrationService.AddProjectUploading(domain, projectId, projectName, projectType,projectSubtype);
        }
        public void GetProjectUploadingsTest()
        {
            //Arrange
            var domain1 = new DomainStatProjectUploading();
            var domain2 = new DomainStatProjectUploading();

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

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

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

            repositoryFactory.Setup(m => m.Create<StatProjectUploadingV2Entity>(Tables.StatProjectUploadingV2)).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.StatProjectUploadingToDomain(entity1)).Returns(domain1);
            statMapper.Setup(m => m.StatProjectUploadingToDomain(entity2)).Returns(domain2);

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

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

            //Assert
            Assert.AreEqual(2, result.Count);
            CollectionAssert.Contains(result, domain1);
            CollectionAssert.Contains(result, domain2);
        }