public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);

            while (game.CanContinue)
            {
                var input   = Console.ReadLine();
                var message = game.GetMessage(input);
                int count   = 0;
                if (message == "OK")
                {
                    var output = game.Guess(input);
                    count++;
                    Console.WriteLine(output);
                }
                else
                {
                    Console.WriteLine(message);
                }

                if (count == 6)
                {
                    break;
                }
            }

            Console.WriteLine("Game Over");
        }
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);

            const int maxCount = 6;
            var       count    = 0;

            while (game.CanContinue)
            {
                var input = Console.ReadLine();

                while (!CheckInput(ref input))
                {
                    Console.WriteLine("invalid input");
                    input = Console.ReadLine();
                }

                var output = game.Guess(input);
                Console.WriteLine(output);
                count++;

                if (output == "4A0B" || count == maxCount)
                {
                    break;
                }
            }

            Console.WriteLine("Game Over");
        }
예제 #3
0
        public void GenerateIdentifiableSecret_HonorsSeed()
        {
            ulong  seed   = uint.MaxValue;
            string secret = SecretGenerator.GenerateIdentifiableSecret(uint.MaxValue);

            ValidateSecret(secret, seed);
        }
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);
            int countGameTimes = 0;

            while (game.CanContinue)
            {
                var input = Console.ReadLine();
                if (!game.IsValid(input))
                {
                    continue;
                }

                var output = game.Guess(input);
                Console.WriteLine(output);
                countGameTimes++;
                if (output == "4A0B")
                {
                    Console.WriteLine("You win!");
                    break;
                }

                if (countGameTimes == 6)
                {
                    break;
                }
            }

            Console.WriteLine("Game Over");
        }
예제 #5
0
        public void Secret_Length_Test()
        {
            var secret = SecretGenerator.RandomString(15);

            Assert.IsNotNull(secret, "Secret is null after gbeeing generated");
            Assert.AreEqual(15, secret.Length, "Secret is not the length spesified in generation");
        }
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);
            var input = Console.ReadLine();

            while (!game.IsInputValid(input))
            {
                Console.WriteLine("Wrong Input, input again! \n");
                input = Console.ReadLine();
            }

            while (game.CanContinue())
            {
                var output = game.Judge(input);
                if (output == "4A0B")
                {
                    Console.WriteLine(output);
                    break;
                }
                else
                {
                    Console.WriteLine(output);
                    input = Console.ReadLine();
                }
            }

            Console.WriteLine("Game Over");
        }
예제 #7
0
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);

            while (game.CanContinue)
            {
                var input = Console.ReadLine();
                if (!game.IsInputValid(input))
                {
                    Console.WriteLine("Wrong Input, input again");
                    continue;
                }

                var output = game.Guess(input);
                Console.WriteLine(output);
                if (output == "4A0B")
                {
                    Console.WriteLine("You win");
                    break;
                }

                game.CountInputTimes();
            }

            Console.WriteLine("Game Over");
        }
예제 #8
0
        //public void GetData(Action<AppSecret, Exception> callback)
        //{
        //    // Use this to create design time data

        //    var item = new AppSecret();
        //    callback(item, null);
        //}
        public void GetAllSecrets(Action <IList <IApiSecret>, Exception> callback)
        {
            callback(new List <IApiSecret>()
            {
                new ApiSecret()
                {
                    AllowedApis = new List <ApiType>()
                    {
                        ApiType.ComputerApi, ApiType.Telefoni
                    },
                    Description = "Testing description",
                    Owner       = "sf9398",
                    Secret      = SecretGenerator.RandomString(15)
                }, new ApiSecret()
                {
                    AllowedApis = new List <ApiType>()
                    {
                        ApiType.ComputerApi, ApiType.Telefoni
                    },
                    Description = "Testing description",
                    Owner       = "sf9398",
                    Secret      = SecretGenerator.RandomString(15)
                }, new ApiSecret()
                {
                    AllowedApis = new List <ApiType>()
                    {
                        ApiType.ComputerApi, ApiType.Telefoni
                    },
                    Description = "Testing description",
                    Owner       = "sf9398",
                    Secret      = SecretGenerator.RandomString(15)
                }
            }, null);
        }
        public void Should_create_proper_random_secret()
        {
            var secretGenerator = new SecretGenerator();
            var secret          = secretGenerator.GenerateSecret();

            Assert.Equal(4, secret.Length);
            Assert.Equal(4, secret.Distinct().Count());
        }
