public void AddProjectCreatingCatchConflictExceptionTest()
        {
            const string projectId = "projectId";
            const string actionType = "actionType";
            var dateTime = new DateTime(2013, 2, 13);

            var domain = new DomainActionData();
            var statProjectStateV2Entity = new StatProjectStateV3Entity();

            var dateTimeWrapper = new Mock<IDateTimeWrapper>();
            var statProjectStateRepository = new Mock<IRepository<StatProjectStateV3Entity>>();
            var repositoryFactory = new Mock<IRepositoryFactory>();
            var statEntityFactory = new Mock<IStatEntityFactory>();

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

            repositoryFactory.Setup(m => m.Create<StatProjectStateV3Entity>(Tables.StatProjectStateV3)).Returns(statProjectStateRepository.Object);

            statEntityFactory.Setup(m => m.CreateProjectCreatingEntity(dateTime, domain, projectId, actionType)).Returns(statProjectStateV2Entity);
            statProjectStateRepository.Setup(m => m.AddAsync(statProjectStateV2Entity, It.IsAny<CancellationToken>())).Throws(new ConflictException());

            var statProjectCreatingService = new StatProjectStateService(repositoryFactory.Object, statEntityFactory.Object, dateTimeWrapper.Object);

            //Act & Assert
            ExceptionAssert.NotThrows<ConflictException>(()=> statProjectCreatingService.AddProjectState(domain, projectId, actionType).Wait());
        }
