Ejemplo n.º 1
0
        public void GetBrands_Test()
        {
            UsingDbContext(async ctx =>
            {
                var initalCount = ctx.Brand.Count();
                //Arrange
                var Brand1 = new CreateBrandDto
                {
                    BrandName = "测试品牌S",
                    EngName   = "TestBrandS",
                    Spell     = "TestS",
                    IsActive  = true,
                };

                var Brand2 = new CreateBrandDto
                {
                    BrandName = "测试品牌F",
                    EngName   = "TestBrandF",
                    Spell     = "TestF",
                    IsActive  = true,
                };
                initalCount.ShouldBe(8);
                //Act
                var brandResult1 = await _brandAppService.Create(Brand1);
                var brandResult2 = await _brandAppService.Create(Brand2);
                //Assert
                initalCount.ShouldBe(8);
                brandResult1.Id.ShouldBeGreaterThan(7);
                brandResult2.Id.ShouldBeGreaterThan(8);
                ctx.Brand.Count().ShouldBe(initalCount + 2);
                var task = ctx.Brand.FirstOrDefault(t => t.BrandName == "测试品牌S");
                task.ShouldNotBe(null);
                task.IsActive.ShouldBe(true);
            });
        }
Ejemplo n.º 2
0
        public void UpdateBrands_Test()
        {
            UsingDbContext(async ctx =>
            {
                //Arrange
                var Brand = new CreateBrandDto
                {
                    BrandName = "测试品牌S",
                    EngName   = "TestBrandS",
                    Spell     = "TestS",
                    IsActive  = true,
                };
                // Act
                var brandResult1 = await _brandAppService.Create(Brand);

                var brandResult2 = await _brandAppService.Update(brandResult1);

                //Assert
                brandResult1.ShouldNotBe(null);
                brandResult2.ShouldNotBe(null);
                brandResult1.Id.ShouldBe(brandResult2.Id);
                brandResult1.TenantId.ShouldBe(brandResult2.TenantId);
                brandResult1.BrandName.ShouldNotBe(brandResult2.BrandName);
                brandResult1.EngName.ShouldNotBe(brandResult2.EngName);
                brandResult1.Spell.ShouldNotBe(brandResult2.Spell);
                brandResult1.IsActive.ShouldNotBe(brandResult2.IsActive);
            });
        }
Ejemplo n.º 3
0
 public async Task Create(CreateBrandDto input)
 {
     await BrandManager.CreateBrand(
         input.Name,
         input.BrandImageId,
         input.Description
         );
 }
Ejemplo n.º 4
0
        public async Task <ActionResult> CreateBrand([FromBody] CreateBrandDto createBrandDto)
        {
            await _mediator.Send(new CreateBrandCommand()
            {
                CreateBrandDto = createBrandDto
            });

            return(Ok());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the brand.
        /// </summary>
        /// <param name="createModel"></param>
        /// <returns></returns>
        public async Task <BrandDto> CreateBrand(CreateBrandDto createModel)
        {
            if (!validationContext.IsValid)
            {
                return(null);
            }

            var brandModel = mapper.Map <CreateBrandDto, Brand>(createModel);

            brandModel.Disabled = false;

            unitOfWork.GetRepository <Brand>().Insert(brandModel);

            await unitOfWork.SaveAsync();

            return(mapper.Map <Brand, BrandDto>(brandModel));
        }