예제 #1
0
        public void GetById_ValidId_KindElement()
        {
            int validId = 1;
            var kind    = new Kind
            {
                KindId = 1,
                Type   = "Product"
            };

            var mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.GetById(It.IsAny <int>()))
            .Returns((int id) =>
            {
                if (id == validId)
                {
                    return(new SuccessResult <Kind>(kind));
                }
                return(new NoneResult <Kind>());
            });

            var kindService = new KindService(mockKindRepository.Object);

            var resultKind = kindService.GetById(validId).GetSuccessResult();

            Assert.AreNotEqual(resultKind, null);
            Assert.AreEqual(resultKind.KindId, validId);
            Assert.AreEqual(resultKind.Type, kind.Type);
            mockKindRepository.Verify(mock => mock.GetById(validId), Times.Once());
        }
예제 #2
0
        public void GetById_InvalidId_Throws()
        {
            int invalidId = 0;

            var mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.GetById(It.IsAny <int>()));

            var kindService = new KindService(mockKindRepository.Object);

            var resultKind = kindService.GetById(invalidId);

            mockKindRepository.Verify(mock => mock.GetById(invalidId), Times.Once());
        }
예제 #3
0
 public IHttpActionResult GetById(int id)
 {
     return(Json(service.GetById(id)));
 }