Example #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));
        }
Example #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);
        }
Example #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);
        }
Example #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));
        }
Example #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);
        }
Example #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
        }
Example #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
        }
Example #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
        }
Example #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);
        }
Example #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
        }
Example #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
        }
Example #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);
        }