Ejemplo n.º 1
0
        public void StatUserRegistrationToDomainTest()
        {
            //Arrange
            var registrationEntity = new StatUserRegistrationV2Entity()
            {
                Tick             = "tick",
                DateTime         = new DateTime(23456345344),
                UserId           = "userId",
                EventId          = "eventId",
                IdentityProvider = "identityProvider",
                ProductName      = "productName"
            };

            var statMapper = new StatMapper();

            //Act
            var domain = statMapper.StatUserRegistrationToDomain(registrationEntity);

            //Assert
            Assert.AreEqual(registrationEntity.Tick, domain.Tick);
            Assert.AreEqual(registrationEntity.DateTime, domain.DateTime);
            Assert.AreEqual(registrationEntity.EventId, domain.EventId);
            Assert.AreEqual(registrationEntity.UserId, domain.UserId);
            Assert.AreEqual(registrationEntity.IdentityProvider, domain.IdentityProvider);
            Assert.AreEqual(registrationEntity.ProductName, domain.ProductName);
        }
Ejemplo n.º 2
0
        public async Task AddUserRegistrationTest()
        {
            //Arrange
            const string eventId  = "eventId";
            var          dateTime = new DateTime(2013, 2, 13);

            var domain                 = new DomainActionData();
            var httpMessageEntity      = new StatHttpMessageV2Entity();
            var userRegistrationEntity = new StatUserRegistrationV2Entity();

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

            statEntityFactory.Setup(m => m.CreateHttpMessageEntity(eventId, dateTime, domain)).Returns(httpMessageEntity);
            statEntityFactory.Setup(m => m.CreateUserRegistrationEntity(eventId, dateTime, domain)).Returns(userRegistrationEntity);
            httpMessageRepository.Setup(m => m.AddAsync(httpMessageEntity, It.IsAny <CancellationToken>())).Returns(async() => httpMessageEntity);
            userRegistrationRepository.Setup(m => m.AddAsync(userRegistrationEntity, It.IsAny <CancellationToken>())).Returns(async() => userRegistrationEntity);

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

            //Act & Assert
            await userRegistrationService.AddUserRegistration(domain);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
 public DomainStatUserRegistration StatUserRegistrationToDomain(StatUserRegistrationV2Entity entity)
 {
     return(new DomainStatUserRegistration
     {
         DateTime = entity.DateTime,
         Tick = entity.Tick,
         UserId = entity.UserId,
         EventId = entity.EventId,
         IdentityProvider = entity.IdentityProvider,
         ProductName = entity.ProductName
     });
 }
        public void GetUserRegistrationsTest()
        {
            //Arrange
            var domain1 = new DomainStatUserRegistration();
            var domain2 = new DomainStatUserRegistration();

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

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

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

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

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

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

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