Ejemplo n.º 2
0
        public async Task AddWatchingTest()
        {
            const string eventId = "eventId";
            const string projectId = "projectId";
            var dateTime = new DateTime(2013, 2, 13);

            var domain = new DomainActionData();
            var httpMessageEntity = new StatHttpMessageV2Entity();
            var watchingEntity = new StatWatchingV2Entity();

            var guidWrapper = new Mock<IGuidWrapper>();
            var dateTimeWrapper = new Mock<IDateTimeWrapper>();
            var httpMessageRepository = new Mock<IRepository<StatHttpMessageV2Entity>>();
            var watchingRepository = new Mock<IRepository<StatWatchingV2Entity>>();
            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<StatWatchingV2Entity>(Tables.StatWatchingV2)).Returns(watchingRepository.Object);

            statEntityFactory.Setup(m => m.CreateHttpMessageEntity(eventId, dateTime, domain)).Returns(httpMessageEntity);
            statEntityFactory.Setup(m => m.CreateWatchingEntity(eventId, dateTime, domain, projectId)).Returns(watchingEntity);
            httpMessageRepository.Setup(m => m.AddAsync(httpMessageEntity, It.IsAny<CancellationToken>())).Returns(async () => httpMessageEntity);
            watchingRepository.Setup(m => m.AddAsync(watchingEntity, It.IsAny<CancellationToken>())).Returns(async () => watchingEntity);

            var watchingService = new StatWatchingService(repositoryFactory.Object, statEntityFactory.Object, guidWrapper.Object, dateTimeWrapper.Object);

            //Act & Assert
            await watchingService.AddWatching(domain, projectId);
        }
        public async Task AddUserLoginTest()
        {
            //Arrange
            const string eventId = "eventId";
            var dateTime = new DateTime(2013, 2, 13);

            var domain = new DomainActionData();
            var httpMessageEntity = new StatHttpMessageV2Entity();
            var userLoginEntity = new StatUserLoginV2Entity();

            var guidWrapper = new Mock<IGuidWrapper>();
            var dateTimeWrapper = new Mock<IDateTimeWrapper>();
            var httpMessageRepository = new Mock<IRepository<StatHttpMessageV2Entity>>();
            var userLoginRepository = new Mock<IRepository<StatUserLoginV2Entity>>();
            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<StatUserLoginV2Entity>(Tables.StatUserLoginV2)).Returns(userLoginRepository.Object);

            statEntityFactory.Setup(m => m.CreateHttpMessageEntity(eventId, dateTime, domain)).Returns(httpMessageEntity);
            statEntityFactory.Setup(m => m.CreateUserLoginEntity(eventId, dateTime, domain)).Returns(userLoginEntity);
            httpMessageRepository.Setup(m => m.AddAsync(httpMessageEntity, It.IsAny<CancellationToken>())).Returns(async () => httpMessageEntity);
            userLoginRepository.Setup(m => m.AddAsync(userLoginEntity, It.IsAny<CancellationToken>())).Returns(async () => userLoginEntity);

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

            //Act & Assert
            await userRegistrationService.AddUserLogin(domain);
        }
        public void LogProjectUploadingTest()
        {
            //Arrange
            const string projectId = "projectId";
            const string projectName = "projectName";
            const ProjectType projectType = ProjectType.Tag;
            const ProjectSubtype projectSubtype = ProjectSubtype.Friend;

            var timeSpan = new DateTime(2013, 7, 16);
            var actionDomain = new DomainActionData();
            var project = new FakeDomainStatProject();

            var eventLogger = new Mock<IEventLogger>();
            var statDomainFactory = new Mock<IStatDomainFactory>();
            var dateTimeWrapper = new Mock<IDateTimeWrapper>();

            var projectUploadingEventService = new ProjectUploadingEventService(eventLogger.Object,statDomainFactory.Object,dateTimeWrapper.Object);
            statDomainFactory.Setup(m => m.CreateProject(actionDomain, projectId, projectName, projectType.ToString(), projectSubtype.ToString())).Returns(project);
            dateTimeWrapper.Setup(m => m.CurrentDateTime()).Returns(timeSpan);

            //Act
            projectUploadingEventService.LogProjectUploading(actionDomain, projectId, projectName, projectType, projectSubtype);
            
            //Assert
            eventLogger.Verify(m => m.TrackProjectUploadingEvent(project, timeSpan), Times.Once());
        }
 public ProjectUploadingEventArg(DomainActionData actionData, string projectId, string projectName, ProjectType projectType, ProjectSubtype projectSubtype)
     : base(actionData)
 {
     ProjectId = projectId;
     ProjectName = projectName;
     ProjectType = projectType;
     ProjectSubtype = projectSubtype;
 }
        public Task AddUserRegistration(DomainActionData domain)
        {
            string eventId = GuidWraper.Generate();
            DateTime curDateTime = DateTimeWrapper.CurrentDateTime();

            StatUserRegistrationV2Entity userRegistrationEntity = StatEntityFactory.CreateUserRegistrationEntity(eventId, curDateTime, domain);
            ITableRepository<StatUserRegistrationV2Entity> userRegistrationRepository = RepositoryFactory.Create<StatUserRegistrationV2Entity>();

            return userRegistrationRepository.AddAsync(userRegistrationEntity);
        }
        public Task AddProjectUploading(DomainActionData actionData, string projectId, string projectName, ProjectType projectType, ProjectSubtype projectSubtype)
        {
            string eventId = GuidWraper.Generate();
            DateTime curDateTime = DateTimeWrapper.CurrentDateTime();

            StatProjectUploadingV2Entity projectUploadingEntity = StatEntityFactory.CreateProjectUploadingEntity(eventId, curDateTime, actionData, projectId, projectName, projectType, projectSubtype);
            ITableRepository<StatProjectUploadingV2Entity> projectUploadingRepository = RepositoryFactory.Create<StatProjectUploadingV2Entity>();

            return projectUploadingRepository.AddAsync(projectUploadingEntity);
        }
        public Task AddProjectDeletion(DomainActionData domain, string projectId)
        {
            string eventId = GuidWraper.Generate();
            DateTime curDateTime = DateTimeWrapper.CurrentDateTime();

            StatProjectDeletionV2Entity statProjectDeletionEntity = StatEntityFactory.CreateProjectDeletionEntity(eventId, curDateTime, domain, projectId);
            ITableRepository<StatProjectDeletionV2Entity> projectDeletionRepository = RepositoryFactory.Create<StatProjectDeletionV2Entity>();

            return projectDeletionRepository.AddAsync(statProjectDeletionEntity);
        }
Ejemplo n.º 9
0
        public Task AddWatching(DomainActionData domain, string projectId)
        {
            string eventId = GuidWraper.Generate();
            DateTime curDateTime = DateTimeWrapper.CurrentDateTime();

            StatWatchingV2Entity watchingEntity = StatEntityFactory.CreateWatchingEntity(eventId, curDateTime, domain, projectId);
            ITableRepository<StatWatchingV2Entity> watchingRepository = RepositoryFactory.Create<StatWatchingV2Entity>();

            return watchingRepository.AddAsync(watchingEntity);
        }
