1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+ // See the LICENSE file in the project root for more information.
4+
5+ using System ;
6+ using Microsoft . Toolkit . Uwp . Helpers ;
7+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
8+ using Windows . ApplicationModel ;
9+ using Windows . Storage ;
10+
11+ namespace UnitTests . Helpers
12+ {
13+ [ TestClass ]
14+ public class Test_SystemInformation
15+ {
16+ [ TestCategory ( "Helpers" ) ]
17+ [ TestMethod ]
18+ public void Test_SystemInformation_ConsistentInfoForFirstStartup ( )
19+ {
20+ ApplicationData . Current . LocalSettings . Values . Clear ( ) ;
21+
22+ var systemInformation = ( SystemInformation ) Activator . CreateInstance ( typeof ( SystemInformation ) , nonPublic : true ) ;
23+ var currentAppVersion = Package . Current . Id . Version ;
24+
25+ Assert . IsTrue ( systemInformation . IsFirstRun ) ;
26+ Assert . IsFalse ( systemInformation . IsAppUpdated ) ;
27+ Assert . AreEqual ( systemInformation . ApplicationVersion , currentAppVersion ) ;
28+ Assert . AreEqual ( systemInformation . PreviousVersionInstalled , currentAppVersion ) ;
29+ Assert . AreEqual ( systemInformation . FirstVersionInstalled , currentAppVersion ) ;
30+ }
31+
32+ [ TestCategory ( "Helpers" ) ]
33+ [ TestMethod ]
34+ public void Test_SystemInformation_ConsistentInfoForStartupWithNoUpdate ( )
35+ {
36+ ApplicationData . Current . LocalSettings . Values . Clear ( ) ;
37+
38+ // Simulate a first app startup
39+ _ = ( SystemInformation ) Activator . CreateInstance ( typeof ( SystemInformation ) , nonPublic : true ) ;
40+
41+ var systemInformation = ( SystemInformation ) Activator . CreateInstance ( typeof ( SystemInformation ) , nonPublic : true ) ;
42+ var currentAppVersion = Package . Current . Id . Version ;
43+
44+ Assert . IsFalse ( systemInformation . IsFirstRun ) ;
45+ Assert . IsFalse ( systemInformation . IsAppUpdated ) ;
46+ Assert . AreEqual ( systemInformation . ApplicationVersion , currentAppVersion ) ;
47+ Assert . AreEqual ( systemInformation . PreviousVersionInstalled , currentAppVersion ) ;
48+ Assert . AreEqual ( systemInformation . FirstVersionInstalled , currentAppVersion ) ;
49+ }
50+
51+ [ TestCategory ( "Helpers" ) ]
52+ [ TestMethod ]
53+ public void Test_SystemInformation_ConsistentInfoForStartupWithUpdate ( )
54+ {
55+ ApplicationData . Current . LocalSettings . Values . Clear ( ) ;
56+
57+ // Simulate a first app startup
58+ _ = ( SystemInformation ) Activator . CreateInstance ( typeof ( SystemInformation ) , nonPublic : true ) ;
59+
60+ LocalObjectStorageHelper localObjectStorageHelper = new ( new SystemSerializer ( ) ) ;
61+ PackageVersion previousVersion = new ( ) { Build = 42 , Major = 1111 , Minor = 2222 , Revision = 12345 } ;
62+
63+ localObjectStorageHelper . Save ( "currentVersion" , previousVersion . ToFormattedString ( ) ) ;
64+
65+ var systemInformation = ( SystemInformation ) Activator . CreateInstance ( typeof ( SystemInformation ) , nonPublic : true ) ;
66+ var currentAppVersion = Package . Current . Id . Version ;
67+
68+ Assert . IsFalse ( systemInformation . IsFirstRun ) ;
69+ Assert . IsTrue ( systemInformation . IsAppUpdated ) ;
70+ Assert . AreEqual ( systemInformation . ApplicationVersion , currentAppVersion ) ;
71+ Assert . AreEqual ( systemInformation . PreviousVersionInstalled , previousVersion ) ;
72+ Assert . AreEqual ( systemInformation . FirstVersionInstalled , currentAppVersion ) ;
73+ }
74+ }
75+ }
0 commit comments