public void ShouldThrowExceptionWhenAddAddressFails() { _addressRepository = new Mock<IAddressRepository>(); _addressRepository.Setup(a => a.Add(It.IsAny<Address>())).Throws(new Exception()); _addressLogic = new AddressLogic(_addressRepository.Object); Assert.Throws<BlogException>(() => _addressLogic.Add(new Common.Contracts.Address())); }
public void ShouldAddAddress() { var dbResult = new Address { AddressId = 3, StreetAddress = "Wiggle", City = "Berry", State = "Carrot", Country = "Gumbo", Zip = 1234, UserId = 5, User = new User { UserId = 5, UserName = "******" } }; _addressRepository = new Mock<IAddressRepository>(); _addressRepository.Setup(a => a.Add(It.IsAny<Address>())).Returns(dbResult); _addressLogic = new AddressLogic(_addressRepository.Object); var result = _addressLogic.Add(new Common.Contracts.Address { AddressId = 3, StreetAddress = "Wiggle", City = "Berry", State = "Carrot", Country = "Gumbo", Zip = 1234 }); Assert.IsNotNull(result); Assert.AreEqual(5, result.UserId); }