public void Test()
        {
            IProduct product = ProductFactory.Create(Category.B);

            Assert.IsNotNull(product);
            Assert.AreEqual <Type>(typeof(ConcreteProductB), product.GetType());
        }
Пример #2
0
        public List <Product> GetProductJoinProductTypeAndCompanyById(int lower, int upper)
        {
            try
            {
                var db         = dbClient.GetDatabase(database);
                var collection = db.GetCollection <BsonDocument>("Product");
                var builder    = Builders <BsonDocument> .Filter;
                var filter     = builder.Gte("ProductId", lower) & builder.Lte("ProductId", upper);

                var aggregation = collection.Aggregate()
                                  .Lookup("ProductType", "productTypeId", "ProductTypeId", "ProductType_object")
                                  .Lookup("Company", "CompanyId", "CompanyId", "Company_object")
                                  .Match(filter)
                ;

                var documents = aggregation.ToList();

                List <Product> products = new List <Product>();

                for (int i = 0; i < documents.Count; i++)
                {
                    products.Add(ProductFactory.Create(documents[i]));
                }
                return(products);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }
Пример #3
0
 public void Init(int ID, string WPT, IRole uvo, SummonVO svo)
 {
     PickedProduct = ProductFactory.Create(ID, WPT);
     textBox1.Text = PickedProduct.GetName();
     this.UVO      = uvo;
     this.SVO      = svo;
 }
Пример #4
0
 private Product CreateProduct(CreateProductCommand command)
 {
     return(_factory.Create(
                command.Name,
                command.Description,
                new CategoryKey(command.CategoryId)));
 }
Пример #5
0
        public void AskProduct(OrderLookupResponse response)
        {
            ProductManager productManager = ProductFactory.Create();

            while (true)
            {
                Console.Write($"Enter Product ({response.Order.ProductType}): ");
                string          product         = Console.ReadLine();
                ProductResponse productResponse = productManager.ProductInfo(product);
                if (String.IsNullOrEmpty(product))
                {
                    ConsoleIO.DisplayOrderDetails(response.Order);
                    return;
                }
                else
                {
                    if (productResponse.Success)
                    {
                        response.Order.ProductType            = productResponse.Product.ProductType;
                        response.Order.LaborCostPerSquareFoot = productResponse.Product.LaborCostPerSquareFoot;
                        response.Order.CostPerSquareFoot      = productResponse.Product.CostPerSquareFoot;
                        ConsoleIO.DisplayOrderDetails(response.Order);
                        break;
                    }
                    else
                    {
                        Console.WriteLine(productResponse.Message);
                        ConsoleIO.PressAnyKey();
                        continue;
                    }
                }
            }
        }
Пример #6
0
        public void Test()
        {
            var product = ProductFactory.Create(Category.B);

            Assert.IsNotNull(product);
            Assert.IsInstanceOfType(product, typeof(ConcreteProductB));
        }
Пример #7
0
        public void PutSuccessTest()
        {
            TokenModel tokenModel = GetToken();

            var withQuantityPostProduct = ProductFactory.Create(StateProduct.WithQuantity);
            var postRequestBuilder      = CreateRequestBuilder(ApiAddressProduct,
                                                               Method.POST.ToString(),
                                                               tokenModel.Token,
                                                               CreateContent(withQuantityPostProduct));

            var postResponse = postRequestBuilder.PostAsync().Result;

            postResponse.EnsureSuccessStatusCode();

            Assert.AreEqual(HttpStatusCode.Created, postResponse.StatusCode);



            var putProduct        = ProductFactory.Create(StateProduct.WithoutQuantity);
            var putRequestBuilder = CreateRequestBuilder($"{ApiAddressProduct}{withQuantityPostProduct.Sku}",
                                                         Method.PUT.ToString(),
                                                         tokenModel.Token,
                                                         CreateContent(putProduct));

            var putResponse = putRequestBuilder.SendAsync(Method.PUT.ToString()).Result;

            putResponse.EnsureSuccessStatusCode();

            putProduct.Inventory.CalculateQuantity();
            putProduct.IsMarketableProduct();

            Assert.AreEqual(HttpStatusCode.NoContent, putResponse.StatusCode);
            Assert.AreEqual(putProduct.IsMarketable, false);
            Assert.IsTrue(putProduct.Inventory.Quantity == 0);
        }
Пример #8
0
        public Product GetProductById(int id)
        {
            MySqlConnection conn = Connect();

            try
            {
                conn.Open();
                string          sql = "SELECT * FROM product WHERE ProductId = " + id;
                MySqlCommand    cmd = new MySqlCommand(sql, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();
                rdr.Read();

                Product product = ProductFactory.Create(rdr);
                return(product);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
            finally
            {
                conn.Close();
            }
        }
Пример #9
0
        /// <summary>
        /// 商品マスタリストを更新します。
        /// </summary>
        /// <param name="input">商品マスタリストの更新対象。</param>
        public Task <HttpStatusCode> Put(IEnumerable <ProductInputModel> input)
        {
            return(Task.Run(() =>
            {
                var addedProducts = input.GetAdded();
                var modifiedProducts = input.GetModified();
                var deletedProducts = input.GetDeleted();
                var updateDateTime = DateTime.Now;
                var updateUserId = "Stub";

                // 追加
                foreach (var product in addedProducts)
                {
                    var addedProduct = DataBase.Products.FirstOrDefault(p => p.ProductId.Equals(product.ProductId));
                    if (addedProduct == null)
                    {
                        DataBase.Products.Add(ProductFactory.Create(
                                                  productId: product.ProductId,
                                                  productName: product.ProductName,
                                                  brandId: product.BrandId,
                                                  catetoryId: product.CatetoryId,
                                                  listPrice: product.ListPrice,
                                                  productTagType: product.ProductTagType,
                                                  updateDateTime: updateDateTime,
                                                  updateUserId: updateUserId
                                                  ));
                    }
                }

                // 更新
                foreach (var product in modifiedProducts)
                {
                    var modifiedProduct = DataBase.Products.FirstOrDefault(p => p.ProductId.Equals(product.ProductId));
                    if (modifiedProduct == null)
                    {
                        continue;
                    }
                    modifiedProduct.ProductName = product.ProductName;
                    modifiedProduct.BrandId = product.BrandId;
                    modifiedProduct.CatetoryId = product.CatetoryId;
                    modifiedProduct.ListPrice = product.ListPrice;
                    modifiedProduct.ProductTagType = product.ProductTagType;
                    modifiedProduct.UpdateDateTime = updateDateTime;
                    modifiedProduct.UpdateUserId = updateUserId;
                }

                // 削除
                foreach (var product in deletedProducts)
                {
                    var deletedProduct = DataBase.Products.FirstOrDefault(p => p.ProductId.Equals(product.ProductId));
                    if (deletedProduct == null)
                    {
                        continue;
                    }
                    DataBase.Products.Remove(deletedProduct);
                }

                return HttpStatusCode.OK;
            }));
        }
Пример #10
0
        public Product GetProductJoinProductTypeAndCompanyById(int id)
        {
            try
            {
                var db         = dbClient.GetDatabase(database);
                var collection = db.GetCollection <BsonDocument>("Product");
                var filter     = Builders <BsonDocument> .Filter.Eq("ProductId", id);

                var aggregation = collection.Aggregate()
                                  .Lookup("ProductType", "productTypeId", "ProductTypeId", "ProductType_object")
                                  .Lookup("Company", "CompanyId", "CompanyId", "Company_object")
                                  .Match(filter)
                ;

                var     documents = aggregation.ToList();
                var     document  = documents[0];
                Product product   = ProductFactory.Create(document);

                return(product);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }
Пример #11
0
        public Product GetProductJoinProductTypeAndCompanyById(int id)
        {
            MySqlConnection conn = Connect();

            try
            {
                conn.Open();
                string sql = "SELECT * " +
                             "FROM product " +
                             "JOIN producttype ON producttype.productTypeId = product.productTypeId " +
                             "JOIN company ON company.CompanyId = product.CompanyId " +
                             "WHERE ProductId = " + id;
                MySqlCommand    cmd = new MySqlCommand(sql, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();
                rdr.Read();
                Product product = ProductFactory.Create(rdr);
                return(product);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
            finally
            {
                conn.Close();
            }
        }
Пример #12
0
        public void WhenPriceAlreadyApproved_ShouldThrowException()
        {
            var product = ProductFactory.Create();
            var command = new ApproveProductPrice();

            Assert.That(() => product.ApprovePrice(command), Throws.TypeOf <PriceAlreadyApproved>());
        }
Пример #13
0
        public void WithEmptyCode_ShouldThrowException()
        {
            var product = ProductFactory.Create();
            var command = new UpdateProduct("", product.Name, product.Price);

            Assert.That(() => product.Update(command), Throws.TypeOf <ProductCodeEmpty>());
        }
Пример #14
0
        public List <Product> GetProductJoinProductTypeAndCompanyById(int lower, int upper)
        {
            MySqlConnection conn = Connect();

            try
            {
                conn.Open();
                string sql = "SELECT * " +
                             "FROM product " +
                             "JOIN producttype ON producttype.productTypeId = product.productTypeId " +
                             "JOIN company ON company.CompanyId = product.CompanyId " +
                             "WHERE product.ProductId BETWEEN " + lower + " AND " + upper;
                MySqlCommand    cmd      = new MySqlCommand(sql, conn);
                MySqlDataReader rdr      = cmd.ExecuteReader();
                List <Product>  products = new List <Product>();
                while (rdr.Read())
                {
                    products.Add(ProductFactory.Create(rdr));
                }

                return(products);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
            finally
            {
                conn.Close();
            }
        }
Пример #15
0
        public void HowManyProductsInWarehousesTest()
        {
            var  withoutQuantityProduct          = ProductFactory.Create(StateProduct.WithoutQuantity);
            uint quantityAllProductsOfWarehouses = 0;

            foreach (var item in withoutQuantityProduct.Inventory.Warehouses)
            {
                quantityAllProductsOfWarehouses += item.Quantity;
            }

            PostProductTest(withoutQuantityProduct);

            TokenModel tokenModel = GetToken();


            var getRequestBuilder = CreateRequestBuilder(Method.GET,
                                                         tokenModel.Token,
                                                         null,
                                                         withoutQuantityProduct.Sku.ToString());
            var getResponse = getRequestBuilder.GetAsync().Result;

            Assert.AreEqual(HttpStatusCode.OK, getResponse.StatusCode);

            var objString     = getResponse.Content.ReadAsStringAsync().Result;
            var productReturn = JsonConvert.DeserializeObject <ResponseProductModel>(objString);

            Assert.IsTrue(productReturn.Data.Inventory.Quantity == quantityAllProductsOfWarehouses);
        }
        public static bool InsertNewProductWithDefaultQuantity(string name, int price)
        {
            // Bikin object pake Factory
            Product newProduct = ProductFactory.Create(name, price);

            // Masukin object nya ke db lewat repo
            return(ProductRepository.InsertProduct(newProduct));
        }
Пример #17
0
        public static void Main(string[] args)
        {
            // Factoryクラスは、IProductを実装していれば、IDCard以外のインスタンスも生成できる
            var factory = new ProductFactory <IDCard>();

            // これ以降は、IDCardという具象クラスには依存していない
            // IDCardではなく、IProductというインターフェースに対してプログラミングしている。
            IProduct card1 = factory.Create("結城浩");
            IProduct card2 = factory.Create("とむら");
            IProduct card3 = factory.Create("佐藤花子");

            card1.Use();
            card2.Use();
            card3.Use();

            factory.Owners.ForEach(owner => Console.WriteLine(owner));
        }
Пример #18
0
        public void WithNegativePrice_ShouldThrowException()
        {
            var updatedPrice = -10;
            var product      = ProductFactory.Create();
            var command      = new UpdateProduct(product.Code, product.Name, updatedPrice);

            Assert.That(() => product.Update(command), Throws.TypeOf <PriceInvalid>());
        }
Пример #19
0
        private void bEditWP_Click(object sender, EventArgs e)
        {
            IProduct pr = SVO.ProductVO;

            pr.ViewEdit(UVO);
            SVO.ProductVO = ProductFactory.Create(SVO.IDWPNAME, SVO.WPTYPE);

            InitTableLayout();
        }
Пример #20
0
        public async Task <ProductDto> Create(ProductDataDto dto)
        {
            validator.Validate(dto);
            var product      = productFactory.Create(dto);
            var addedProduct = await repository.AddAsync(product);

            await unitOfWork.SaveAsync();

            return(mapper.Map <ProductDto>(addedProduct));
        }
Пример #21
0
        public void WithPriceHigherThanThreshold_ShouldNotBeApproved()
        {
            var price = 1000;

            var product = ProductFactory.Create(price: price);

            Assert.That(product.Id, Is.Not.EqualTo(default(Guid)));
            Assert.That(product.Price, Is.EqualTo(price));
            Assert.That(product.PriceApproved, Is.False);
        }
Пример #22
0
        public void WithValidRequest_ShouldUpdateProperties()
        {
            var updatedCode = "updatedCode";
            var product     = ProductFactory.Create();
            var command     = new UpdateProduct(updatedCode, product.Name, product.Price);

            product.Update(command);

            Assert.That(product.Code, Is.EqualTo(updatedCode));
        }
        public void Run()
        {
            try
            {
                string[] peopleInput = Console.ReadLine()
                                       .Split(";")
                                       .ToArray();

                List <Person> people = new List <Person>();

                PersonFactory.Create(peopleInput, people);

                string[] productsInput = Console.ReadLine()
                                         .Split(";", StringSplitOptions.RemoveEmptyEntries)
                                         .ToArray();

                List <Product> products = new List <Product>();

                ProductFactory.Create(productsInput, products);

                string input = string.Empty;

                while ((input = Console.ReadLine()) != "END")
                {
                    string[] elements = input
                                        .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                        .ToArray();

                    string personName  = elements[0];
                    string productName = elements[1];

                    int indexPerson  = people.FindIndex(x => x.Name == personName);
                    int indexProduct = products.FindIndex(x => x.Name == productName);

                    if (indexPerson == -1 || indexProduct == -1)
                    {
                        continue;
                    }

                    string result = people[indexPerson].BuyProduct(products[indexProduct]);

                    Console.WriteLine(result);
                }

                foreach (Person person in people)
                {
                    Console.WriteLine(person);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #24
0
        public void WhenPriceNotApproved_ShouldApprove()
        {
            var product = ProductFactory.Create(price: 1000);
            var command = new ApproveProductPrice();

            Assert.That(product.PriceApproved, Is.False);

            product.ApprovePrice(command);

            Assert.That(product.PriceApproved, Is.True);
        }
Пример #25
0
        public void WithPriceAboveThreshold_ShouldNotBeApproved()
        {
            var updatedPrice = 1000;
            var product      = ProductFactory.Create();
            var command      = new UpdateProduct(product.Code, product.Name, updatedPrice);

            product.Update(command);

            Assert.That(product.Price, Is.EqualTo(updatedPrice));
            Assert.That(product.PriceApproved, Is.False);
        }
Пример #26
0
 protected void CallFactory(IEnumerable <ProductData> productData, ProductsObjectsList contextList)
 {
     foreach (var data in productData)
     {
         contextList.Add(ProductFactory.Create(
                             ProductsDictionary[data.Id]
                             , MoniesDictionary[data.PriceId].Currency
                             , MoniesDictionary[data.PriceId]
                             //in this sale we only have 1 vendor, so no built-in function for selecting a specific one
                             , Vendors["1"]));
     }
 }
Пример #27
0
        private async Task <Result <Product> > GetProductOrError(Guid productId)
        {
            var maybeProduct = await _productRepository.FindById(productId);

            if (maybeProduct.HasNoValue)
            {
                return(Result.Fail <Product>("Product does not exist"));
            }

            var productAdapter = maybeProduct.Value;

            var categoryOrError = await GetCategoryOrError(productAdapter.CategoryName);

            var filesOrError = await GetFilesOrErrors(productAdapter.FileNames);

            var idOrError = Identifier.Of(productAdapter.Id);

            var nameOrError = Name.Of(productAdapter.Name);

            var descriptionOrError = Description.Of(productAdapter.Description);

            var priceOrError = Price.Of(productAdapter.Price);

            var quantityOrError = Quantity.Of(productAdapter.Quantity);

            var result = Result.Combine
                         (
                Result.Combine(idOrError, categoryOrError, nameOrError, descriptionOrError, priceOrError, quantityOrError),
                Result.Combine(filesOrError)
                         );

            if (result.Failure)
            {
                return(Result.Fail <Product>(result.Message));
            }

            var files = filesOrError.Select(it => it.Value);

            var product = ProductFactory.Create
                          (
                idOrError.Value,
                categoryOrError.Value,
                nameOrError.Value,
                descriptionOrError.Value,
                priceOrError.Value,
                quantityOrError.Value,
                files,
                productAdapter.Status
                          );

            return(Result.Ok(product));
        }
Пример #28
0
        public void PostProductTest()
        {
            TokenModel tokenModel = GetToken();

            var badProduct     = ProductFactory.Create(StateProduct.Bad);
            var requestBuilder = CreateRequestBuilder(Method.POST,
                                                      tokenModel.Token,
                                                      CreateContent(badProduct));

            var response = requestBuilder.PostAsync().Result;

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Пример #29
0
        private void button1_Click(object sender, EventArgs e)
        {
            WPName wp = new WPName(true, UVO, WPTYPE.WPNAMELIST, false);

            wp.ShowDialog();
            if (wp.PickedID == 0)
            {
                return;
            }

            PickedProduct = ProductFactory.Create(wp.PickedID, wp.PickedType);
            textBox1.Text = PickedProduct.GetName();
        }
Пример #30
0
        public void ShouldCreateAProduct()
        {
            var product = _productFactory.Create(_productCsv);

            Assert.Equal(_productCsv.Key, product.Key);
            Assert.Equal(_productCsv.ArtikleCode, product.ArticleCode);
            Assert.Equal(_productCsv.ColorCode, product.ColorCode);
            Assert.Equal(_productCsv.Description, product.Description);
            Assert.Equal(_productCsv.Price, product.Price);
            Assert.Equal(_productCsv.DiscountPrice, product.DiscountPrice);
            Assert.Equal(_productCsv.DeliveredIn, product.DeliveredIn);
            Assert.Equal(_productCsv.Q1, product.Category);
            Assert.Equal(_productCsv.Size, product.Size);
            Assert.Equal(_productCsv.Color, product.Color);
        }