|
1 | | -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Diagnostics.CodeAnalysis; |
3 | 4 | using System.Net.Http.Json; |
| 5 | +using System.Reflection; |
4 | 6 | using System.Threading.Tasks; |
5 | 7 | using Microsoft.Extensions.DependencyInjection; |
6 | 8 | using NetEvent.Server.Data; |
@@ -91,5 +93,59 @@ public async Task PostOrganizationHandler_Error_Test() |
91 | 93 |
|
92 | 94 | #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. |
93 | 95 | } |
| 96 | + |
| 97 | + [Fact] |
| 98 | + public async Task GetSystemInfoVersionsSetted_Success_Test() |
| 99 | + { |
| 100 | + // Arrange |
| 101 | + AppDomain currentDomain = AppDomain.CurrentDomain; |
| 102 | + Environment.SetEnvironmentVariable("BUILDNODE", "TEST"); |
| 103 | + Environment.SetEnvironmentVariable("BUILDID", "TEST"); |
| 104 | + Environment.SetEnvironmentVariable("BUILDNUMBER", "TEST"); |
| 105 | + Environment.SetEnvironmentVariable("SOURCE_COMMIT", "TEST"); |
| 106 | + |
| 107 | + // Act |
| 108 | + var response = await Client.GetFromJsonAsync<SystemInfoDto>($"/api/system/info/all"); |
| 109 | + |
| 110 | + // Assert |
| 111 | + Assert.NotNull(response); |
| 112 | + Assert.NotNull(response?.Components); |
| 113 | + Assert.Equal(currentDomain.GetAssemblies().Length, response?.Components.Count); |
| 114 | + Assert.NotNull(response?.Health); |
| 115 | + Assert.NotNull(response?.Versions); |
| 116 | + Assert.NotEmpty(response?.Health); |
| 117 | + Assert.NotEmpty(response?.Versions); |
| 118 | + Assert.NotEqual(0, response?.Health.Count); |
| 119 | + Assert.NotEqual(0, response?.Versions.Count); |
| 120 | + Assert.Equal("TEST", response?.Versions?.Find(x => x.Component.Equals("BUILDNODE"))?.Version); |
| 121 | + Assert.Equal("TEST", response?.Versions?.Find(x => x.Component.Equals("BUILDID"))?.Version); |
| 122 | + Assert.Equal("TEST", response?.Versions?.Find(x => x.Component.Equals("BUILDNUMBER"))?.Version); |
| 123 | + Assert.Equal("TEST", response?.Versions?.Find(x => x.Component.Equals("SOURCE_COMMIT"))?.Version); |
| 124 | + Assert.Equal(Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion, response?.Versions?.Find(x => x.Component.Equals("NETEVENT"))?.Version); |
| 125 | + } |
| 126 | + |
| 127 | + [Fact] |
| 128 | + public async Task GetSystemInfoVersionsNotSetted_Success_Test() |
| 129 | + { |
| 130 | + // Arrange |
| 131 | + AppDomain currentDomain = AppDomain.CurrentDomain; |
| 132 | + Environment.SetEnvironmentVariable("BUILDNODE", string.Empty); |
| 133 | + Environment.SetEnvironmentVariable("BUILDID", string.Empty); |
| 134 | + Environment.SetEnvironmentVariable("BUILDNUMBER", string.Empty); |
| 135 | + Environment.SetEnvironmentVariable("SOURCE_COMMIT", string.Empty); |
| 136 | + |
| 137 | + // Act |
| 138 | + var response = await Client.GetFromJsonAsync<SystemInfoDto>($"/api/system/info/all"); |
| 139 | + |
| 140 | + // Assert |
| 141 | + Assert.NotNull(response); |
| 142 | + Assert.NotNull(response?.Versions); |
| 143 | + Assert.NotEmpty(response?.Versions); |
| 144 | + Assert.NotEqual(0, response?.Versions.Count); |
| 145 | + Assert.Equal("dev", response?.Versions?.Find(x => x.Component.Equals("BUILDNODE"))?.Version); |
| 146 | + Assert.Equal("dev", response?.Versions?.Find(x => x.Component.Equals("BUILDID"))?.Version); |
| 147 | + Assert.Equal("dev", response?.Versions?.Find(x => x.Component.Equals("BUILDNUMBER"))?.Version); |
| 148 | + Assert.Equal("dev", response?.Versions?.Find(x => x.Component.Equals("SOURCE_COMMIT"))?.Version); |
| 149 | + } |
94 | 150 | } |
95 | 151 | } |
0 commit comments