예제 #1
0
        public void ReadSmartPhoneByGivingNonExistingIdThrowsException()
        {
            var id             = 0;
            var smartPhoneRepo = new Mock <ISmartPhoneRepository>();

            smartPhoneRepo.Setup(x => x.GetSmartPhoneById(It.IsAny <int>())).Returns(default(SmartPhone));
            ISmartPhoneService service = new SmartPhoneService(smartPhoneRepo.Object);


            Exception ex = Assert.Throws <InvalidDataException>(() => service.GetSmartPhoneById(id));

            Assert.Equal("No SmartPhone with id: " + id + " exist", ex.Message);
        }
예제 #2
0
        public void ReadSmartPhoneById()
        {
            var id    = 1;
            var phone = new SmartPhone
            {
                Camera  = "10 mega pixels",
                CpuType = "Qualcomm SnapDragon",
                Memory  = 124,
                OS      = "Android coffee",
                Name    = "Samsung Galaxy",
                Stock   = 10,
                Price   = 1234,
                Screen  = 6.0
            };

            var smartPhoneRepo = new Mock <ISmartPhoneRepository>();

            smartPhoneRepo.Setup(x => x.GetSmartPhoneById(id)).Returns(phone);
            ISmartPhoneService service = new SmartPhoneService(smartPhoneRepo.Object);

            var result = service.GetSmartPhoneById(id);

            Assert.Equal(phone, result);
        }