public void Test_AddSubCategory()
        {
            Category category = null;
            var      result   = subCategoryController.Post(subCategoryName, category).Result;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult));

            category = new Category {
                Id = Guid.NewGuid(), Name = categoryName
            };
            result = subCategoryController.Post(subCategoryName, category).Result;
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult));

            category = DocumentDbRepository.GetCategory(categoryName);
            SubCategory subCategory = DocumentDbRepository.GetSubCategory(subCategoryName, category);

            result = subCategoryController.Post(subCategoryName, category).Result;
            Assert.IsNotNull(result);

            if (subCategory == null)
            {
                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <string>));
            }
            else
            {
                Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult));
            }
        }
Exemplo n.º 2
0
        public void Post_WithMockedModel_ShouldReturnNewId()
        {
            // Arrange
            var mockRepository = new Mock <ISubCategoryRepository>();
            var dbModel        = new SubCategoryModel();
            var expectedValue  = 7452;

            mockRepository
            .Setup(m => m.Insert(dbModel))
            .Returns(expectedValue);

            var controller = new SubCategoryController(mockRepository.Object);

            // Act
            var result      = controller.Post(dbModel) as JsonResult;
            var actualValue = (int)result.Value;

            // Assert
            Assert.AreEqual(expectedValue, actualValue);
        }