예제 #10
0
        public void Should_create_BullsAndCowsGame()
        {
            var secretGenerator = new SecretGenerator();
            var game            = new BullsAndCowsGame(secretGenerator);

            Assert.NotNull(game);
            Assert.True(game.CanContinue);
        }
예제 #11
0
 public RequestPasswordResetTransactionScript(
     RequestPasswordResetRequestValidator requestPasswordResetRequestValidator,
     SecretGenerator secretGenerator,
     IResetPasswordNotifier resetPasswordNotifier)
 {
     _requestPasswordResetRequestValidator = requestPasswordResetRequestValidator;
     _secretGenerator       = secretGenerator;
     _resetPasswordNotifier = resetPasswordNotifier;
 }
예제 #12
0
        public void SecretGeneratedShouldHaveLengthOfFour()
        {
            var secretGenerator = new SecretGenerator();
            var secret          = secretGenerator.GenerateSecret();
            var expected        = secret.Count();
            var actual          = 4;

            Assert.Equal(expected, actual);
        }
예제 #13
0
 public SignUpTransactionScript(
     SignUpRequestValidator signUpRequestValidator,
     ISignUpConfirmationNotifier signUpConfirmationNotifier,
     SecretGenerator secretGenerator)
 {
     _signUpRequestValidator     = signUpRequestValidator;
     _signUpConfirmationNotifier = signUpConfirmationNotifier;
     _secretGenerator            = secretGenerator;
 }
예제 #14
0
 public SignInTransactionScript(
     SignInRequestValidator signInRequestValidator,
     SecretGenerator secretGenerator,
     ITimeProvider timeProvider)
 {
     _signInRequestValidator = signInRequestValidator;
     _secretGenerator        = secretGenerator;
     _timeProvider           = timeProvider;
 }
        public void Secret_should_different_between_two_generate()
        {
            string          secret1;
            string          secret2;
            SecretGenerator secretGenerator = new SecretGenerator();

            secret1 = secretGenerator.GenerateSecret();
            secret2 = secretGenerator.GenerateSecret();
            Assert.NotEqual(secret1, secret2);
        }
예제 #16
0
        public void Should_GenerateSecret_return_valid_secret()
        {
            // given
            var secretGenerator = new SecretGenerator();

            // when
            var secret = secretGenerator.GenerateSecret();

            // then
            Assert.True(IsSecretValid(secret));
        }
예제 #17
0
        public void Secret_Uniqe_Test()
        {
            var numberOfGenerations = 1000;
            var range = Enumerable.Range(0, numberOfGenerations);

            var secrets = range.Select(i => SecretGenerator.RandomString(15));

            var duplicats = secrets.Distinct();

            Assert.AreEqual(numberOfGenerations, duplicats.Count());
        }
예제 #18
0
        public void Should_return_non_repeatable_secret_numbers()
        {
            var secretGenerator = new SecretGenerator();
            var secret          = secretGenerator.GenerateSecret();

            var secretChars = secret.ToCharArray();
            var len         = 4;
            var actual      = secretChars.Length == len && secretChars.Distinct().Count() == len;

            Assert.Equal(true, actual);
        }
        public void Should_different_Between_2_Digits()
        {
            //given
            var secretGenerator = new SecretGenerator();
            var secret          = secretGenerator.GenerateSecret();

            //when
            var secret1 = secretGenerator.GenerateSecret();

            //then
            Assert.NotEqual(secret, secret1);
        }
        public void Should_Generat_4_Digits()
        {
            //given
            var secretGenerator = new SecretGenerator();
            var secret          = secretGenerator.GenerateSecret();

            //when
            var secretLength = 4;

            //then
            Assert.Equal(secret.Length, secretLength);
        }
        public void Secret_length_should_be_4()
        {
            // given
            string secret          = string.Empty;
            var    secretGenerator = new SecretGenerator();

            // when
            secret = secretGenerator.GenerateSecret();

            // then
            Assert.Equal(4, secret.Length);
        }
