3
使用XUnit声明异常
我是XUnit和Moq的新手。我有一个以字符串为参数的方法,如何使用XUnit处理异常。 [Fact] public void ProfileRepository_GetSettingsForUserIDWithInvalidArguments_ThrowsArgumentException() { //arrange ProfileRepository profiles = new ProfileRepository(); //act var result = profiles.GetSettingsForUserID(""); //assert //The below statement is not working as expected. Assert.Throws<ArgumentException>(() => profiles.GetSettingsForUserID("")); } 被测方法 public IEnumerable<Setting> GetSettingsForUserID(string userid) { if (string.IsNullOrWhiteSpace(userid)) throw new ArgumentException("User Id Cannot be null"); var s = profiles.Where(e => …
111
c#
unit-testing
xunit