public async Task GetCatalogDetail_With_Empty_CatalogId_ShouldBe_Invalid(int pageIndex, int pageSize) { var request = new GetCatalogDetailRequest { CatalogId = IdentityFactory.Create <CatalogId>(Guid.Empty), SearchCatalogCategoryRequest = new GetCatalogDetailRequest.CatalogCategorySearchRequest { PageIndex = pageIndex, PageSize = pageSize } }; await this._testFixture.ExecuteValidationTest(request, result => { result.ShouldHaveValidationErrorFor(x => x.CatalogId); if (pageIndex < 0 || pageIndex == int.MaxValue) { result.ShouldHaveValidationErrorFor(x => x.SearchCatalogCategoryRequest.PageIndex); } if (pageSize < 0 || pageSize == int.MaxValue) { result.ShouldHaveValidationErrorFor(x => x.SearchCatalogCategoryRequest.PageSize); } }); }
public async Task Remove_CatalogCategory_Successfully() { var catalog = Catalog.Create(this.Fixture.Create <string>()); var catalogs = new List <Catalog> { catalog }; this._mockDbContext .Setup(x => x.Set <Catalog>()) .ReturnsDbSet(catalogs); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this.Fixture.Create <string>()); var command = new RemoveCatalogCategoryCommand { CatalogId = catalog.CatalogId, CatalogCategoryId = catalogCategory.CatalogCategoryId }; IRequestHandler <RemoveCatalogCategoryCommand> handler = new CommandHandler(this.MockRepositoryFactory.Object, this._validator); await handler.Handle(command, this.CancellationToken); this._mockDbContext.Verify(x => x.Update(catalog), Times.Once); }
public override TIdentity Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return(IdentityFactory.Create <TIdentity>(reader.GetGuid())); }
private Product(string productCode, string productName) : this(IdentityFactory.Create <ProductId>(), productCode, productName) { this.AddUncommittedEvent(new ProductCreated { ProductId = this.Id, ProductCode = this.Code }); }
public void CatalogCategory_Change_DisplayName_ToEmpty_ShouldThrowException(string creationName) { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, creationName); Should.Throw <DomainException>(() => catalogCategory.ChangeDisplayName(string.Empty)); }
public void Create_CatalogProduct_With_Null_Of_ProductId_ShouldThrowException() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); Should.Throw <DomainException>(() => catalogCategory.CreateCatalogProduct(null, this._fixture.Create <string>())); }
public void Catalog_Create_Chain_Of_CatalogCategories_Successfully() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryIdLv1 = IdentityFactory.Create <CategoryId>(); var categoryIdLv2 = IdentityFactory.Create <CategoryId>(); var categoryIdLv3 = IdentityFactory.Create <CategoryId>(); var catalogCategoryLv1 = catalog.AddCategory(categoryIdLv1, this._fixture.Create <string>()); var catalogCategoryLv2 = catalog.AddCategory(categoryIdLv2, this._fixture.Create <string>(), catalogCategoryLv1); var catalogCategoryLv3 = catalog.AddCategory(categoryIdLv3, this._fixture.Create <string>(), catalogCategoryLv2); var catalogCategories = new List <CatalogCategory> { catalogCategoryLv1, catalogCategoryLv2, catalogCategoryLv3 }; catalog .Categories .Except(catalogCategories) .Any() .ShouldBeFalse(); var roots = catalog.FindCatalogCategoryRoots(); roots.ShouldHaveSingleItem(); var descendantsOfLv1 = catalog.GetDescendantsOfCatalogCategory(catalogCategoryLv1); descendantsOfLv1 .Except(catalogCategories) .Any() .ShouldBeFalse(); var descendantsOfLv2 = catalog.GetDescendantsOfCatalogCategory(catalogCategoryLv2); descendantsOfLv2 .Except(catalogCategories.Where(x => x != catalogCategoryLv1)) .Any() .ShouldBeFalse(); var descendantsOfLv3 = catalog.GetDescendantsOfCatalogCategory(catalogCategoryLv3); descendantsOfLv3 .Except(catalogCategories.Where(x => x != catalogCategoryLv1 && x != catalogCategoryLv2)) .Any() .ShouldBeFalse(); }
public void Remove_Null_Of_CatalogProduct_ShouldThrowException() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var catalogProduct = catalogCategory.Products.FirstOrDefault(); Should.Throw <DomainException>(() => catalogCategory.RemoveCatalogProduct(catalogProduct)); }
public void Create_CatalogProduct_Without_DisplayName_ShouldThrowException() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var productId = IdentityFactory.Create <ProductId>(); Should.Throw <DomainException>(() => catalogCategory.CreateCatalogProduct(productId, string.Empty)); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var stringValue = value as string; if (!string.IsNullOrEmpty(stringValue) && Guid.TryParse(stringValue, out var guid)) { return(IdentityFactory.Create <TIdentity>(guid)); } return(base.ConvertFrom(context, culture, value)); }
public void CatalogCategory_Change_DisplayName_Successfully(string creationName, string changeToName) { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog .AddCategory(categoryId, creationName) .ChangeDisplayName(changeToName); catalogCategory.DisplayName.ShouldBe(changeToName); }
public void Remove_CatalogProduct_Successfully() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var productId = IdentityFactory.Create <ProductId>(); var catalogProduct = catalogCategory.CreateCatalogProduct(productId, this._fixture.Create <string>()); catalogCategory.RemoveCatalogProduct(catalogProduct); catalogCategory.Products.ShouldBeEmpty(); }
public void Catalog_NotFound_ShouldBeInvalid() { var command = new RemoveCatalogCategoryCommand { CatalogId = (CatalogId)Guid.Empty, CatalogCategoryId = IdentityFactory.Create <CatalogCategoryId>() }; var result = this._validator.TestValidate(command); result.ShouldHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogCategoryId); }
private CatalogProduct InitCatalogProduct(string creationName) { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var productId = IdentityFactory.Create <ProductId>(); var catalogProduct = catalogCategory .CreateCatalogProduct(productId, creationName); return(catalogProduct); }
public void Create_CatalogProduct_Successfully() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var productId = IdentityFactory.Create <ProductId>(); var catalogProduct = catalogCategory.CreateCatalogProduct(productId, this._fixture.Create <string>()); catalogCategory.Products.ShouldContain(catalogProduct); catalogProduct.ShouldNotBeNull(); catalogProduct.CatalogCategory.ShouldBe(catalogCategory); }
public void Command_With_NotFound_Catalog_ShouldBeInvalid() { var command = new CreateCatalogCategoryCommand { CatalogId = IdentityFactory.Create <CatalogId>(), CategoryId = this._category.CategoryId, DisplayName = this._category.DisplayName }; var result = this._validator.TestValidate(command); result.ShouldHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.CategoryId); result.ShouldNotHaveValidationErrorFor(x => x.DisplayName); }
public void CatalogProduct_NotFound_ShouldBe_Invalid() { var command = new RemoveCatalogProductCommand { CatalogId = this._catalog.CatalogId, CatalogCategoryId = this._catalogCategory.CatalogCategoryId, CatalogProductId = IdentityFactory.Create <CatalogProductId>() }; var result = this._validator.TestValidate(command); result.ShouldHaveValidationErrorFor(x => x.CatalogProductId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogCategoryId); }
public async Task Should_Throw_ValidationException_When_Request_Is_Invalid(int pageIndex, int pageSize) { var request = new GetCatalogDetailRequest { CatalogId = IdentityFactory.Create <CatalogId>(Guid.Empty), SearchCatalogCategoryRequest = new GetCatalogDetailRequest.CatalogCategorySearchRequest { PageIndex = pageIndex, PageSize = pageSize } }; await Should.ThrowAsync <ValidationException>(async() => await this._testFixture.ExecuteTestRequestHandler <GetCatalogDetailRequest, GetCatalogDetailResult>(request, result => {})); }
public void Not_Found_Catalog_ShouldBeInvalid() { var command = new UpdateCatalogCategoryCommand { CatalogId = IdentityFactory.Create <CatalogId>(), CatalogCategoryId = IdentityFactory.Create <CatalogCategoryId>(), DisplayName = this.Fixture.Create <string>() }; var result = this._validator.TestValidate(command); result.ShouldHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogCategoryId); result.ShouldNotHaveValidationErrorFor(x => x.DisplayName); }
public async Task Should_GetCatalogDetail_Successfully_Even_NotFound_Catalog() { var request = new GetCatalogDetailRequest { CatalogId = IdentityFactory.Create <CatalogId>() }; await this._testFixture.ExecuteTestRequestHandler <GetCatalogDetailRequest, GetCatalogDetailResult>(request, result => { result.ShouldNotBeNull(); result.TotalOfCatalogCategories.ShouldBe(0); result.CatalogDetail.ShouldNotBeNull(); result.CatalogDetail.Id.ShouldBeNull(); result.CatalogDetail.DisplayName.ShouldBeNull(); result.CatalogCategories.ShouldBeNull(); }); }
public void Command_With_Invalid_ParentCatalogCategoryId_ShouldBeInvalid() { var command = new CreateCatalogCategoryCommand { CatalogId = this._catalog.CatalogId, CategoryId = this._category.CategoryId, DisplayName = this.Fixture.Create <string>(), ParentCatalogCategoryId = IdentityFactory.Create <CatalogCategoryId>() }; var result = this._validator.TestValidate(command); result.ShouldNotHaveValidationErrorFor(x => x.CategoryId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.DisplayName); result.ShouldHaveValidationErrorFor(x => x.ParentCatalogCategoryId); }
public async Task Update_NotFound_Category_ShouldThrowException() { var command = new UpdateCategoryCommand { CategoryId = IdentityFactory.Create <CategoryId>(), CategoryName = this.Fixture.Create <string>() }; this.MockRepository .Setup(x => x.FindOneAsync(It.IsAny <Expression <Func <Category, bool> > >())) .ReturnsAsync((Category)null); IRequestHandler <UpdateCategoryCommand> handler = new CommandHandler(this.MockRepositoryFactory.Object, this._validator); await Should.ThrowAsync <ValidationException>(async() => await handler.Handle(command, this.CancellationToken)); }
public void Product_NotFound_ShouldBe_Invalid() { var command = new CreateCatalogProductCommand { CatalogId = this._catalog.CatalogId, CatalogCategoryId = this._catalogCategory.CatalogCategoryId, ProductId = IdentityFactory.Create <ProductId>(), DisplayName = this._product.Name }; var result = this._validator.TestValidate(command); result.ShouldHaveValidationErrorFor(x => x.ProductId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogCategoryId); result.ShouldNotHaveValidationErrorFor(x => x.DisplayName); }
public async Task GetCatalogProductDetail_NotFound_CatalogProduct_Still_Work_Correctly() { var request = new GetCatalogProductDetailRequest { CatalogProductId = IdentityFactory.Create <CatalogProductId>() }; await this._testFixture.ExecuteTestRequestHandler <GetCatalogProductDetailRequest, GetCatalogProductDetailResult>(request, result => { result.ShouldNotBeNull(); result.IsNull.ShouldBe(true); result.CatalogCategory.ShouldNotBeNull(); result.CatalogCategory.CatalogCategoryId.ShouldBeNull(); string.IsNullOrWhiteSpace(result.CatalogCategory.DisplayName).ShouldBeTrue(); result.Catalog.ShouldNotBeNull(); result.Catalog.CatalogId.ShouldBeNull(); string.IsNullOrWhiteSpace(result.Catalog.CatalogName).ShouldBeTrue(); }); }
public void Catalog_Remove_CatalogCategory_Within_Descendants_Successfully() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryIdLv1 = IdentityFactory.Create <CategoryId>(); var categoryIdLv2 = IdentityFactory.Create <CategoryId>(); var categoryIdLv3 = IdentityFactory.Create <CategoryId>(); var catalogCategoryLv1 = catalog.AddCategory(categoryIdLv1, this._fixture.Create <string>()); var catalogCategoryLv2 = catalog.AddCategory(categoryIdLv2, this._fixture.Create <string>(), catalogCategoryLv1); var catalogCategoryLv3 = catalog.AddCategory(categoryIdLv3, this._fixture.Create <string>(), catalogCategoryLv2); catalog.RemoveCatalogCategoryWithDescendants(catalogCategoryLv1); catalog.Categories.ShouldBeEmpty(); }
private Person(string personName) : this(IdentityFactory.Create <PersonId>(), personName) { }
public override TIdenity Parse(object value) { return(IdentityFactory.Create <TIdenity>(value)); }
private Inventory(string name, string location) : this(IdentityFactory.Create <InventoryId>(), name, location) { }
private Product(string code) : this(IdentityFactory.Create <ProductId>(), code) { }
private Product(string productName) : this(IdentityFactory.Create <ProductId>(), productName) { }