예제 #1
0
        public static async Task Main(string[] args)
        {
            if (!Directory.Exists(SeedFileFolder))
            {
                Directory.CreateDirectory(SeedFileFolder);
            }

            var seedStream = File.Open(SeedFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            using (var crng = await PRNGFortunaProviderFactory.CreateWithSeedFileAsync(seedStream))
            {
                await crng.InitializePRNGAsync();

                string input = args.Length > 0 ? args[0] : "100";
                do
                {
                    if (int.TryParse(input, out int range))
                    {
                        Console.WriteLine(crng.RandomNumber(range));
                    }
                    else
                    {
                        Console.WriteLine("Please enter a valid integer.");
                    }

                    input = Console.ReadLine();
                } while (input != "exit" && args.Length <= 0);
            }
        }
        public async Task CreateAsync_Cancelled_ThrowsCancellationException()
        {
            // Create an immediate cancellation
            var source = new CancellationTokenSource();

            source.Cancel();

            await Assert.ThrowsAsync <TaskCanceledException>(async() => await PRNGFortunaProviderFactory.CreateAsync(token: source.Token));
        }
        public void Create_Cancelled_ThrowsCancellationException()
        {
            // Create an immediate cancellation
            var source = new CancellationTokenSource();

            source.Cancel();

            Assert.Throws <OperationCanceledException>(() => PRNGFortunaProviderFactory.Create(token: source.Token));
        }
예제 #4
0
        public async static Task Main(string[] args)
        {
            var builder = new HostBuilder()
                          .ConfigureServices((services) =>
                                             services
                                             .AddSingleton(_ => PRNGFortunaProviderFactory.Create())
                                             .AddSingleton <ConfigFacade>()
                                             .AddSingleton <GambleConfigFacade>()
                                             .AddSingleton <GambleFacade>()
                                             .AddHostedService <Bot>());

            await builder.RunConsoleAsync();
        }
 public PRNGFortunaProviderTests(ITestOutputHelper output)
 {
     _output = output;
     _sut    = PRNGFortunaProviderFactory.Create() as PRNGFortunaProvider;
 }
        public void Create_WithSeedFile_DoesNotThrow()
        {
            var memoryStream = new MemoryStream(new byte[64]);

            PRNGFortunaProviderFactory.CreateWithSeedFile(memoryStream);
        }
 public PRNGFortunaProviderTests()
 {
     _sut = PRNGFortunaProviderFactory.Create() as PRNGFortunaProvider;
 }