Exemplo n.º 1
0
        public void BlogEnumerableToBlogDTOList()
        {
            //Arrange
            var blog = BlogFactory.CreateBlog("Name", "Url", 0);

            IEnumerable <Blog> blogs = new List <Blog>()
            {
                blog
            };

            //Act
            ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter();
            var          dtos    = adapter.Adapt <IEnumerable <Blog>, List <BlogDTO> >(blogs);

            //Assert
            Assert.NotNull(dtos);
            Assert.True(dtos.Any());
            Assert.True(dtos.Count == 1);

            var dto = dtos[0];

            Assert.Equal(blog.BlogId, dto.BlogId);
            Assert.Equal(blog.Name, dto.Name);
            Assert.Equal(blog.Url, dto.Url);
            Assert.Equal(blog.Rating, dto.Rating);
        }
Exemplo n.º 2
0
        public void BlogToBlogDTOAdapter()
        {
            //Arrange
            var blog = BlogFactory.CreateBlog("Name", "Url", 0);

            //Act
            ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter();
            var          dto     = adapter.Adapt <Blog, BlogDTO>(blog);

            //Assert
            Assert.Equal(blog.BlogId, dto.BlogId);
            Assert.Equal(blog.Name, dto.Name);
            Assert.Equal(blog.Url, dto.Url);
            Assert.Equal(blog.Rating, dto.Rating);
        }
Exemplo n.º 3
0
        public override async Task <BlogDTO> AddAsync(BlogDTO blogDTO)
        {
            if (blogDTO == null)
            {
                throw new ArgumentException(_resources.GetStringResource(LocalizationKeys.Application.validation_No_Records_Found_Error));
            }

            Blog blog = BlogFactory.CreateBlog(blogDTO.Name, blogDTO.Url, blogDTO.Rating);

            if (_validator.IsValid <Blog>(blog))
            {
                _blogRepository.Add(blog);

                await _blogRepository.UnitOfWork.CommitAsync();

                return(blog.ProjectedAs <BlogDTO>());
            }
            else
            {
                throw new ApplicationValidationErrorsException(_validator.GetInvalidMessages <Blog>(blog));
            }
        }