コード例 #1
0
        public void ScreensChanged_ShouldFireAndResolutionShowMatchChange_WhenScreenResolutionChanges()
        {
            var manager    = new ScreenManager();
            var hasChanged = false;
            IReadOnlyCollection <IScreen> updatedScreens = null;

            manager.Changed += (sender, args) =>
            {
                hasChanged     = true;
                updatedScreens = args.Screens;
            };

            var primaryScreen = manager.GetAll().Single(screen => screen.IsPrimary);
            var displayName   = primaryScreen.Name;
            var oldResolution = primaryScreen.Resolution;
            var newResolution = primaryScreen.GetResolutions().OrderByDescending(screen => screen).Skip(1).FirstOrDefault();

            _output.WriteLine("Changing resolution to: " + newResolution);
            ScreenUtils.ChangeResolution(displayName, newResolution);

            Thread.Sleep(1000);

            hasChanged.ShouldBeTrue();
            updatedScreens.ShouldNotBeNull();
            updatedScreens.ShouldContain(screen => screen.IsPrimary && screen.Resolution == newResolution, 1);

            _output.WriteLine("Changing resolution back to: " + oldResolution);
            ScreenUtils.ChangeResolution(displayName, oldResolution);
        }