Exemple #1
0
        public virtual ApiDirectTweetServerResponseModel MapEntityToModel(
            DirectTweet item)
        {
            var model = new ApiDirectTweetServerResponseModel();

            model.SetProperties(item.TweetId,
                                item.Content,
                                item.Date,
                                item.TaggedUserId,
                                item.Time);
            if (item.TaggedUserIdNavigation != null)
            {
                var taggedUserIdModel = new ApiUserServerResponseModel();
                taggedUserIdModel.SetProperties(
                    item.TaggedUserIdNavigation.UserId,
                    item.TaggedUserIdNavigation.BioImgUrl,
                    item.TaggedUserIdNavigation.Birthday,
                    item.TaggedUserIdNavigation.ContentDescription,
                    item.TaggedUserIdNavigation.Email,
                    item.TaggedUserIdNavigation.FullName,
                    item.TaggedUserIdNavigation.HeaderImgUrl,
                    item.TaggedUserIdNavigation.Interest,
                    item.TaggedUserIdNavigation.LocationLocationId,
                    item.TaggedUserIdNavigation.Password,
                    item.TaggedUserIdNavigation.PhoneNumber,
                    item.TaggedUserIdNavigation.Privacy,
                    item.TaggedUserIdNavigation.Username,
                    item.TaggedUserIdNavigation.Website);

                model.SetTaggedUserIdNavigation(taggedUserIdModel);
            }

            return(model);
        }
Exemple #2
0
        public virtual BODirectTweet MapEFToBO(
            DirectTweet ef)
        {
            var bo = new BODirectTweet();

            bo.SetProperties(
                ef.TweetId,
                ef.Content,
                ef.Date,
                ef.TaggedUserId,
                ef.Time);
            return(bo);
        }
Exemple #3
0
        public virtual DirectTweet MapBOToEF(
            BODirectTweet bo)
        {
            DirectTweet efDirectTweet = new DirectTweet();

            efDirectTweet.SetProperties(
                bo.Content,
                bo.Date,
                bo.TaggedUserId,
                bo.Time,
                bo.TweetId);
            return(efDirectTweet);
        }
        public virtual async Task <ApiDirectTweetServerResponseModel> Get(int tweetId)
        {
            DirectTweet record = await this.DirectTweetRepository.Get(tweetId);

            if (record == null)
            {
                return(null);
            }
            else
            {
                return(this.DalDirectTweetMapper.MapEntityToModel(record));
            }
        }
Exemple #5
0
        public void MapEntityToModelList()
        {
            var         mapper = new DALDirectTweetMapper();
            DirectTweet item   = new DirectTweet();

            item.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("01:00:00"));
            List <ApiDirectTweetServerResponseModel> response = mapper.MapEntityToModel(new List <DirectTweet>()
            {
                { item }
            });

            response.Count.Should().Be(1);
        }
Exemple #6
0
        public void MapModelToEntity()
        {
            var mapper = new DALDirectTweetMapper();
            ApiDirectTweetServerRequestModel model = new ApiDirectTweetServerRequestModel();

            model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("01:00:00"));
            DirectTweet response = mapper.MapModelToEntity(1, model);

            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.TaggedUserId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
        }
Exemple #7
0
        public void MapEFToBOList()
        {
            var         mapper = new DALDirectTweetMapper();
            DirectTweet entity = new DirectTweet();

            entity.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("0"), 1);

            List <BODirectTweet> response = mapper.MapEFToBO(new List <DirectTweet>()
            {
                entity
            });

            response.Count.Should().Be(1);
        }
Exemple #8
0
        public void MapEntityToModel()
        {
            var         mapper = new DALDirectTweetMapper();
            DirectTweet item   = new DirectTweet();

            item.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("01:00:00"));
            ApiDirectTweetServerResponseModel response = mapper.MapEntityToModel(item);

            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.TaggedUserId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
            response.TweetId.Should().Be(1);
        }
Exemple #9
0
        public void MapEFToBO()
        {
            var         mapper = new DALDirectTweetMapper();
            DirectTweet entity = new DirectTweet();

            entity.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("0"), 1);

            BODirectTweet response = mapper.MapEFToBO(entity);

            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.TaggedUserId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("0"));
            response.TweetId.Should().Be(1);
        }
Exemple #10
0
        public void MapBOToEF()
        {
            var mapper = new DALDirectTweetMapper();
            var bo     = new BODirectTweet();

            bo.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("0"));

            DirectTweet response = mapper.MapBOToEF(bo);

            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.TaggedUserId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("0"));
            response.TweetId.Should().Be(1);
        }
Exemple #11
0
        public virtual DirectTweet MapModelToEntity(
            int tweetId,
            ApiDirectTweetServerRequestModel model
            )
        {
            DirectTweet item = new DirectTweet();

            item.SetProperties(
                tweetId,
                model.Content,
                model.Date,
                model.TaggedUserId,
                model.Time);
            return(item);
        }
        public virtual async Task <CreateResponse <ApiDirectTweetServerResponseModel> > Create(
            ApiDirectTweetServerRequestModel model)
        {
            CreateResponse <ApiDirectTweetServerResponseModel> response = ValidationResponseFactory <ApiDirectTweetServerResponseModel> .CreateResponse(await this.DirectTweetModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                DirectTweet record = this.DalDirectTweetMapper.MapModelToEntity(default(int), model);
                record = await this.DirectTweetRepository.Create(record);

                response.SetRecord(this.DalDirectTweetMapper.MapEntityToModel(record));
                await this.mediator.Publish(new DirectTweetCreatedNotification(response.Record));
            }

            return(response);
        }
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IDirectTweetRepository>();
            var record = new DirectTweet();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new DirectTweetService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.DirectTweetModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLDirectTweetMapperMock,
                                                 mock.DALMapperMockFactory.DALDirectTweetMapperMock);

            ApiDirectTweetResponseModel response = await service.Get(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public virtual async Task <UpdateResponse <ApiDirectTweetServerResponseModel> > Update(
            int tweetId,
            ApiDirectTweetServerRequestModel model)
        {
            var validationResult = await this.DirectTweetModelValidator.ValidateUpdateAsync(tweetId, model);

            if (validationResult.IsValid)
            {
                DirectTweet record = this.DalDirectTweetMapper.MapModelToEntity(tweetId, model);
                await this.DirectTweetRepository.Update(record);

                record = await this.DirectTweetRepository.Get(tweetId);

                ApiDirectTweetServerResponseModel apiModel = this.DalDirectTweetMapper.MapEntityToModel(record);
                await this.mediator.Publish(new DirectTweetUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiDirectTweetServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiDirectTweetServerResponseModel> .UpdateResponse(validationResult));
            }
        }