public Task <string> GenerateGenericKeyAsync(IEnumerable <string> keyElementCollection)
        {
            NullGuard.NotNull(keyElementCollection, nameof(keyElementCollection));

            string[] keyElementArray = keyElementCollection.ToArray();

            ValidateKeyElementCollection(keyElementArray, typeof(IEnumerable <string>), nameof(keyElementCollection));

            return(_hashKeyGenerator.ComputeHashAsync(ToByteArray(Join(keyElementArray))));
        }
Esempio n. 2
0
        public async Task ComputeHashAsync_WhenCalledWithDifferentByteCollectionsSameInstance_ReturnsDifferentStrings()
        {
            IHashKeyGenerator sut = CreateSut();

            string result = await sut.ComputeHashAsync(_fixture.CreateMany <byte>(_random.Next(128, 256)).ToArray());

            foreach (byte[] byteCollection in new[] { _fixture.CreateMany <byte>(_random.Next(128, 256)).ToArray(), _fixture.CreateMany <byte>(_random.Next(128, 256)).ToArray(), _fixture.CreateMany <byte>(_random.Next(128, 256)).ToArray() })
            {
                Assert.That(await sut.ComputeHashAsync(byteCollection), Is.Not.EqualTo(result));
            }
        }
Esempio n. 3
0
        public async Task ComputeHashAsync_WhenByteCollectionIsNotNull_ReturnsStringWith88Characters()
        {
            IHashKeyGenerator sut = CreateSut();

            string result = await sut.ComputeHashAsync(_fixture.CreateMany <byte>(_random.Next(128, 256)).ToArray());

            Assert.That(result.Length, Is.EqualTo(88));
        }
Esempio n. 4
0
        public async Task ComputeHashAsync_WhenByteCollectionIsNotNull_ReturnsBase64String()
        {
            IHashKeyGenerator sut = CreateSut();

            string result = await sut.ComputeHashAsync(_fixture.CreateMany <byte>(_random.Next(128, 256)).ToArray());

            Assert.That(result.IsBase64String(), Is.True);
        }
Esempio n. 5
0
        public async Task ComputeHashAsync_WhenCalledWithSameByteCollectionOnDifferentInstances_ReturnsSameStringOnEachInstance()
        {
            IHashKeyGenerator sut = CreateSut();

            byte[] byteCollection = _fixture.CreateMany <byte>(_random.Next(128, 256)).ToArray();

            string result = await sut.ComputeHashAsync(byteCollection);

            foreach (IHashKeyGenerator otherSut in new[] { CreateSut(), CreateSut(), CreateSut() })
            {
                Assert.That(await otherSut.ComputeHashAsync(byteCollection), Is.EqualTo(result));
            }
        }
Esempio n. 6
0
        public void ComputeHashAsync_WhenByteCollectionIsNull_ThrowsArgumentNullException()
        {
            IHashKeyGenerator sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.ComputeHashAsync(null));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("byteCollection"));
            // ReSharper restore PossibleNullReferenceException
        }