예제 #1
0
        public void Save_Null_Throws()
        {
            Kind invalidObj         = null;
            var  mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.Save(It.IsAny <Kind>()));

            var kindProvider = new KindService(mockKindRepository.Object);

            kindProvider.Save(invalidObj);

            mockKindRepository.Verify(mock => mock.Save(invalidObj), Times.Once());
        }
예제 #2
0
        public void Save_ValidKindObj_ObjSaved()
        {
            var kinds = new List <Kind>();
            var kind  = new Kind
            {
                KindId = 1,
                Type   = "Product"
            };

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

            mockKindRepository.Setup(repo => repo.Save(It.IsAny <Kind>()))
            .Callback((Kind value) => kinds.Add(value));

            var kindService = new KindService(mockKindRepository.Object);

            kindService.Save(kind);

            Assert.AreEqual(kinds.Count, 1);
            Assert.IsTrue(kinds.Contains(kind));
            mockKindRepository.Verify(mock => mock.Save(kind), Times.Once());
        }
예제 #3
0
        public IHttpActionResult Save(KindDto kindDto)
        {
            if (kindDto.Name == null || kindDto.Description == null)
            {
                return(Json(new ResponseMessage {
                    Code = 500, Error = "Your data is not valid."
                }));
            }

            ResponseMessage response = new ResponseMessage();

            if (service.Save(kindDto))
            {
                response.Code = 200;
                response.Body = "Kind was saved.";
            }
            else
            {
                response.Code = 500;
                response.Body = "Kind was not saved.";
            }

            return(Json(response));
        }