Ejemplo n.º 10
0
        public StatProjectDeletionV2Entity CreateProjectDeletionEntity(string eventId, DateTime dateTime, DomainActionData domain, string projectId)
        {
            string productName = _tableValueConverter.UserAgentToProductName(domain.UserAgent);

            return new StatProjectDeletionV2Entity
            {
                Tick = _tableValueConverter.DateTimeToTickWithGuid(dateTime),
                EventId = eventId,
                DateTime = dateTime,
                ProjectId = projectId,
                ProductName = productName,
                UserId = domain.UserId
            };
        }
Ejemplo n.º 11
0
        public async Task AddProjectState(DomainActionData domain, string projectId, string actionType)
        {
            DateTime curDateTime = _dateTimeWrapper.CurrentDateTime();

            StatProjectStateV3Entity statProjectStateEntity = _statEntityFactory.CreateProjectCreatingEntity(curDateTime, domain, projectId, actionType);
            ITableRepository<StatProjectStateV3Entity> statProjectStateRepository = _repositoryFactory.Create<StatProjectStateV3Entity>();

            try
            {
                await statProjectStateRepository.AddAsync(statProjectStateEntity);
            }
            catch (ConflictException)
            {
            }
        }
Ejemplo n.º 12
0
        public void Initialize()
        {
            _domain = new DomainActionData()
            {
                UserAgent = UserAgent,
                UserId = UserId,
                UserEmail = UserEmail,
                UserName = UserName,
                IdentityProvider = IdentityProvider
            };

            _tableValueConverter = new Mock<ITableValueConverter>();
            _tableValueConverter.Setup(m => m.UserAgentToProductName(UserAgent)).Returns(ProductName);
            _tableValueConverter.Setup(m => m.UserAgentToVersion(UserAgent)).Returns(ProductVersion);
        }
Ejemplo n.º 13
0
 public StatWatchingV2Entity CreateWatchingEntity(string eventId, DateTime dateTime, DomainActionData domain, string projectId)
 {
     return new StatWatchingV2Entity
     {
         Tick = _tableValueConverter.DateTimeToTickWithGuid(dateTime),
         EventId = eventId,
         DateTime = dateTime,
         IsAuthenticated = domain.IsAuthenticated,
         UrlReferrer = domain.UrlReferrer,
         UserId = domain.UserId,
         AnonymousId = domain.AnonymousId,
         ProjectId = projectId,
         UserAgent = domain.UserAgent
     };
 }
Ejemplo n.º 14
0
        public StatUserRegistrationV2Entity CreateUserRegistrationEntity(string eventId, DateTime dateTime, DomainActionData domain)
        {
            string productName = _tableValueConverter.UserAgentToProductName(domain.UserAgent);

            return new StatUserRegistrationV2Entity
            {
                Tick = _tableValueConverter.DateTimeToTickWithGuid(dateTime),
                EventId = eventId,
                DateTime = dateTime,
                Email = domain.UserEmail,
                UserName = domain.UserName,
                IdentityProvider = domain.IdentityProvider,
                ProductName = productName,
                UserId = domain.UserId
            };
        }
        public void Initialize()
        {
            var httpMessageEntity = new StatHttpMessageV2Entity();

            _dateTime = new DateTime(2013, 2, 13);
            _domain = new DomainActionData();
            _guidWrapper = new Mock<IGuidWrapper>();
            _dateTimeWrapper = new Mock<IDateTimeWrapper>();
            _httpMessageRepository = new Mock<IRepository<StatHttpMessageV2Entity>>();
            _statEntityFactory = new Mock<IStatEntityFactory>();
            _repositoryFactory = new Mock<IRepositoryFactory>();

            _httpMessageRepository.Setup(m => m.AddAsync(httpMessageEntity, It.IsAny<CancellationToken>())).Returns(async () => httpMessageEntity);
            _repositoryFactory.Setup(m => m.Create<StatHttpMessageV2Entity>(Tables.StatHttpMessageV2)).Returns(_httpMessageRepository.Object);
            _statEntityFactory.Setup(m => m.CreateHttpMessageEntity(EventId, _dateTime, _domain)).Returns(httpMessageEntity);
            _guidWrapper.Setup(m => m.Generate()).Returns(EventId);
            _dateTimeWrapper.Setup(m => m.CurrentDateTime()).Returns(_dateTime);
        }
