public async void Should_return_CreatedResult_when_model_Is_valid() { // Arrange var returnExistValue = true; var address = AddressData; int userId = 1; var resultObject = new Address { Address1 = "1601 Hood Avenue", Address2 = "dolore in adipisicing et", City = "San Diego", CountryCode = "11", PinCode = "92103", StateId = 1 }; AddressServiceMock .Setup(x => x.CreateAsync(userId, address)) .ReturnsAsync(resultObject); UserServiceMock .Setup(x => x.IsExistAsync(userId)) .ReturnsAsync(true); //Act UserServiceMock.Setup(x => x.IsExistAsync(userId)).ReturnsAsync(returnExistValue); var result = await ControllerUnderTest.CreateAddress(userId, address); //Assert var okResult = Assert.IsType <CreatedResult>(result); Assert.Same(resultObject, okResult.Value); }
public async void Should_return_BadRequest_when_model_is_null() { // Arrange var key = "Address_StatusCode_400_BadRequest"; var localizedString = new LocalizedString(key, "Bad Request"); LocalizerMock .Setup(_ => _[key]) .Returns(localizedString); // Act var result = await ControllerUnderTest.CreateAddress(1, null); // Assert Assert.IsType <BadRequestObjectResult>(result); }