예제 #22
0
        public void GenerateFunctionKeyValue_GeneratesCorrectSecret()
        {
            // This is how the preliminary system key seed was generated.
            // "Functi01" can be used as the next string literal if this seed
            // is versioned. The bytes are reversed in an attempt to retain a
            // common prefix (left-hand data value) for the the seed if changed.
            ulong expectedSeed = BitConverter.ToUInt64(Encoding.ASCII.GetBytes("Functi00").Reverse().ToArray());

            Assert.Equal(expectedSeed, SecretGenerator.FunctionKeySeed);

            string secret = SecretGenerator.GenerateFunctionKeyValue();

            ValidateSecret(secret, SecretGenerator.FunctionKeySeed);
        }
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);

            while (game.CanContinue)
            {
                var input  = Console.ReadLine();
                var output = game.Guess(input);
                Console.WriteLine(output);
            }

            Console.WriteLine("Game Over");
        }
예제 #24
0
        private static void ProcessDbCommands(string[] args, IHost host)
        {
            var services = (IServiceScopeFactory)host.Services.GetService(typeof(IServiceScopeFactory));

            using (var scope = services.CreateScope())
            {
                var context       = scope.ServiceProvider.GetRequiredService <DblDipDbContext>();
                var store         = scope.ServiceProvider.GetRequiredService <EventStore>();
                var configuration = scope.ServiceProvider.GetRequiredService <IConfiguration>();

                if (args.Contains("ci"))
                {
                    args = new string[4] {
                        "dropdb", "migratedb", "seeddb", "stop"
                    }
                }
                ;

                if (args.Contains("dropdb"))
                {
                    context.Database.EnsureDeleted();
                    store.Database.EnsureDeleted();
                }

                if (args.Contains("migratedb"))
                {
                    context.Database.Migrate();
                    store.Database.Migrate();
                }

                if (args.Contains("seeddb"))
                {
                    context.Database.EnsureCreated();
                    store.Database.EnsureCreated();
                    DbInitializer.Initialize(context, store, configuration);
                }

                if (args.Contains("secret"))
                {
                    Console.WriteLine(SecretGenerator.Generate());
                    Environment.Exit(0);
                }

                if (args.Contains("stop"))
                {
                    Environment.Exit(0);
                }
            }
        }
예제 #25
0
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);

            Console.WriteLine("please input 4 different digital, use space to separate each other");
            while (game.CanContinue)
            {
                var input  = Console.ReadLine();
                var output = game.Guess(input);
                Console.WriteLine(output);
            }

            Console.WriteLine("Game Over");
        }
예제 #26
0
        private async Task <string> GetOrCreateExtensionKey(string extensionName)
        {
            ISecretManager secretManager = _secretManagerProvider.Current;
            var            hostSecrets   = await secretManager.GetHostSecretsAsync();

            string keyName = GetKeyName(extensionName);
            string keyValue;

            if (!hostSecrets.SystemKeys.TryGetValue(keyName, out keyValue))
            {
                // if the requested secret doesn't exist, create it on demand
                keyValue = SecretGenerator.GenerateSystemKeyValue();
                await secretManager.AddOrUpdateFunctionSecretAsync(keyName, keyValue, HostKeyScopes.SystemKeys, ScriptSecretsType.Host);
            }

            return(keyValue);
        }
