예제 #1
0
        public DTO.ProductSize CreateProductSize(DataAccess.ProductSize productSize, bool includeOnlyActive = true)
        {
            CheckHelper.ArgumentNotNull(productSize, "productSize");
            CheckHelper.ArgumentWithinCondition(!productSize.IsNew(), "!productSize.IsNew()");

            return
                (_dtoCache.Get(
                     productSize,
                     ps =>
            {
                var result =
                    new DTO.ProductSize
                {
                    Id = ps.Id,
                    Price = ps.Price,
                    Active = ps.Active
                };

                CopyTrackableFields(result, ps);

                return result;
            },
                     (psDto, ps) =>
            {
                psDto.Size = CreateSize(ps.Size, includeOnlyActive);
                psDto.Product = CreateProduct(ps.Product, includeOnlyActive);
            }));
        }
예제 #2
0
        public void UpdateProductSize_Should_Throw_Exception_When_ProductSize_With_The_Same_Product_Size_Already_Exists()
        {
            // Arrange
            var container       = ContainerMockFactory.Create();
            var securityService = container.Get <ISecurityService>();

            securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password);

            var size    = container.Get <IDtoService>().CreateSize(SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months);
            var product = container.Get <IDtoService>().CreateProduct(ProductMockFactory.TheChildrensPlace_Boys_Sweater);

            const decimal NEW_PRODUCT_SIZE_PRICE = 1200;

            var updatedProductSize =
                new DTO.ProductSize
            {
                Id      = ProductSizeMockFactory.Girls_Sweater_0_3_Months.Id,
                Size    = size,
                Product = product,
                Active  = true,
                Price   = NEW_PRODUCT_SIZE_PRICE
            };

            var productSizeService = container.Get <IProductSizeService>();

            // Act
            // Assert
            ExceptionAssert.Throw <ProductSizeServiceException>(
                () => productSizeService.UpdateProductSize(updatedProductSize),
                "Размер товара с заданным размером уже существует для данного товара.");
        }
예제 #3
0
        public void UpdateProductSize_Should_Throw_Exception_When_Current_User_Is_Not_Seller()
        {
            // Arrange
            var container       = ContainerMockFactory.Create();
            var securityService = container.Get <ISecurityService>();

            securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password);

            var size    = container.Get <IDtoService>().CreateSize(SizeMockFactory.TheChildrensPlace_Boys_0_2_Newborn);
            var product = container.Get <IDtoService>().CreateProduct(ProductMockFactory.TheChildrensPlace_Boys_TShirt);

            const decimal NEW_PRODUCT_SIZE_PRICE = 1200;

            var updatedProductSize =
                new DTO.ProductSize
            {
                Id      = ProductSizeMockFactory.Boys_Sweater_0_3_Months.Id,
                Size    = size,
                Product = product,
                Active  = false,
                Price   = NEW_PRODUCT_SIZE_PRICE
            };

            var productSizeService = container.Get <IProductSizeService>();

            // Act
            // Assert
            ExceptionAssert.Throw <InvalidOperationException>(
                () => productSizeService.UpdateProductSize(updatedProductSize),
                "Only seller can change product size.");
        }
예제 #4
0
        public void CreateProductSize(DTO.ProductSize createdProductSize)
        {
            CheckHelper.ArgumentNotNull(createdProductSize, "createdProductSize");
            CheckHelper.ArgumentWithinCondition(createdProductSize.IsNew(), "ProductSize is not new.");
            Container.Get <IValidateService>().CheckIsValid(createdProductSize);
            CheckHelper.ArgumentWithinCondition(!createdProductSize.Product.IsNew(), "Product of ProductSize is new.");
            CheckHelper.ArgumentWithinCondition(!createdProductSize.Size.IsNew(), "Size of ProductSize is new.");

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can create product size.");

            var persistentService = Container.Get <IPersistentService>();

            var doesAnotherProductSizeWithTheSameProductAndSizeExist =
                persistentService
                .GetEntitySet <DataAccess.ProductSize>()
                .Any(ps =>
                     ps.ProductId == createdProductSize.Product.Id &&
                     ps.SizeId == createdProductSize.Size.Id);

            if (doesAnotherProductSizeWithTheSameProductAndSizeExist)
            {
                throw new ProductSizeServiceException("Размер товара с заданным размером уже существует для данного товара.");
            }

            var product = persistentService.GetEntityById <DataAccess.Product>(createdProductSize.Product.Id);

            CheckHelper.NotNull(product, "Product does not exist.");
            var size = persistentService.GetEntityById <DataAccess.Size>(createdProductSize.Size.Id);

            CheckHelper.NotNull(size, "Size does not exist.");

            CheckHelper.WithinCondition(product.SubCategoryId == size.SubCategoryId, "Товар и размер должны принадлежать одной подкатегории.");

            var productSize =
                new DataAccess.ProductSize
            {
                Active    = createdProductSize.Active,
                Price     = createdProductSize.Price,
                Product   = product,
                ProductId = product.Id,
                Size      = size,
                SizeId    = size.Id
            };

            productSize.UpdateTrackFields(Container);
            persistentService.Add(productSize);

            persistentService.SaveChanges();

            createdProductSize.Id         = productSize.Id;
            createdProductSize.CreateDate = productSize.CreateDate;
            createdProductSize.CreateUser = productSize.CreatedBy.GetFullName();
            createdProductSize.ChangeDate = productSize.ChangeDate;
            createdProductSize.ChangeUser = productSize.ChangedBy.GetFullName();
        }
