Exemplo n.º 1
0
        //public void CreateCategoryShouldThrowException()
        //{
        //    var mockRepo = new Mock<ICategoryRepository>();
        //    Category category = new Category { Id = 101, Name = "Sports", CreatedBy = "Mukesh", Description = "All about sports", CreationDate = new DateTime() };
        //    List<Category> categories = new List<Category>();
        //    mockRepo.Setup(repo => repo.GetAllCategoriesByUserId("Mukesh")).Returns(this.GetCategories());
        //    var service = new CategoryService.Service.CategoryService(mockRepo.Object);

        //    var actual = Assert.Throws<CategoryNotCreatedException>(()=> service.CreateCategory(category));
        //    Assert.Equal("This category already exists",actual.Message);
        //}
        public void CreateCategoryShouldThrowException()
        {
            var      mockRepo = new Mock <ICategoryRepository>();
            Category category = new Category {
                Id = 101, Name = "Sports", CreatedBy = "Mukesh", Description = "All about sports", CreationDate = new DateTime()
            };
            List <Category> categories = new List <Category>();

            mockRepo.Setup(repo => repo.GetAllCategoriesByUserId("Mukesh")).Returns(this.GetCategories());
            mockRepo.Setup(repo => repo.GetCategoryById(101)).Returns(category); //insert this line
            var service = new CategoryService.Service.CategoryService(mockRepo.Object);
            var actual  = Assert.Throws <CategoryNotCreatedException>(() => service.CreateCategory(category));

            Assert.Equal("This category already exists", actual.Message);
        }
Exemplo n.º 2
0
        public void CreateCategoryShouldReturnCategory()
        {
            var      mockRepo = new Mock <ICategoryRepository>();
            Category category = new Category {
                Id = 121, Name = "Entertainment", CreatedBy = "Mukesh", Description = "All about entertainment", CreationDate = DateTime.Now
            };

            mockRepo.Setup(repo => repo.GetAllCategoriesByUserId("Mukesh")).Returns(this.GetCategories());
            mockRepo.Setup(repo => repo.CreateCategory(category)).Returns(category);
            var service = new CategoryService.Service.CategoryService(mockRepo.Object);

            var actual = service.CreateCategory(category);

            Assert.NotNull(actual);
            Assert.IsAssignableFrom <Category>(actual);
        }