コード例 #1
0
        public void Create_傳入已存在的分類名稱_拋出例外()
        {
            string categoryName = "BBB";

            ICategoryDAO dao = Substitute.For <ICategoryDAO>();

            dao.IsExist(Arg.Any <string>()).Returns(true);

            var service = new CategoryService(dao);
            var ex      = Assert.Throws <Exception>(() => service.Create(categoryName));

            Assert.That(() => ex.Message.Contains("存在"));
        }
コード例 #2
0
        public void Create_傳入不存在的分類名稱_新增資料成功()
        {
            string categoryName = "BBB";

            ICategoryDAO dao = Substitute.For <ICategoryDAO>();

            dao.IsExist(Arg.Any <string>()).Returns(false);

            var service = new CategoryService(dao);

            service.Create(categoryName);

            dao.Received().Create(categoryName);
        }