コード例 #1
0
ファイル: Program.cs プロジェクト: Diagnosea/Submarine.Api
        public static async Task Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile(SettingsFileName)
                                .Build();

            var databaseSettings = configuration.GetSettings <DatabaseSettings>();

            var database = new SubmarineDatabaseBuilder()
                           .WithConnectionString(databaseSettings.ConnectionString)
                           .WithConvention(new EnumRepresentationConvention(BsonType.String))
                           .Build();

            var userCollection    = database.GetEntityCollection <UserEntity>();
            var licenseCollection = database.GetEntityCollection <LicenseEntity>();

            var hashedPassword  = BCrypt.Net.BCrypt.HashPassword("password");
            var isValidPassword = BCrypt.Net.BCrypt.Verify("password", hashedPassword);

            Console.WriteLine($"Generated Valid Password: {isValidPassword}");

            var user = new UserEntity
            {
                Id           = Guid.NewGuid(),
                EmailAddress = "*****@*****.**",
                Password     = hashedPassword,
                FriendlyName = "Joshua Crowe",
                UserName     = "******",
                Roles        = new List <UserRole> {
                    UserRole.Standard
                }
            };

            await userCollection.InsertOneAsync(user);

            var product = new LicenseProductEntity
            {
                Name       = "Submarine",
                Expiration = DateTime.UtcNow.AddYears(1)
            };

            var licenseKeyBytes  = Encoding.UTF8.GetBytes("licenseKey");
            var licenseKey       = Convert.ToBase64String(licenseKeyBytes);
            var hashedLicenseKey = BCrypt.Net.BCrypt.HashPassword(licenseKey);

            var license = new LicenseEntity
            {
                Id       = Guid.NewGuid(),
                UserId   = user.Id,
                Key      = hashedLicenseKey,
                Products = new List <LicenseProductEntity> {
                    product
                }
            };

            await licenseCollection.InsertOneAsync(license);

            Console.WriteLine($"Inserted User '{user.Id}' with License '{license.Id}'");
        }
コード例 #2
0
 public static LicenseProductDto ToDto(this LicenseProductEntity licenseProduct)
 {
     return(new LicenseProductDto
     {
         Name = licenseProduct.Name,
         Expiration = licenseProduct.Expiration
     });
 }
コード例 #3
0
 public TestLicenseEntityBuilder WithProduct(LicenseProductEntity product)
 {
     _products.Add(product);
     return(this);
 }