public void Is_invalid_when_associated_products_exist() { var categoryID = 1; var proxyMock = new Mock <IProductDataProxy>(); proxyMock.Setup(proxy => proxy.GetByCategory(categoryID)) .Returns(new[] { new Product() }); var rule = new CanDeleteCategoryRule(categoryID, proxyMock.Object); rule.Validate().IsValid.ShouldBe(false); rule.ErrorMessage.ShouldNotBe(null); }
public void Is_valid_when_no_associated_products_exist() { var categoryID = 1; var proxyMock = new Mock <IProductDataProxy>(); proxyMock.Setup(proxy => proxy.GetByCategory(categoryID)) .Returns(Enumerable.Empty <Product>()); var rule = new CanDeleteCategoryRule(categoryID, proxyMock.Object); rule.Validate().IsValid.ShouldBe(true); rule.ErrorMessage.ShouldBe(null); }
public async Task Is_invalid_when_associated_products_exist_async() { var categoryID = 1; var proxyMock = new Mock <IProductDataProxy>(); proxyMock.Setup(proxy => proxy.GetByCategoryAsync(categoryID)) .Returns(Task.FromResult((new[] { new Product() }).AsEnumerable <Product>())); var rule = new CanDeleteCategoryRule(categoryID, proxyMock.Object); await rule.ValidateAsync(); rule.IsValid.ShouldBe(false); rule.ErrorMessage.ShouldNotBe(null); }
public void Is_valid_when_no_associated_products_exist() { var categoryID = 1; var proxyMock = new Mock <IProductDataProxy>(); proxyMock.Setup(proxy => proxy.GetByCategory(categoryID)).Returns(Enumerable.Empty <Product>()); var rule = new CanDeleteCategoryRule(categoryID, proxyMock.Object); bool isValid = rule.Validate().IsValid; Assert.IsTrue(isValid, "Rule validation result should be TRUE!"); Assert.IsNull(rule.ErrorMessage, "Rule Error message should be NULL!"); }
public async Task Is_invalid_when_associated_products_exist_async() { var categoryID = 1; var proxyMock = new Mock <IProductDataProxy>(); proxyMock.Setup(proxy => proxy.GetByCategoryAsync(categoryID)).Returns(Task.FromResult((new[] { new Product() }).AsEnumerable <Product>())); var rule = new CanDeleteCategoryRule(categoryID, proxyMock.Object); await rule.ValidateAsync(); bool isValid = rule.IsValid; Assert.IsFalse(isValid, "Rule validation result should be TRUE!"); Assert.IsNotNull(rule.ErrorMessage, "Rule Error message should be NULL!"); }