public void StatWatchingEntityToDomainTest() { //Arrange var watchingEntity = new StatWatchingV2Entity() { AnonymousId = "AnonymousId", DateTime = new DateTime(23456345344), ProjectId = "projectId", UrlReferrer = "urlReferrer", UserId = "userId", IsAuthenticated = true, Tick = "tick", EventId = "eventId" }; var statMapper = new StatMapper(); //Act var domain = statMapper.StatWatchingToDomain(watchingEntity); //Assert Assert.AreEqual(watchingEntity.Tick, domain.Tick); Assert.AreEqual(watchingEntity.AnonymousId, domain.AnonymousId); Assert.AreEqual(watchingEntity.DateTime, domain.DateTime); Assert.AreEqual(watchingEntity.EventId, domain.EventId); Assert.AreEqual(watchingEntity.IsAuthenticated, domain.IsAuthenticated); Assert.AreEqual(watchingEntity.ProjectId, domain.ProjectId); Assert.AreEqual(watchingEntity.UrlReferrer, domain.UrlReferrer); Assert.AreEqual(watchingEntity.UserId, domain.UserId); }
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 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)); }
public DomainStatWatching StatWatchingToDomain(StatWatchingV2Entity entity) { return(new DomainStatWatching { AnonymousId = entity.AnonymousId, DateTime = entity.DateTime, ProjectId = entity.ProjectId, Tick = entity.Tick, UrlReferrer = entity.UrlReferrer, UserId = entity.UserId, IsAuthenticated = entity.IsAuthenticated, EventId = entity.EventId, UserAgent = entity.UserAgent }); }
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); }