コード例 #1
0
        public void ShouldThrowExceptionWhenUpdateAddressFails()
        {
            _addressRepository = new Mock<IAddressRepository>();
            _addressRepository.Setup(a => a.Edit(It.IsAny<Address>())).Throws(new Exception());

            _addressLogic = new AddressLogic(_addressRepository.Object);

            Assert.Throws<BlogException>(() => _addressLogic.Update(new Common.Contracts.Address()));
        }
コード例 #2
0
        public void ShouldUpdateAddress()
        {
            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.Edit(It.IsAny<Address>())).Returns(dbResult);

            _addressLogic = new AddressLogic(_addressRepository.Object);

            var result = _addressLogic.Update(new Common.Contracts.Address
            {
                AddressId = 3,
                StreetAddress = "Wiggle",
                City = "Berry",
                State = "Carrot",
                Country = "Gumbo",
                Zip = 1234
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(5, result.UserId);
        }