diff --git a/src/NzbDrone.Common.Test/Http/UserAgentBuilderFixture.cs b/src/NzbDrone.Common.Test/Http/UserAgentBuilderFixture.cs new file mode 100644 index 000000000..6b99793ea --- /dev/null +++ b/src/NzbDrone.Common.Test/Http/UserAgentBuilderFixture.cs @@ -0,0 +1,30 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Http; +using NzbDrone.Test.Common; + +namespace NzbDrone.Common.Test.Http +{ + [TestFixture] + public class UserAgentBuilderFixture : TestBase + { + [Test] + public void should_get_user_agent_if_os_version_is_null() + { + Mocker.GetMock().SetupGet(c => c.Version).Returns((string)null); + Mocker.GetMock().SetupGet(c => c.Name).Returns("TestOS"); + + Subject.GetUserAgent(false).Should().NotBeNullOrWhiteSpace(); + } + + [Test] + public void should_get_use_os_family_if_name_is_null() + { + Mocker.GetMock().SetupGet(c => c.Version).Returns((string)null); + Mocker.GetMock().SetupGet(c => c.Name).Returns((string)null); + + Subject.GetUserAgent(false).Should().NotBeNullOrWhiteSpace(); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index 3f501c00c..eac513244 100644 --- a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -89,6 +89,7 @@ + diff --git a/src/NzbDrone.Common/Http/UserAgentBuilder.cs b/src/NzbDrone.Common/Http/UserAgentBuilder.cs index 57b63bd89..5d3dc9644 100644 --- a/src/NzbDrone.Common/Http/UserAgentBuilder.cs +++ b/src/NzbDrone.Common/Http/UserAgentBuilder.cs @@ -24,8 +24,14 @@ namespace NzbDrone.Common.Http public UserAgentBuilder(IOsInfo osInfo) { - var osName = osInfo.Name.ToLower(); - var osVersion = osInfo.Version.ToLower(); + var osName = OsInfo.Os.ToString(); + + if (!string.IsNullOrWhiteSpace(osInfo.Name)) + { + osName = osInfo.Name.ToLower(); + } + + var osVersion = osInfo.Version?.ToLower(); _userAgent = $"Sonarr/{BuildInfo.Version} ({osName} {osVersion})"; _userAgentSimplified = $"Sonarr/{BuildInfo.Version.ToString(2)}";