Exemple #1
0
        /// <summary>
        /// The main program
        /// </summary>
        /// <param name="args">
        /// The args. 
        /// </param>
        private static void Main(string[] args)
        {
            Console.Title = Title;
            CommandLine.WriteLineColor(ConsoleColor.Yellow, Title);
            Trace.Listeners.Add(new ConsoleTraceListener());
            var door = new SecurityDoor();
            var done = false;
            while (!done)
            {
                CommandLine.WriteLineColor(ConsoleColor.Magenta, "\r\nThe door is now {0}", door.State);

                switch (DisplayMenu())
                {
                    case 'a':
                        door.InsertKey(Guid.NewGuid());
                        break;
                    case 'u':
                        door.InsertKey(Guid.Empty);
                        break;
                    case 'x':
                        done = true;
                        break;
                }
            }

            CommandLine.Pause("Sample complete. Press any key to exit");
        }
        public void ValidKeyShouldAuthorize()
        {
            // Arrange
            var securityDoor = new SecurityDoor { Timeout = this.timeout };
            var tracking = new MemoryTrackingParticipant();
            try
            {
                // Act
                // Insert a valid key
                securityDoor.InsertKey(Guid.NewGuid());

                // Assert
                Assert.AreEqual(DoorState.ClosedUnlocked, securityDoor.State);
            }
            finally
            {
                tracking.Trace();
                securityDoor.Trace();
            }
        }