コード例 #1
0
        public void GetCategory_InvalidCategoryId_ThrowsNotFound(long id)
        {
            var response    = new HttpResponseMessage(HttpStatusCode.NotFound);
            var contextMock = Mock.Of <Entities>();

            var logic = new CategoryLogic(contextMock);

            logic.Invoking(p => p.GetCategory(id)).ShouldThrow <HttpResponseException>().Where(p => p.Response == response);
        }
コード例 #2
0
        public void GetCategory_CategoryNotNull_ReturnsCategory()
        {
            var category = new Category()
            {
                CategoryId = 1
            };
            //var contextMock = Mock.Of<Entities>(entities => entities.Categories.Find(1) == category);
            var dbSetMock   = Mock.Of <DbSet <Category> >(set => set.Find(1) == category);
            var contextMock = Mock.Of <Entities>(entities => entities.Categories.Find(1) == dbSetMock.Find(1));

            var logic = new CategoryLogic(contextMock);

            logic.Invoking(p => p.GetCategory(1)).ShouldBeEquivalentTo(category);
        }