public void DeleteSmartPhone() { var id = 1; var phone = new SmartPhone { Id = id, 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.DeleteSmartPhone(id)).Returns(phone); ISmartPhoneService service = new SmartPhoneService(smartPhoneRepo.Object); var result = service.DeleteSmartPhone(id); Assert.Equal(phone, result); }
public void DeleteSmartPhoneByGivingNonExistingIdThrowsException() { var id = 0; var smartPhoneRepo = new Mock <ISmartPhoneRepository>(); smartPhoneRepo.Setup(x => x.DeleteSmartPhone(It.IsAny <int>())).Returns(default(SmartPhone)); ISmartPhoneService service = new SmartPhoneService(smartPhoneRepo.Object); Exception ex = Assert.Throws <InvalidDataException>(() => service.DeleteSmartPhone(id)); Assert.Equal("No SmartPhone with id: " + id + " exist", ex.Message); }