/// <summary> /// Implementation of <see cref="IBrandCommands.CreateNewBrand(string, string, string, Image)"/> /// </summary> /// <param name="name">The brand's name</param> /// <param name="url">The brand's unique url</param> /// <param name="description">The brand's description</param> /// <param name="logo">The brand's logo</param> /// <returns>The brand id</returns> public virtual async Task <Guid> CreateNewBrand(string name, string url, string description, Image logo) { try { var brand = Brand.Create(name, url); if (!string.IsNullOrEmpty(description)) { brand.ChangeDescription(description); } if (logo != null) { brand.SetLogo(logo); } Repository.Add(brand); await Repository.SaveChangesAsync(); var @event = new BrandCreatedEvent(brand.Id, brand.Name); EventBus.RaiseEvent(@event); return(brand.Id); } catch { throw; } }
public async Task UpdateBrandInfo_Should_Update_Brand_With_Specified_Values() { var brand = Brand.Create("brand to edit", "brand-to-edit"); var repositoryMock = new Mock <Repository.IRepository>(); repositoryMock.Setup(r => r.GetByKeyAsync <Brand>(It.IsAny <Guid>())) .Returns(Task.FromResult(brand)); Repository.IRepository repository = repositoryMock.Object; Core.Infrastructure.IEventBus eventBus = new Mock <Core.Infrastructure.IEventBus>().Object; Guid brandId = brand.Id; string name = "brand"; string url = "url"; string description = "description"; Image logo = new Image { MimeType = "image/jpeg", Data = new byte[0] }; var commands = new BrandCommands(repository, eventBus); await commands.UpdateBrandInfo(brandId, name, url, description, logo); Assert.Equal(name, brand.Name); Assert.Equal(url, brand.Url); Assert.Equal(description, brand.Description); Assert.Equal(logo, brand.Logo); }
public void SetLogo_Should_Throw_ArgumentNullException_If_Logo_IsNull() { var brand = Brand.Create("brand", "brand"); var ex = Assert.Throws <ArgumentNullException>(() => brand.SetLogo(null)); Assert.Equal("logo", ex.ParamName); }
public void Restore_Should_Throw_InvalidOperationException_If_Brand_IsNotDeleted() { var brand = Brand.Create("brand", "brand"); var ex = Assert.Throws <InvalidOperationException>(() => brand.Restore()); Assert.Equal("The brand is not deleted", ex.Message); }
public void ChangeUrl_Should_Throw_ArgumentNullException_If_Url_IsEmpty(string value) { var brand = Brand.Create("brand", "brand"); var ex = Assert.Throws <ArgumentNullException>(() => brand.ChangeUrl(value)); Assert.Equal("url", ex.ParamName); }
public void Brand_created() { var brandId = new BrandId(SequentialGuid.NewSequentialGuid()); var sut = Brand.Create(brandId, "My brand"); Assert.NotNull(sut); Assert.Contains("My brand", sut.Name); }
public void Valid_brand_name(string name) { var sut = Brand.Create(Guid.NewGuid(), "test"); sut.UpdateBrandName(name); Assert.Equal(name, sut.Name); }
public void Invalid_brand_name(string name) { var sut = Brand.Create(Guid.NewGuid(), "test"); Action action = () => sut.UpdateBrandName(name); Assert.Throws <ArgumentException>(action.Invoke); }
public void Brand_name_cannot_be_null() { var sut = Brand.Create(Guid.NewGuid(), "test"); Action action = () => sut.UpdateBrandName(null); Assert.Throws <ArgumentNullException>(action.Invoke); }
public void ChangeDescription_Should_Clear_If_Description_IsEmpty(string value) { var brand = Brand.Create("brand", "brand"); brand.ChangeDescription(value); Assert.True(string.IsNullOrWhiteSpace(value)); }
private Brand GetBrandFromJObject(JObject brand) { return(Brand.Create (new BrandDto { Name = brand.Value <String>("BrandName") })); }
public void BrandFactory_Should_Throw_ArgumentNullException_If_Url_IsEmpty(string value) { var ex = Assert.Throws <ArgumentNullException>(() => Brand.Create( "My Brand", value )); Assert.Equal("url", ex.ParamName); }
public void Invalid_size_update() { var sut = Product.Create(new ProductId(SequentialGuid.NewSequentialGuid()), "Duff", Brand.Create(new BrandId(SequentialGuid.NewSequentialGuid()), "Duff"), ProductType.Create(Guid.NewGuid(), "product type"), Size.Create(Guid.NewGuid(), "your size")); Assert.Throws <ArgumentNullException>(() => sut.UpdateSize(null)); }
public void BrandFactory_Should_Throw_ArgumentNullException_If_Name_IsEmpty(string value) { var ex = Assert.Throws <ArgumentNullException>(() => Brand.Create( value, "my-brand" )); Assert.Equal("name", ex.ParamName); }
public void Delete_Should_Throw_InvalidOperationException_If_Brand_IsDeleted() { var brand = Brand.Create("brand", "brand"); brand.Delete(); var ex = Assert.Throws <InvalidOperationException>(() => brand.Delete()); Assert.Equal("The brand is already deleted", ex.Message); }
public void Product_created() { var productId = new ProductId(SequentialGuid.NewSequentialGuid()); var brandId = Brand.Create(new BrandId(SequentialGuid.NewSequentialGuid()), "Duff"); var productType = ProductType.Create(Guid.NewGuid(), "product type"); var size = Size.Create(Guid.NewGuid(), "your size"); var sut = Product.Create(productId, "Duff", brandId, productType, size); Assert.NotNull(sut); Assert.Contains("Duff", sut.Name); }
public void Valid_product_name(string name) { var sut = Product.Create(new ProductId(SequentialGuid.NewSequentialGuid()), "Duff", Brand.Create(new BrandId(SequentialGuid.NewSequentialGuid()), "Duff"), ProductType.Create(Guid.NewGuid(), "product type"), Size.Create(Guid.NewGuid(), "your size")); sut.UpdateProductName(name); Assert.Equal(name, sut.Name); }
public void Invalid_product_name(string name) { var sut = Product.Create(new ProductId(SequentialGuid.NewSequentialGuid()), "Duff", Brand.Create(new BrandId(SequentialGuid.NewSequentialGuid()), "Duff"), ProductType.Create(Guid.NewGuid(), "product type"), Size.Create(Guid.NewGuid(), "your size")); Action action = () => sut.UpdateProductName(name); Assert.Throws <ArgumentException>(action.Invoke); }
public void Product_name_cannot_be_null() { var sut = Product.Create(new ProductId(SequentialGuid.NewSequentialGuid()), "Duff", Brand.Create(new BrandId(SequentialGuid.NewSequentialGuid()), "Duff"), ProductType.Create(Guid.NewGuid(), "product type"), Size.Create(Guid.NewGuid(), "your size")); Action action = () => sut.UpdateProductName(null); Assert.Throws <ArgumentNullException>(action.Invoke); }
public void ThatBrandWithoutNameThrowsException() { try { Brand.Create(new BrandDto()); Assert.Fail(); } catch (Exception e) { Assert.IsNotInstanceOfType(e, typeof(AssertFailedException)); } }
public void Valid_product_type_update() { var sut = Product.Create(new ProductId(SequentialGuid.NewSequentialGuid()), "Duff", Brand.Create(new BrandId(SequentialGuid.NewSequentialGuid()), "Duff"), ProductType.Create(Guid.NewGuid(), "product type"), Size.Create(Guid.NewGuid(), "your size")); var newProductType = ProductType.Create(new ProductTypeId(SequentialGuid.NewSequentialGuid()), "Duff IPA"); sut.UpdateProductType(newProductType); Assert.Equal("Duff IPA", sut.ProductType.Name); }
public void Valid_size_update() { var sut = Product.Create(new ProductId(SequentialGuid.NewSequentialGuid()), "Duff", Brand.Create(new BrandId(SequentialGuid.NewSequentialGuid()), "Duff"), ProductType.Create(Guid.NewGuid(), "product type"), Size.Create(Guid.NewGuid(), "your size")); var newSize = Size.Create(new SizeId(SequentialGuid.NewSequentialGuid()), "0.33"); sut.UpdateSize(newSize); Assert.Equal("0.33", sut.Size.Amount); }
public void Valid_brand_update() { var sut = Product.Create(new ProductId(SequentialGuid.NewSequentialGuid()), "Duff", Brand.Create(new BrandId(SequentialGuid.NewSequentialGuid()), "Duff"), ProductType.Create(Guid.NewGuid(), "product type"), Size.Create(Guid.NewGuid(), "your size")); var newBrand = Brand.Create(new BrandId(SequentialGuid.NewSequentialGuid()), "DuffZ"); sut.UpdateBrand(newBrand); Assert.Equal("DuffZ", sut.Brand.Name); }
public void Has_product() { var price = new Price(1.00m); var brand = Brand.Create(Guid.NewGuid(), "test"); var productType = ProductType.Create(Guid.NewGuid(), "product type"); var size = Size.Create(Guid.NewGuid(), "your size"); var prodId = new ProductId(SequentialGuid.NewSequentialGuid()); var product = Product.Create(prodId, "newProd", brand, productType, size); var sut = LineItemBuilder.LineItem(price).WithProduct(product).Build(); Assert.Contains("newProd", sut.Product.Name); }
public async Task Valid_Id_Returns_Brand() { var id = Guid.NewGuid(); var brand = Brand.Create(id, "test"); var mockBrandService = new Mock <IBrandService>(); mockBrandService.Setup(s => s.GetBrandAsync(id)) .Returns(() => Task.FromResult(brand)); var brandController = new BrandController(mockBrandService.Object); var result = await brandController.GetBrand(id); mockBrandService.Verify(mock => mock.GetBrandAsync(id), Times.Once()); Assert.NotNull(result); }
public void Has_notes() { var brand = Brand.Create(Guid.NewGuid(), "brand"); var productType = ProductType.Create(Guid.NewGuid(), "product type"); var size = Size.Create(Guid.NewGuid(), "your size"); var product = Product.Create(Guid.NewGuid(), "product", brand, productType, size); var price = new Price(1.00m); var sut = LineItemBuilder.LineItem(price) .WithNotes("No kun sai niin halvalla.") .WithProduct(product) .Build(); Assert.Contains("halvalla", sut.Notes); }
public void Active_Should_Return_Only_Brands_Not_Deleted() { var brand1 = Brand.Create("b1", "b1"); var brand2 = Brand.Create("b2", "b2"); var brand3 = Brand.Create("b3", "b3"); brand3.Delete(); IQueryable <Brand> brands = new Brand[] { brand1, brand2, brand3 }.AsQueryable(); var activeBrands = BrandExtensions.Active(brands).ToArray(); Assert.True(activeBrands.All(b => !b.Deleted)); }
public async Task DeleteBrand_Should_Mark_Brand_As_Deleted() { var brand = Brand.Create("brand to edit", "brand-to-edit"); var repositoryMock = new Mock <Repository.IRepository>(); repositoryMock.Setup(r => r.GetByKeyAsync <Brand>(It.IsAny <Guid>())) .Returns(Task.FromResult(brand)); Repository.IRepository repository = repositoryMock.Object; Core.Infrastructure.IEventBus eventBus = new Mock <Core.Infrastructure.IEventBus>().Object; Guid brandId = brand.Id; var commands = new BrandCommands(repository, eventBus); await commands.DeleteBrand(brandId); Assert.True(brand.Deleted); }
public void Total_sum_of_line_items() { var sut = CreatePurchaseTransaction(); var brand = Brand.Create(Guid.NewGuid(), "brand"); var productType = ProductType.Create(Guid.NewGuid(), "product type"); var size = Size.Create(Guid.NewGuid(), "your size"); var product = Product.Create(Guid.NewGuid(), "prod", brand, productType, size); for (int i = 1; i < 6; i++) { var lineItem = LineItemBuilder.LineItem(new Price(1.0m * i)) .WithProduct(product) .Build(); sut.UpdateLineItem(lineItem); } Assert.Contains("15.0", sut.TotalPrice); }
public void ByVendor_Should_Return_Only_Products_With_The_Specified_Vendor() { var vendor = Brand.Create("brand", "brand"); var p1 = Product.Create("ean", "sku", "name", "url"); var p2 = Product.Create("ean", "sku", "name", "url"); var p3 = Product.Create("ean", "sku", "name", "url"); p1.SetVendor(vendor); p2.SetVendor(vendor); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); Guid vendorId = vendor.Id; var productsByVendor = ProductExtensions.ByVendor(products, vendorId).ToArray(); Assert.True(productsByVendor.All(p => p.Vendor != null && p.Vendor.Id == vendorId)); }