예제 #5
0
        public void CreateProductSize_Should_Create_ProductSize()
        {
            // Arrange
            var container       = ContainerMockFactory.Create();
            var securityService = container.Get <ISecurityService>();

            securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password);

            var size    = container.Get <IDtoService>().CreateSize(SizeMockFactory.TheChildrensPlace_Boys_0_2_Newborn);
            var product = container.Get <IDtoService>().CreateProduct(ProductMockFactory.TheChildrensPlace_Boys_TShirt);

            const decimal NEW_PRODUCT_SIZE_PRICE = 1200;

            var createdProductSize =
                new DTO.ProductSize
            {
                Size    = size,
                Product = product,
                Active  = true,
                Price   = NEW_PRODUCT_SIZE_PRICE
            };

            var productSizeService = container.Get <IProductSizeService>();
            var persistentService  = container.Get <IPersistentService>();
            var timeService        = container.Get <ITimeService>();

            // Act
            productSizeService.CreateProductSize(createdProductSize);

            // Assert
            Assert.IsTrue(createdProductSize.Id > 0);

            var actualProductSize =
                persistentService
                .GetEntitySet <DataAccess.ProductSize>()
                .Single(ps => ps.Id == createdProductSize.Id);

            Assert.IsTrue(actualProductSize.Active);
            Assert.AreEqual(NEW_PRODUCT_SIZE_PRICE, actualProductSize.Price);
            Assert.AreEqual(SizeMockFactory.TheChildrensPlace_Boys_0_2_Newborn.Id, actualProductSize.Size.Id);
            Assert.AreEqual(SizeMockFactory.TheChildrensPlace_Boys_0_2_Newborn.Name, actualProductSize.Size.Name);
            Assert.AreEqual(SizeMockFactory.TheChildrensPlace_Boys_0_2_Newborn.Active, actualProductSize.Size.Active);
            Assert.AreEqual(ProductMockFactory.TheChildrensPlace_Boys_TShirt.Id, actualProductSize.Product.Id);
            Assert.AreEqual(ProductMockFactory.TheChildrensPlace_Boys_TShirt.Name, actualProductSize.Product.Name);
            Assert.AreEqual(ProductMockFactory.TheChildrensPlace_Boys_TShirt.Description, actualProductSize.Product.Description);
            Assert.AreEqual(ProductMockFactory.TheChildrensPlace_Boys_TShirt.Active, actualProductSize.Product.Active);
            Assert.AreEqual(timeService.UtcNow, actualProductSize.CreateDate);
            Assert.AreEqual(timeService.UtcNow, actualProductSize.ChangeDate);
            Assert.AreEqual(UserMockFactory.Diana, actualProductSize.CreatedBy);
            Assert.AreEqual(UserMockFactory.Diana, actualProductSize.ChangedBy);

            Assert.AreEqual(createdProductSize, container.Get <IDtoService>().CreateProductSize(actualProductSize));
        }
예제 #6
0
        private void UpdateProductSize(OrderItem orderItem, DTO.ProductSize productSize)
        {
            CheckHelper.ArgumentNotNull(orderItem, "orderItem");
            CheckHelper.ArgumentNotNull(productSize, "productSize");

            var productSizeId = productSize.Id;

            CheckHelper.WithinCondition(productSizeId > 0, "Product size is new.");

            var persistentService = Container.Get <IPersistentService>();

            var ps = persistentService.GetEntityById <DataAccess.ProductSize>(productSizeId);

            CheckHelper.NotNull(ps, "Product size user does not exist.");

            orderItem.ProductSizeId = ps.Id;
            orderItem.ProductSize   = ps;
        }