protected override Task <string> GenerateKey(IKeyGenerator keyGenerator, IEnumerable <string> keyElementCollection) { NullGuard.NotNull(keyGenerator, nameof(keyGenerator)) .NotNull(keyElementCollection, nameof(keyElementCollection)); return(keyGenerator.GenerateUserSpecificKeyAsync(keyElementCollection)); }
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); }
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); }
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)); }
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); }
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 }
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 }
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 }
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); }
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 }
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 }
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); }