public void Initialize_IfItemIsValid_ShouldReturnFilledProduct() { // arrange var dbItem = this.InitializeBaseProductItem(); var builder = new TestBaseProductBuilder(this.CatalogContext, this.CatalogMapper); using (var db = new Db { dbItem }) { var productItem = db.GetItem(dbItem.ID); // act var product = builder.Initialize(productItem); // assert Assert.NotNull(product); Assert.Equal(product.Id, productItem.Name); Assert.Equal(product.ProductId, productItem["ProductId"]); Assert.Equal(product.SitecoreId, productItem["SitecoreId"]); Assert.Equal(product.DisplayName, productItem["DisplayName"]); Assert.Equal(product.Description, productItem["Description"]); Assert.Equal(product.Brand, productItem["Brand"]); Assert.Equal(product.Tags[0], productItem["Tags"]); Assert.Equal(product.CustomerAverageRating, decimal.Parse(productItem["Rating"])); Assert.Empty(product.ImageUrls); Assert.Equal(product.CatalogName, this.CatalogContext.CatalogName); } }
public void SetPrices_IfProductInvalid_ShouldNotThrowException(BaseProduct product) { // arrange var prices = this.Fixture.Create <Dictionary <string, Price> >(); var builder = new TestBaseProductBuilder(this.CatalogContext, this.CatalogMapper); // act var exception = Record.Exception(() => builder.SetPrices(product, prices)); // assert Assert.Null(exception); }
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 SetStockStatus_IfParametersNotNull_ShouldSetStockStatus() { // arrange var product = new TestBaseProduct(); var stockInformation = this.Fixture.Create <StockInformation>(); var stockStatus = this.Fixture.Create <StockStatus>(); this.CatalogMapper .Map <Sitecore.Commerce.Entities.Inventory.StockStatus, StockStatus>( Arg.Any <Sitecore.Commerce.Entities.Inventory.StockStatus>()) .Returns(stockStatus); var builder = new TestBaseProductBuilder(this.CatalogContext, this.CatalogMapper); // act builder.SetStockStatus(product, stockInformation); // assert this.CatalogMapper.Received(1) .Map <Sitecore.Commerce.Entities.Inventory.StockStatus, StockStatus>( Arg.Any <Sitecore.Commerce.Entities.Inventory.StockStatus>()); Assert.Equal(stockStatus, product.StockStatus); }
public void SetPrices_IfPriceExistInDictionary_ShouldSetPrices() { // arrange var price = this.Fixture.Create <CommercePrice>(); var product = this.Fixture.Build <TestBaseProduct>() .With(prod => prod.CurrencyCode, null) .With(prod => prod.AdjustedPrice, null) .With(prod => prod.ListPrice, null) .Create(); var prices = new Dictionary <string, Price> { { product.Id, price } }; var builder = new TestBaseProductBuilder(this.CatalogContext, this.CatalogMapper); // act builder.SetPrices(product, prices); // assert Assert.Equal(price.CurrencyCode, product.CurrencyCode); Assert.Equal(price.Amount, product.ListPrice); Assert.Equal(price.ListPrice, product.AdjustedPrice); }