Ejemplo n.º 1
0
        protected override Task <string> GenerateKey(IKeyGenerator keyGenerator, IEnumerable <string> keyElementCollection)
        {
            NullGuard.NotNull(keyGenerator, nameof(keyGenerator))
            .NotNull(keyElementCollection, nameof(keyElementCollection));

            return(keyGenerator.GenerateUserSpecificKeyAsync(keyElementCollection));
        }
Ejemplo n.º 2
0
        public async Task GenerateUserSpecificKeyAsync_WhenKeyElementCollectionHasKeyElements_ReturnsNotNull()
        {
            IKeyGenerator sut = CreateSut();

            string result = await sut.GenerateUserSpecificKeyAsync(_fixture.CreateMany <string>(_random.Next(1, 5)).ToArray());

            Assert.That(result, Is.Not.Null);
        }
Ejemplo n.º 3
0
        public async Task GenerateUserSpecificKeyAsync_WhenKeyElementCollectionHasKeyElementsAndNoMailAddressWasReturnedFromClaimResolver_AssertGetNameIdentifierWasCalledOnClaimResolver()
        {
            IKeyGenerator sut = CreateSut(hasMailAddress: false);

            await sut.GenerateUserSpecificKeyAsync(_fixture.CreateMany <string>(_random.Next(1, 5)).ToArray());

            _claimResolverMock.Verify(m => m.GetNameIdentifier(), Times.Once);
        }
Ejemplo n.º 4
0
        public async Task GenerateUserSpecificKeyAsync_WhenKeyElementCollectionHasKeyElements_ReturnsComputedHashFromComputeHashAsyncOnHashKeyGenerator()
        {
            string        computedHash = _fixture.Create <string>();
            IKeyGenerator sut          = CreateSut(computedHash);

            string result = await sut.GenerateUserSpecificKeyAsync(_fixture.CreateMany <string>(_random.Next(1, 5)).ToArray());

            Assert.That(result, Is.EqualTo(computedHash));
        }
Ejemplo n.º 5
0
        public async Task GenerateUserSpecificKeyAsync_WhenKeyElementCollectionHasKeyElementsAndNoMailAddressButNameIdentifierWasReturnedFromClaimResolver_AssertComputeHashAsyncWasCalledOnHashKeyGenerator()
        {
            string        nameIdentifier = _fixture.Create <string>();
            IKeyGenerator sut            = CreateSut(hasMailAddress: false, nameIdentifier: nameIdentifier);

            string[] keyElements = _fixture.CreateMany <string>(_random.Next(1, 5)).ToArray();
            await sut.GenerateUserSpecificKeyAsync(keyElements);

            _hashKeyGeneratorMock.Verify(m => m.ComputeHashAsync(It.Is <IEnumerable <byte> >(value => value != null && Convert.ToBase64String(value.ToArray()) == Convert.ToBase64String(CalculateByteArrayForKeyElements(nameIdentifier, keyElements)))), Times.Once);
        }
Ejemplo n.º 6
0
        public void GenerateUserSpecificKeyAsync_WhenKeyElementCollectionIsEmpty_ThrowsIntranetValidationExceptionWhereValidatingTypeIsEqualToStringEnumerable()
        {
            IKeyGenerator sut = CreateSut();

            IntranetValidationException result = Assert.ThrowsAsync <IntranetValidationException>(async() => await sut.GenerateUserSpecificKeyAsync(Array.Empty <string>()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ValidatingType, Is.EqualTo(typeof(IEnumerable <string>)));
            // ReSharper restore PossibleNullReferenceException
        }
Ejemplo n.º 7
0
        public void GenerateUserSpecificKeyAsync_WhenKeyElementCollectionIsEmpty_ThrowsIntranetValidationExceptionWhereErrorCodeIsEqualToValueShouldContainSomeItems()
        {
            IKeyGenerator sut = CreateSut();

            IntranetValidationException result = Assert.ThrowsAsync <IntranetValidationException>(async() => await sut.GenerateUserSpecificKeyAsync(Array.Empty <string>()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueShouldContainSomeItems));
            // ReSharper restore PossibleNullReferenceException
        }
Ejemplo n.º 8
0
        public void GenerateUserSpecificKeyAsync_WhenKeyElementCollectionIsEmpty_ThrowsIntranetValidationExceptionWhereMessageContainsKeyElementCollection()
        {
            IKeyGenerator sut = CreateSut();

            IntranetValidationException result = Assert.ThrowsAsync <IntranetValidationException>(async() => await sut.GenerateUserSpecificKeyAsync(Array.Empty <string>()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains("keyElementCollection"), Is.True);
            // ReSharper restore PossibleNullReferenceException
        }
Ejemplo n.º 9
0
        public void GenerateUserSpecificKeyAsync_WhenKeyElementCollectionIsEmpty_ThrowsIntranetValidationException()
        {
            IKeyGenerator sut = CreateSut();

            IntranetValidationException result = Assert.ThrowsAsync <IntranetValidationException>(async() => await sut.GenerateUserSpecificKeyAsync(Array.Empty <string>()));

            Assert.That(result, Is.Not.Null);
        }
Ejemplo n.º 10
0
        public void GenerateUserSpecificKeyAsync_WhenKeyElementCollectionIsNull_ThrowsArgumentNullException()
        {
            IKeyGenerator sut = CreateSut();

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

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("keyElementCollection"));
            // ReSharper restore PossibleNullReferenceException
        }
Ejemplo n.º 11
0
        public void GenerateUserSpecificKeyAsync_WhenKeyElementCollectionHasKeyElementsAndNoMailAddressAndNoNameIdentifierWasReturnedFromClaimResolver_ThrowsIntranetSystemExceptionWhereInnerExceptionIsNull()
        {
            IKeyGenerator sut = CreateSut(hasMailAddress: false, hasNameIdentifier: false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.GenerateUserSpecificKeyAsync(_fixture.CreateMany <string>(_random.Next(1, 5)).ToArray()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
Ejemplo n.º 12
0
        public void GenerateUserSpecificKeyAsync_WhenKeyElementCollectionHasKeyElementsAndNoMailAddressAndNoNameIdentifierWasReturnedFromClaimResolver_ThrowsIntranetSystemException()
        {
            IKeyGenerator sut = CreateSut(hasMailAddress: false, hasNameIdentifier: false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.GenerateUserSpecificKeyAsync(_fixture.CreateMany <string>(_random.Next(1, 5)).ToArray()));

            Assert.That(result, Is.Not.Null);
        }