Ejemplo n.º 16
0
 public void Initialize()
 {
     _domain = new DomainActionData()
         {
             UserAgent = UserAgent,
             HttpMethod = HttpMethod,
             IsAuthenticated = IsAuthenticated,
             StatusCode = StatusCode,
             Url = Url,
             UrlReferrer = UrlReferrer,
             UserHostAddress = UserHostAddress,
             UserHostName = UserHostName,
             UserId = UserId,
             UserLanguages = _userLanguages,
             AnonymousId = AnonymousId,
             UserEmail=Email,
             UserName=UserName,
             IdentityProvider=IdentityProvider
         };
 }
Ejemplo n.º 17
0
        public StatProjectUploadingV2Entity CreateProjectUploadingEntity(string eventId, DateTime dateTime, DomainActionData domain, string projectId, string projectName, ProjectType projectType,
            ProjectSubtype projectSubtype)
        {
            string productName = _tableValueConverter.UserAgentToProductName(domain.UserAgent);
            string productVersion = _tableValueConverter.UserAgentToVersion(domain.UserAgent);

            return new StatProjectUploadingV2Entity
            {
                Tick = _tableValueConverter.DateTimeToTickWithGuid(dateTime),
                EventId = eventId,
                DateTime = dateTime,
                ProductName = productName,
                UserId = domain.UserId,
                ProjectId = projectId,
                ProjectName = projectName,
                IdentityProvider = domain.IdentityProvider,
                ProductVersion = productVersion,
                ProjectType = (int)projectType,
                TagType = (int)projectSubtype
            };
        }
        public void IdentifyUserTest()
        {
            //Arrange
            var timeSpan = new DateTime(2013, 7, 16);
            var actionDomain = new DomainActionData();
            var user = new FakeDomainStatUser();

            var eventLogger = new Mock<IEventLogger>();
            var statDomainFactory = new Mock<IStatDomainFactory>();
            var dateTimeWrapper = new Mock<IDateTimeWrapper>();

            var userRegistrationEventService = new UserIdentifyEventService(eventLogger.Object, statDomainFactory.Object, dateTimeWrapper.Object);

            statDomainFactory.Setup(m => m.CreateUser(actionDomain)).Returns(user);
            dateTimeWrapper.Setup(m => m.CurrentDateTime()).Returns(timeSpan);

            //Act
            userRegistrationEventService.IdentifyUser(actionDomain);

            //Assert
            eventLogger.Verify(m => m.Identify(user, timeSpan), Times.Once());
        }
        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);
        }
Ejemplo n.º 20
0
 public StatProjectStateV3Entity CreateProjectCreatingEntity(DateTime dateTime, DomainActionData domain, string projectId, string actionType)
 {
     return new StatProjectStateV3Entity
     {
         ProjectId = projectId,
         ActionType = actionType,
         DateTime = dateTime,
         Producer = _tableValueConverter.UserAgentToProductName(domain.UserAgent),
         Version = _tableValueConverter.UserAgentToVersion(domain.UserAgent)
     };
 }
Ejemplo n.º 21
0
 public UserRegistrationEventArg(DomainActionData actionData)
     : base(actionData)
 {
 }
Ejemplo n.º 22
0
 public UserLoginEventArg(DomainActionData actionData)
     : base(actionData)
 {
 }
Ejemplo n.º 23
0
 public WatchingEventArg(DomainActionData actionData, string projectId)
     : base(actionData)
 {
     ProjectId = projectId;
 }
Ejemplo n.º 24
0
        public StatUserLoginV2Entity CreateUserLoginEntity(DomainActionData domain)
        {
            string productName = _tableValueConverter.UserAgentToProductName(domain.UserAgent);

            return new StatUserLoginV2Entity
            {
                IdentityProvider = domain.IdentityProvider,
                ProductName = productName,
                UserId = domain.UserId
            };
        }
Ejemplo n.º 25
0
 public StatProjectStateEventArg(DomainActionData actionData, string projectId, string actionType)
     : base(actionData)
 {
     ProjectId = projectId;
     ActionType = actionType;
 }
Ejemplo n.º 26
0
 public ProjectDeletionEventArg(DomainActionData actionData, string projectId)
     : base(actionData)
 {
     ProjectId = projectId;
 }