コード例 #1
0
        public void GetAddressById_NoMatch() {
            // Arrange
            const int addressId = 15;
            var mockAddressService = new Mock<IAddressService>();
            mockAddressService.Setup(x => x.GetAddressById(addressId))
                .Returns((Address)null);
            var addressController = new AddressesController(mockAddressService.Object) {
                Request = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            // Act
            var response = addressController.Get(addressId);

            // Assert
            Address address;
            Assert.IsFalse(response.TryGetContentValue(out address));
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
コード例 #2
0
        public void GetAddressesPaginated() {
            // Arrange
            const int pageNumber = 2;
            const int pageSize = 2;
            var mockAddressService = new Mock<IAddressService>();
            mockAddressService.Setup(x => x.GetAddressesPaginated(pageNumber, pageSize))
                .Returns(new PaginationViewModel {
                    CurrentPage = pageNumber,
                    PageSize = pageSize
                });

            var addressController = new AddressesController(mockAddressService.Object) {
                Request = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            // Act
            var response = addressController.GetAddressesPaginated(pageNumber, pageSize);

            // Assert
            PaginationViewModel paginationViewModel;
            Assert.IsTrue(response.TryGetContentValue(out paginationViewModel));
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
コード例 #3
0
        public void AddAddress_CanAdd() {
            // Arrange
            var address = new Address {
                Id = 1
            };
            var mockAddressService = new Mock<IAddressService>();
            mockAddressService.Setup(x => x.AddAddress(address))
                .Returns(address);
            var addressController = new AddressesController(mockAddressService.Object) {
                Request = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            // Act
            var response = addressController.AddAddress(address);

            // Assert
            Address addedAddress;
            Assert.IsTrue(response.TryGetContentValue(out addedAddress));
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }
コード例 #4
0
        public void DeleteAddress_CanDelete() {
            // Arrange
            const int addressId = 4;
            var mockAddressService = new Mock<IAddressService>();
            mockAddressService.Setup(x => x.DeleteAddress(addressId))
                .Returns(true);
            var addressController = new AddressesController(mockAddressService.Object) {
                Request = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            // Act
            var response = addressController.DeleteAddress(addressId);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }