Ejemplo n.º 1
0
        public async Task <IActionResult> PutStockInformation(int id, StockInformation stockInformation)
        {
            if (id != stockInformation.StockId)
            {
                return(BadRequest());
            }

            _context.Entry(stockInformation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StockInformationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public void ShouldReturnOnlyOneStockInformationIfDuplicatedProductIdsPassed()
        {
            // Arrange
            var stockInfo = new StockInformation {
                Product = new InventoryProduct {
                    ProductId = "1001"
                }, Status = StockStatus.InStock, AvailabilityDate = new DateTime(2014, 3, 12)
            };
            var invProduct1 = new InventoryProduct {
                ProductId = "1001"
            };

            this._serviceProvider
            .GetStockInformation(Arg.Is <GetStockInformationRequest>(r => r.Shop.Name == "shopname" && r.Products.Contains(invProduct1) && r.Products.Count() == 1 && r.DetailsLevel == StockDetailsLevel.All))
            .ReturnsForAnyArgs(new GetStockInformationResult {
                StockInformation = new List <StockInformation> {
                    stockInfo
                }
            });

            // Act
            var stockInfos = this._inventoryService.GetStockInformation("shopname", new List <string> {
                "1001", "1001"
            }, StockDetailsLevel.All, string.Empty, string.Empty);

            // Assert
            stockInfos.Count.Should().Be(1);
            stockInfos.FirstOrDefault().ShouldBeEquivalentTo(stockInfo);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <StockInformation> > PostStockInformation(StockInformation stockInformation)
        {
            _context.StockInformation.Add(stockInformation);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetStockInformation", new { id = stockInformation.StockId }, stockInformation));
        }
        public void ShouldGetStockInformation()
        {
            // Arrange
            var stockInfo1 = new StockInformation {
                Product = new InventoryProduct {
                    ProductId = "1001"
                }, Status = StockStatus.InStock, AvailabilityDate = new DateTime(2014, 3, 12)
            };
            var stockInfo2 = new StockInformation {
                Product = new InventoryProduct {
                    ProductId = "1002"
                }, Status = StockStatus.InStock, AvailabilityDate = new DateTime(2014, 3, 12)
            };
            var stockInfos = new List <StockInformation> {
                stockInfo1, stockInfo2
            };
            var products = new List <string> {
                "1001", "1002"
            };

            this._serviceProvider
            .GetStockInformation(Arg.Is <GetStockInformationRequest>(r => r.Shop.Name == "shopname" && r.Products.First().ProductId == "1001" && r.Products.Last().ProductId == "1002" && r.Products.Count() == 2 && r.DetailsLevel == StockDetailsLevel.All))
            .Returns(new GetStockInformationResult {
                StockInformation = stockInfos
            });

            // Act & Assert
            this._inventoryService.GetStockInformation("shopname", products, StockDetailsLevel.All, string.Empty, string.Empty).ShouldBeEquivalentTo(stockInfos);
        }
        /// <summary>
        /// Gets the product model.
        /// </summary>
        /// <param name="productItem">The product item.</param>
        /// <param name="price">The product price.</param>
        /// <param name="stockInformation">The stock information.</param>
        /// <param name="orderableInformation">The pre-orderable information.</param>
        /// <returns>The product model.</returns>
        private ProductModel GetProductModel(Item productItem, decimal price, StockInformation stockInformation, OrderableInformation orderableInformation)
        {
            ISitecoreService glassMapper = GlassMapperService.Current;

            var productModel = glassMapper.CreateClass <ProductModel, decimal, StockInformation, OrderableInformation>(false, false, productItem, price, stockInformation, orderableInformation);

            return(productModel.SetProductResource(this.productService, productItem));
        }
 private Product(string name, string categoryId, string partitionKey, double price, StockInformation stock)
 {
     Name         = name;
     CategoryId   = categoryId;
     PartitionKey = partitionKey;
     Price        = price;
     Stock        = stock;
 }
 public Product(string name, string categoryId, double price, StockInformation stock)
 {
     Name         = name;
     CategoryId   = categoryId;
     Stock        = stock;
     Price        = price;
     PartitionKey = categoryId;
 }
        /// <summary>
        /// Gets the product back-orderable information.
        /// </summary>
        /// <param name="shopName">The shop name.</param>
        /// <param name="stockInformation">The product stock information.</param>
        /// <param name="location">The location.</param>
        public void VisitedProductStockStatus(string shopName, StockInformation stockInformation, string location)
        {
            var request = new VisitedProductStockStatusRequest(shopName, stockInformation)
            {
                Location = location
            };

            this._serviceProvider.VisitedProductStockStatus(request);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets stock status to product
        /// </summary>
        /// <param name="product">Product to set stock status</param>
        /// <param name="stockInformation">Stock information</param>
        protected void SetStockStatus(BaseProduct product, StockInformation stockInformation)
        {
            if (stockInformation == null || product == null)
            {
                return;
            }

            product.StockStatus =
                this.CatalogMapper.Map <StockStatus, Models.Catalog.StockStatus>(stockInformation.Status);
        }
Ejemplo n.º 10
0
 internal Instance()
 {
     Observer               = new SimulationObserver(this);
     StockInfo              = new StockInformation(this);
     MetaInfoManager        = new MetaInformationManager(this);
     FrequencyTracker       = new FrequencyTracker(this);
     ElementMetaInfoTracker = new ElementMetaInfoTracker(this);
     BotCrashHandler        = new BotCrashHandler(this);
     SharedControlElements  = new SharedControlElementsContainer(this);
 }
Ejemplo n.º 11
0
        public void Ctor_Symbol_InvalidExceptionRaised()
        {
            // Testing an invalid symbol non alphanumeric
            // Arrange
            string symbol = "N_T";

            // Act
            StockInformation stockInformation = new StockInformation(10, "ValidPassword", symbol);

            // Assert
            // Expecting an exception raised, done in tags
        }
Ejemplo n.º 12
0
        public void Ctor_WS_InvalidInfo()
        {
            // Testing valid symbol but doesn't exist in web service so exception raised
            // Arrange
            string symbol = "AAAA";

            // Act
            StockInformation stockInformation = new StockInformation(9999, "ValidPassword", symbol);

            // Assert
            // Exception should be raised
        }
Ejemplo n.º 13
0
        public void Ctor_BasicInput()
        {
            // Tests basic constructor inpu
            // Arrange

            // Act
            StockInformation stockInformation = new StockInformation(1111, "ValidPassword", "AAA");

            // Assert
            // If built successfully no exception raised
            Assert.IsTrue(true);
        }
Ejemplo n.º 14
0
        public void Ctor_Symbol_ValidNoException()
        {
            // Testing constructor userID being over the limit of 9999
            // Arrange
            string symbol = "AAA";

            // Act
            StockInformation stockInformation = new StockInformation(9999, "ValidPassword", symbol);

            // Assert
            // No exception raised so:
            Assert.IsTrue(true);
        }
        public void SetStockStatus_IfParameterIsNull_ShouldNotThrowException(
            BaseProduct product,
            StockInformation stockInformation)
        {
            // arrange
            var builder = new TestBaseProductBuilder(this.CatalogContext, this.CatalogMapper);

            // act
            var exception = Record.Exception(() => builder.SetStockStatus(product, stockInformation));

            // assert
            Assert.Null(exception);
        }
        public void ShouldGetProductByIdBackOrderable()
        {
            // Arrange
            var stockInfo = new StockInformation {
                Product = new InventoryProduct {
                    ProductId = "1001"
                }, Status = StockStatus.BackOrderable, AvailabilityDate = new DateTime(2014, 3, 12)
            };
            var orderableInfo = new OrderableInformation {
                Product = new InventoryProduct {
                    ProductId = "1001"
                }, Status = StockStatus.BackOrderable, InStockDate = new DateTime(2014, 3, 12)
            };

            using (new SiteContextSwitcher(new TSiteContext("shopname")))
            {
                using (var tree = new TTree {
                    new TItem("T-800", new NameValueCollection {
                        { "ExternalID", "1001" }
                    })
                })
                {
                    Item productItem = tree.Database.GetItem("/sitecore/content/home/T-800");
                    this.productService.ReadProduct("1001").Returns(productItem);
                    this.pricingService.GetProductPrice("1001").Returns(5000);
                    this._inventoryService
                    .GetStockInformation("shopname", Arg.Is <IEnumerable <string> >(ids => ids.Contains("1001") && ids.Count() == 1), StockDetailsLevel.All, string.Empty, string.Empty)
                    .Returns(new List <StockInformation> {
                        stockInfo
                    });
                    this._inventoryService
                    .GetBackOrderableInformation("shopname", Arg.Is <IEnumerable <string> >(ids => ids.Contains("1001") && ids.Count() == 1), string.Empty, string.Empty)
                    .Returns(new List <OrderableInformation> {
                        orderableInfo
                    });

                    GlassMapperService.Current.CreateClass <ProductModel, decimal, StockInformation, OrderableInformation>(false, false, Arg.Is <Item>(item => item.ID == productItem.ID), 5000, stockInfo, orderableInfo)
                    .Returns(new ProductModel(5000, stockInfo, orderableInfo));

                    // Act
                    var result = this.controller.Index("1001");

                    // Assert
                    var productModel = (ProductModel)((ViewResult)result).Model;
                    productModel.Price.Should().Be(5000);
                    productModel.Status.Should().Be(StockStatus.BackOrderable);
                    productModel.AvailabilityDate.Should().Be(new DateTime(2014, 3, 12));
                    productModel.InStockDate.Should().Be(new DateTime(2014, 3, 12));
                }
            }
        }
Ejemplo n.º 17
0
        public void Ctor_Symbol_Exists_NumberOutstanding()
        {
            // Testing valid symbol, exists in the web service so company name should be set
            // Arrange
            string symbol = "AAA";
            int    expectedNumOutstanding = 50;
            int    actualNumOutstanding;

            // Act
            StockInformation stockInformation = new StockInformation(9999, "ValidPassword", symbol);

            actualNumOutstanding = stockInformation.NumberOfSharesOutstanding;

            // Assert
            Assert.AreEqual(expectedNumOutstanding, actualNumOutstanding);
        }
Ejemplo n.º 18
0
        public void Ctor_Symbol_Exists_CurrentPrice()
        {
            // Testing valid symbol, exists in the web service so company name should be set
            // Arrange
            string symbol = "AAA";
            int    expectedCurrentPrice = 100;
            int    actualCurrentPrice;

            // Act
            StockInformation stockInformation = new StockInformation(9999, "ValidPassword", symbol);

            actualCurrentPrice = stockInformation.CurrentPrice;

            // Assert
            Assert.AreEqual(expectedCurrentPrice, actualCurrentPrice);
        }
Ejemplo n.º 19
0
        public void Ctor_Symbol_Exists_CompanyName()
        {
            // Testing valid symbol, exists in the web service so company name should be set
            // Arrange
            string symbol = "AAA";
            string expectedCompanyName = "A Company";
            string actualCompanyName;

            // Act
            StockInformation stockInformation = new StockInformation(9999, "ValidPassword", symbol);

            actualCompanyName = stockInformation.CompanyName;

            // Assert
            Assert.AreEqual(expectedCompanyName, actualCompanyName);
        }
Ejemplo n.º 20
0
        public void Ctor_Exists_NotKnown()
        {
            // Testing valid symbol, exists in the web service so company name should be set
            // Arrange
            string symbol        = "AAA_A";
            bool   expectedExist = false;
            bool   actualExist;

            // Act
            StockInformation stockInformation = new StockInformation(9999, "ValidPassword", symbol);

            actualExist = stockInformation.Exists;

            // Assert
            Assert.AreEqual(expectedExist, actualExist);
        }
Ejemplo n.º 21
0
        public void ToString_Valid()
        {
            // Testing valid symbol, exists in the web service so company name should be set
            // Arrange
            string symbol         = "AAA";
            string expectedString = "A Company [AAA] 100";
            string actualString;

            // Act
            StockInformation stockInformation = new StockInformation(9999, "ValidPassword", symbol);

            actualString = stockInformation.ToString();

            // Assert
            Assert.AreEqual(expectedString, actualString);
        }
Ejemplo n.º 22
0
        public void Ctor_UserID_Valid()
        {
            // Testing constructor userID being under the limit of 9999
            // Arrange
            int    userID = 1111;
            string expectedCompanyName = "A Company";
            string actualCompanyName;

            // Act
            StockInformation stockInformation = new StockInformation(userID, "ValidPassword", "AAA");

            actualCompanyName = stockInformation.CompanyName;

            // Assert
            Assert.AreEqual(expectedCompanyName, actualCompanyName);
        }
Ejemplo n.º 23
0
        public void Ctor_Available_NoInfo()
        {
            // Testing valid symbol, exists in the web service so company name should be set
            // Arrange
            string symbol            = "AAAA";
            bool   expectedAvailable = false;
            bool   actualAvailavle;

            // Act
            StockInformation stockInformation = new StockInformation(9999, "ValidPassword", symbol);

            actualAvailavle = stockInformation.Available;

            // Assert
            Assert.AreEqual(expectedAvailable, actualAvailavle);
        }
Ejemplo n.º 24
0
        public void Ctor_Password_Valid()
        {
            // Testing a valid password over or equal 8 char
            // Arrange
            string password            = "******";
            string expectedCompanyName = "A Company";
            string actualCompanyName;

            // Act
            StockInformation stockInformation = new StockInformation(1111, password, "AAA");

            actualCompanyName = stockInformation.CompanyName;

            // Assert
            Assert.AreEqual(expectedCompanyName, actualCompanyName);
        }
Ejemplo n.º 25
0
        public void Ctor_Password_Under8Char()
        {
            // Testing constructor password being under 8 char
            // Arrange
            string password            = "******";
            string expectedCompanyName = "Not allowed";
            string actualCompanyName;

            // Act
            StockInformation stockInformation = new StockInformation(10, password, "AAA");

            actualCompanyName = stockInformation.CompanyName;

            // Assert
            Assert.AreEqual(expectedCompanyName, actualCompanyName);
        }
Ejemplo n.º 26
0
        public void Ctor_UserIDPassword_Invalid()
        {
            // Testing a valid password over or equal 8 char
            // Arrange
            int    userID              = 1111;
            string password            = "******";
            string expectedCompanyName = "Not allowed";
            string actualCompanyName;

            // Act
            StockInformation stockInformation = new StockInformation(userID, password, "AAA");

            actualCompanyName = stockInformation.CompanyName;

            // Assert
            Assert.AreEqual(expectedCompanyName, actualCompanyName);
        }
Ejemplo n.º 27
0
        public void Ctor_Symbol_Exists_MarketCapitalisation()
        {
            // Testing valid symbol, exists in the web service so company name should be set
            // Arrange
            string symbol = "AAA";
            int    actualMarketCap;
            int    expectedMarketCap;

            // Act
            StockInformation stockInformation = new StockInformation(9999, "ValidPassword", symbol);

            actualMarketCap   = stockInformation.MarketCapitilisationInMillions;
            expectedMarketCap = stockInformation.CurrentPrice * stockInformation.NumberOfSharesOutstanding;

            // Assert
            Assert.AreEqual(expectedMarketCap, actualMarketCap);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Initializes the specified stock infos.
        /// </summary>
        /// <param name="stockInfo">The stock information.</param>
        public virtual void Initialize(StockInformation stockInfo)
        {
            Assert.ArgumentNotNull(stockInfo, "stockInfo");

            if (stockInfo == null || stockInfo.Status == null)
            {
                return;
            }

            this.ProductId = stockInfo.Product.ProductId;
            this.VariantId = string.IsNullOrEmpty(((CommerceInventoryProduct)stockInfo.Product).VariantId) ? string.Empty : ((CommerceInventoryProduct)stockInfo.Product).VariantId;
            this.Status    = StorefrontManager.GetProductStockStatusName(stockInfo.Status);
            this.Count     = stockInfo.Count < 0 ? 0 : stockInfo.Count;
            if (stockInfo.AvailabilityDate != null & stockInfo.AvailabilityDate.HasValue)
            {
                this.AvailabilityDate = stockInfo.AvailabilityDate.Value.ToDisplayedDate();
            }
        }
        public void Initialize(StockInformation stockInfo)
        {
            Assert.ArgumentNotNull(stockInfo, nameof(stockInfo));

            if (stockInfo == null || stockInfo.Status == null)
            {
                return;
            }

            ProductId = stockInfo.Product.ProductId;
            VariantId = string.IsNullOrEmpty(((CommerceInventoryProduct)stockInfo.Product).VariantId) ? string.Empty : ((CommerceInventoryProduct)stockInfo.Product).VariantId;
            Status    = InventoryManager.GetStockStatusName(stockInfo.Status);
            Count     = stockInfo.Count < 0 ? 0 : stockInfo.Count;
            CanShowSignupForNotification = Context.User.IsAuthenticated;
            if ((stockInfo.AvailabilityDate != null) & stockInfo.AvailabilityDate.HasValue)
            {
                AvailabilityDate = stockInfo.AvailabilityDate.Value.ToDisplayedDate();
            }
        }
Ejemplo n.º 30
0
        public ICollection <StockInformation> GetStockInformationByOrderID(int orderId)
        {
            var balance = new Balance();
            var stockInformationTable = balance.GetBalanceByOrder(orderId, CurrentContext.UserId);
            ICollection <StockInformation> stockInformations = new Collection <StockInformation>();

            foreach (DataRowView stockInformationRow in stockInformationTable)
            {
                var itemID = Convert.ToInt32(stockInformationRow["ItemID"]);
                var unitID = Convert.ToInt32(stockInformationRow["UnitID"]);

                var stockInformation = new StockInformation
                {
                    Item         = _itemRepository.FindSingle(Convert.ToInt32(itemID)),
                    Unit         = _unitOfIssueRepository.FindSingle(Convert.ToInt32(unitID)),
                    Manufacturer =
                        DBNull.Value != stockInformationRow["ManufacturerId"]
                                                       ? _manufacturerRepository.FindSingle(
                            Convert.ToInt32(stockInformationRow["ManufacturerId"]))
                                                       : null,
                    Activity =
                        _activityRepository.FindSingle(
                            Convert.ToInt32(stockInformationRow["ActivityID"]),
                            Convert.ToBoolean(stockInformationRow["DeliveryNote"])),
                    ExpiryDate =
                        DBNull.Value != stockInformationRow["ExpiryDate"]
                                                       ? Convert.ToDateTime(stockInformationRow["ExpiryDate"])
                                                       : (DateTime?)null,
                    PhysicalStore =
                        DBNull.Value != stockInformationRow["PhysicalStoreID"]
                                                       ? _physicalStoreRepository.FindSingle(
                            Convert.ToInt32(stockInformationRow["PhysicalStoreID"]))
                                                       : null,
                    Quantity = Convert.ToDecimal(stockInformationRow["Usable"])
                };
                stockInformations.Add(stockInformation);
            }
            return(stockInformations);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Visiteds the product stock status.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="stockInformation">The stock information.</param>
        /// <param name="location">The location.</param>
        /// <returns>The manager response which returns success flag in the Result.</returns>
        public virtual ManagerResponse<VisitedProductStockStatusResult, bool> VisitedProductStockStatus([NotNull] CommerceStorefront storefront, StockInformation stockInformation, string location)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(stockInformation, "stockInformation");

            var request = new VisitedProductStockStatusRequest(storefront.ShopName, stockInformation) { Location = location };
            var result = this.InventoryServiceProvider.VisitedProductStockStatus(request);

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return new ManagerResponse<VisitedProductStockStatusResult, bool>(result, result.Success);
        }
        /// <summary>
        /// Initializes the specified stock infos.
        /// </summary>
        /// <param name="stockInfo">The stock information.</param>
        public virtual void Initialize(StockInformation stockInfo)
        {
            Assert.ArgumentNotNull(stockInfo, "stockInfo");

            if (stockInfo == null || stockInfo.Status == null)
            {
                return;
            }

            this.ProductId = stockInfo.Product.ProductId;
            this.VariantId = string.IsNullOrEmpty(((CommerceInventoryProduct)stockInfo.Product).VariantId) ? string.Empty : ((CommerceInventoryProduct)stockInfo.Product).VariantId;
            this.Status = StorefrontManager.GetProductStockStatusName(stockInfo.Status);
            this.Count = stockInfo.Count < 0 ? 0 : stockInfo.Count;
            if (stockInfo.AvailabilityDate != null & stockInfo.AvailabilityDate.HasValue)
            {
                this.AvailabilityDate = stockInfo.AvailabilityDate.Value.ToDisplayedDate();
            }
        }