Exemple #1
0
        /// <summary>
        /// Generates db tables and inserts some dummy data.
        /// </summary>
        /// <param name="app"></param>
        public static void Seed(IApplicationBuilder app)
        {
            AppDbContext context = app.ApplicationServices.GetRequiredService <AppDbContext>();

            context.Database.Migrate();

            if (!context.Users.Any())
            {
                var hash     = new Sha512Hash();
                var salt     = hash.GetSalt();
                var userHash = hash.GetHash("*****@*****.**" + "password", salt);

                context.Users.Add(new User()
                {
                    IsActive  = true,
                    Salt      = salt,
                    Hash      = userHash,
                    Created   = DateTime.Now,
                    Email     = "*****@*****.**",
                    FirstName = "Ahmet",
                    LastName  = "Sönmez",
                    UserName  = "******",
                });

                context.SaveChanges();
            }
        }
Exemple #2
0
        public void Sha512Hash_GetHash_Null_3()
        {
            IHash hashAlgo = new Sha512Hash();

            Action action = () => hashAlgo.GetHash(null as FileInfo);

            action.Should().Throw <ArgumentNullException>();
        }
Exemple #3
0
        public void Sha512Hash_GetHash_Empty()
        {
            IHash hashAlgo = new Sha512Hash();

            Action action = () => hashAlgo.GetHash(string.Empty);

            action.Should().Throw <ArgumentNullException>();
        }
Exemple #4
0
        public void Sha512Hash_GetHash_Valid_2()
        {
            IHash hashAlgo = new Sha512Hash();

            HashResult hashResult = hashAlgo.GetHash(Data.ExpectedHashFilePath);

            hashResult.Algorithm.Should().Be(Hashing.ExpectedSha512Algorithm);
            hashResult.Value.Should().Be(Hashing.ExpectedSha512Hash);
        }
Exemple #5
0
        public void Sha512Hash_GetHash_Valid_1()
        {
            IHash hashAlgo = new Sha512Hash();

            using FileStream fileStream = new(Data.ExpectedHashFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);

            HashResult hashResult = hashAlgo.GetHash(fileStream);

            hashResult.Algorithm.Should().Be(Hashing.ExpectedSha512Algorithm);
            hashResult.Value.Should().Be(Hashing.ExpectedSha512Hash);
        }