public DtoExpanderTests()
        {
            _dtoExpanderEngine.Setup(x => x.GetConfiguration(typeof(ProductExpandableStubDto))).Returns(new ProductExpandableStubDtoExpandProfile().GetConfiguration());
            _dtoExpanderEngine.Setup(x => x.GetConfiguration(typeof(ProductGroupExpandableStubDto))).Returns(new ProductGroupExpandableStubDtoExpandProfile().GetConfiguration());

            _externalCommandServiceMock.Setup(x => x.Execute(It.IsAny <ProductStubDtoGetByIdRequest>()))
            .Returns(new OkResponseStatus <ProductStubDtoGetByIdResponse>(new ProductStubDtoGetByIdResponse
            {
                Item = new ProductStubDto
                {
                    Id            = 1,
                    Name          = "Test",
                    PropertyId    = 15,
                    CollectionIds = new[] { 1, 2, 3, 4 }
                }
            }));

            _externalCommandServiceMock.Setup(x => x.Execute(It.IsAny <ProductCategoryStubGetByIdRequest>()))
            .Returns(new OkResponseStatus <ProductCategoryStubGetByIdResponse>(new ProductCategoryStubGetByIdResponse()
            {
                Item = new ProductCategoryStubDto()
                {
                    Id          = 1,
                    Text        = "Loaded",
                    ModeratorId = 3
                }
            }));
            _externalCommandServiceMock.Setup(x => x.Execute(It.IsAny <ProductCategoryModeratorStubGetByIdRequest>()))
            .Returns((ProductCategoryModeratorStubGetByIdRequest request) => new OkResponseStatus <ProductCategoryModeratorStubGetByIdResponse>(new ProductCategoryModeratorStubGetByIdResponse()
            {
                Item = new ProductCategoryModeratorStubDto()
                {
                    Id        = request.Id,
                    FirstName = "Test",
                    LastName  = "Moderator"
                }
            }));

            _externalCommandServiceMock.Setup(x => x.Execute(It.IsAny <ProductCategoryStubFindByIdsRequest>()))
            .Returns(new OkResponseStatus <ProductCategoryStubFindByIdsResponse>(new ProductCategoryStubFindByIdsResponse()
            {
                Items = new Collection <ProductCategoryStubDto> {
                    new ProductCategoryStubDto()
                    {
                        Id   = 1,
                        Text = "Loaded"
                    }, new ProductCategoryStubDto
                    {
                        Id   = 2,
                        Text = "Second Loaded"
                    }, new ProductCategoryStubDto
                    {
                        Id   = 3,
                        Text = "Third Loaded"
                    }, new ProductCategoryStubDto
                    {
                        Id   = 4,
                        Text = "Fourth Loaded"
                    }
                }
            }));

            _mapperMock.Setup(x => x.Map(typeof(ProductStubDto), typeof(ProductExpandableStubDto), It.IsAny <object>()))
            .Returns((Type sourceType, Type targetType, object result) =>
            {
                var cast = (ProductStubDto)result;
                return((object)new ProductExpandableStubDto
                {
                    Id = cast.Id,
                    Name = cast.Name,
                    MainCategoryId = cast.PropertyId,
                    AdditionalCategoryIds = cast.CollectionIds.ToArray()
                });
            });

            _mapperMock.Setup(x => x.Map(typeof(ProductCategoryStubDto), typeof(ProductGroupExpandableStubDto), It.IsAny <object>()))
            .Returns((Type sourceType, Type targetType, object result) =>
            {
                var cast = (ProductCategoryStubDto)result;
                return((object)new ProductGroupExpandableStubDto
                {
                    Id = cast.Id,
                    Text = cast.Text
                });
            });

            _mapperMock.Setup(x => x.Map(typeof(ProductCategoryModeratorStubDto), typeof(ProductCategoryModeratorExpandedStubDto), It.IsAny <object>()))
            .Returns((Type sourceType, Type targetType, object result) =>
            {
                var cast = (ProductCategoryModeratorStubDto)result;
                return((object)new ProductCategoryModeratorExpandedStubDto
                {
                    Id = cast.Id,
                    FullName = cast.FirstName + " " + cast.LastName
                });
            });

            _mapperMock.Setup(x => x.MapCollection <ProductCategoryStubDto, ProductGroupExpandableStubDto>(It.IsAny <IEnumerable <ProductCategoryStubDto> >()))
            .Returns((IEnumerable <ProductCategoryStubDto> result) =>
            {
                return(result.Select(x => new ProductGroupExpandableStubDto
                {
                    Id = x.Id,
                    Text = x.Text
                }));
            });

            _dtoExpander = new DtoExpander(_dtoExpanderEngine.Object, _externalCommandServiceMock.Object, _mapperMock.Object);
        }
示例#2
0
 public StoreController(IExternalCommandService externalCommandService, IDtoExpander dtoExpander)
 {
     _externalCommandService = externalCommandService;
     _dtoExpander            = dtoExpander;
 }