Esempio n. 1
0
        public void TagTypeLogic_Add_CreateTagType()
        {
            // Arrange
            var name        = GetUniqueString("Tag Type");
            var uniqueAlias = GetUniqueString("Alias", 14);

            // this presumes there is always a category with id 1
            int categoryId = 1;

            var tagType = new Database.Domain.Tagging.TagType()
            {
                Name  = name,
                Alias = uniqueAlias
            };

            // Act
            var service = GetServiceInstance();

            var createResult = service.CreateTagForCategory(tagType, categoryId);

            // Assert
            Assert.IsTrue(createResult.Success, "The result returned from calling CreateTagForCategory must be true");

            // get the tag types for the specified cateogry as atached to that category and not parent
            // categories
            var createdTagType = GetServiceInstance().GetTagTypeForId(createResult.Data.Id).Data;

            Assert.IsNotNull(createdTagType, $"The new tag we tried to read from the collection of tags for the category with id {categoryId}");
            Assert.IsTrue(createdTagType.Name == name, "The expected tag type should have the provided name");

            AssertEntityCreated(createdTagType);
        }
Esempio n. 2
0
        public void UpdateProduct_BySettingAValueForTag_ForWhichTheProduct_DidNotHaveValueBefore()
        {
            //======================================================
            // ARRANGE
            //======================================================

            // the id of the product with which we will be working with
            var productId = 2;

            // get the product and check its category
            // so we can create a new tag for the category
            var productWeWillEdit = GetServiceInstance().GetEdit(productId).Data;

            var categoryId = productWeWillEdit.Category.Id;

            // create a new tag type that will be atached t
            var newTagTypeName = GetUniqueString("TType");
            var tagType        = new Database.Domain.Tagging.TagType {
                Name = newTagTypeName
            };

            var newCreatedTag = GetUtilityService <ITagTypesLogic>().CreateTagForCategory(tagType, categoryId).Data;

            // update the product we will edit
            var newTagValueForProduct     = GetUniqueString("New Tag VAlue");
            var updatedTagValueForProduct = GetUniqueString("Existing Updated Tag Value");
            var updatedProductName        = GetUniqueString("Updated Name");

            // first edit a current tag/property for the given product
            var existingProperty = productWeWillEdit.Properties.FirstOrDefault();

            if (existingProperty != null)
            {
                existingProperty.Value = updatedTagValueForProduct;
            }

            // add a property for which the product has not had an value so far
            productWeWillEdit.Properties.Add(new ProductProperty
            {
                PropertyTypeId = newCreatedTag.Id,
                Value          = newTagValueForProduct
            });

            // change the name of the product
            productWeWillEdit.Name = updatedProductName;

            //======================================================
            // ACT
            //======================================================

            // update the product now
            var methodUnderTestResult = ExecuteMethodUnderTest(productWeWillEdit);

            //======================================================
            // ASSERT
            //======================================================
            // get the number of tag types for the category for which the product belongs to:
            var tagsProductShouldHave = GetUtilityService <ITagTypesLogic>().GetTagTypes(categoryId, true).Data.ToList();

            // re-read the product and check that the values are all set
            var updatedProduct = methodUnderTestResult.Result.Data;

            var readUpdatedProduct = GetServiceInstance().GetEdit(productId).Data;

            // Assert that the number of tag types the product has as it was returned from the edit action
            // matches the number of tag types for its categroy
            Assert.AreEqual(tagsProductShouldHave.Count, updatedProduct.Properties.Count);
            Assert.AreEqual(tagsProductShouldHave.Count, readUpdatedProduct.Properties.Count);

            // assert on the product returned from the update call
            RunUpdateProductAsserts("[FromUpdate]", updatedProduct, updatedProductName, existingProperty, updatedTagValueForProduct, newTagTypeName, newTagValueForProduct);

            RunUpdateProductAsserts("[CleanRead]", readUpdatedProduct, updatedProductName, existingProperty, updatedTagValueForProduct, newTagTypeName, newTagValueForProduct);
        }