예제 #27
0
        public static async Task DBSetup(string[] args, IHost host)
        {
            var serviceScopeFactory = (IServiceScopeFactory)host.Services.GetService(typeof(IServiceScopeFactory));

            using var scope = serviceScopeFactory.CreateScope();

            var eventStoreContext  = scope.ServiceProvider.GetRequiredService <EventStoreContext>();
            var appDatabaseContext = scope.ServiceProvider.GetRequiredService <AppDatabaseContext>();
            var configuration      = scope.ServiceProvider.GetRequiredService <IConfiguration>();

            if (args.Contains("ci"))
            {
                args = new string[4] {
                    "dropdb", "migratedb", "seeddb", "stop"
                }
            }
            ;
            if (args.Contains("dropdb"))
            {
                eventStoreContext.Database.EnsureDeleted();
            }
            if (args.Contains("migratedb"))
            {
                eventStoreContext.Database.Migrate();
            }

            if (args.Contains("seeddb"))
            {
                eventStoreContext.Database.EnsureCreated();
                await DataSeeder.SeedAsync(appDatabaseContext, configuration);
            }

            if (args.Contains("secret"))
            {
                Console.WriteLine(SecretGenerator.GenerateSecret());
                Environment.Exit(0);
            }

            if (args.Contains("stop"))
            {
                Environment.Exit(0);
            }
        }
    }
        public static void Main(string[] args)
        {
            SecretGenerator  secretGenerator = new SecretGenerator();
            BullsAndCowsGame game            = new BullsAndCowsGame(secretGenerator);
            InputCheck       inputCheck      = new InputCheck();

            while (game.CanContinue)
            {
                var input = Console.ReadLine();
                input = inputCheck.CheckInput(input);
                if (!IsNullOrEmpty(input))
                {
                    var output = game.Guess(input);
                    Console.WriteLine(output);
                }
            }

            Console.WriteLine("Game Over");
        }
        public TokenProviderTests()
        {
            var secret = SecretGenerator.Generate();

            var values = new Dictionary <string, string> {
                { $"{nameof(Authentication)}:{nameof(Authentication.TokenPath)}", "/token" },
                { $"{nameof(Authentication)}:{nameof(Authentication.ExpirationMinutes)}", "1" },
                { $"{nameof(Authentication)}:{nameof(Authentication.JwtKey)}", secret },
                { $"{nameof(Authentication)}:{nameof(Authentication.JwtIssuer)}", "UnitTests" },
                { $"{nameof(Authentication)}:{nameof(Authentication.JwtAudience)}", "UnitTests" },
                { $"{nameof(Authentication)}:{nameof(Authentication.AuthType)}", "Test" }
            };

            var configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection(values)
                                .Build();

            _tokenProvider = new TokenProvider(configuration);
        }
예제 #30
0
        private static void ProcessDatabase(string[] args, IHost host)
        {
            var services = (IServiceScopeFactory)host.Services.GetService(typeof(IServiceScopeFactory));

            using var scope = services.CreateScope();
            var eventStoreDbContext = scope.ServiceProvider.GetRequiredService <EventStoreDatabaseContext>();
            var databaseContext     = scope.ServiceProvider.GetRequiredService <IDatabaseContext>();
            var configuration       = scope.ServiceProvider.GetRequiredService <IConfiguration>();

            if (args.Contains("ci"))
            {
                args = new string[4] {
                    "dropdb", "migratedb", "seeddb", "stop"
                }
            }
            ;

            if (args.Contains("dropdb"))
            {
                eventStoreDbContext.Database.EnsureDeleted();
            }
            if (args.Contains("migratedb"))
            {
                eventStoreDbContext.Database.Migrate();
            }

            if (args.Contains("seeddb"))
            {
                eventStoreDbContext.Database.EnsureCreated();
                DataSeeder.Seed(databaseContext);
            }

            if (args.Contains("secret"))
            {
                Console.WriteLine(SecretGenerator.GenerateSecret());
                Environment.Exit(0);
            }

            if (args.Contains("stop"))
            {
                Environment.Exit(0);
            }
        }