protected override Task <string> GenerateKey(IKeyGenerator keyGenerator, IEnumerable <string> keyElementCollection) { NullGuard.NotNull(keyGenerator, nameof(keyGenerator)) .NotNull(keyElementCollection, nameof(keyElementCollection)); return(keyGenerator.GenerateGenericKeyAsync(keyElementCollection)); }
public async Task GenerateGenericKeyAsync_WhenKeyElementCollectionHasKeyElements_ReturnsNotNull() { IKeyGenerator sut = CreateSut(); string result = await sut.GenerateGenericKeyAsync(_fixture.CreateMany <string>(_random.Next(1, 5)).ToArray()); Assert.That(result, Is.Not.Null); }
public async Task GenerateGenericKeyAsync_WhenKeyElementCollectionHasKeyElements_ReturnsComputedHashFromComputeHashAsyncOnHashKeyGenerator() { string computedHash = _fixture.Create <string>(); IKeyGenerator sut = CreateSut(computedHash); string result = await sut.GenerateGenericKeyAsync(_fixture.CreateMany <string>(_random.Next(1, 5)).ToArray()); Assert.That(result, Is.EqualTo(computedHash)); }
public async Task GenerateGenericKeyAsync_WhenKeyElementCollectionHasKeyElements_AssertComputeHashAsyncWasCalledOnHashKeyGenerator() { IKeyGenerator sut = CreateSut(); string[] keyElements = _fixture.CreateMany <string>(_random.Next(1, 5)).ToArray(); await sut.GenerateGenericKeyAsync(keyElements); _hashKeyGeneratorMock.Verify(m => m.ComputeHashAsync(It.Is <IEnumerable <byte> >(value => value != null && Convert.ToBase64String(value.ToArray()) == Convert.ToBase64String(CalculateByteArrayForKeyElements(keyElements)))), Times.Once); }
public void GenerateGenericKeyAsync_WhenKeyElementCollectionIsEmpty_ThrowsIntranetValidationExceptionWhereValidatingTypeIsEqualToStringEnumerable() { IKeyGenerator sut = CreateSut(); IntranetValidationException result = Assert.ThrowsAsync <IntranetValidationException>(async() => await sut.GenerateGenericKeyAsync(Array.Empty <string>())); // ReSharper disable PossibleNullReferenceException Assert.That(result.ValidatingType, Is.EqualTo(typeof(IEnumerable <string>))); // ReSharper restore PossibleNullReferenceException }
public void GenerateGenericKeyAsync_WhenKeyElementCollectionIsEmpty_ThrowsIntranetValidationExceptionWhereErrorCodeIsEqualToValueShouldContainSomeItems() { IKeyGenerator sut = CreateSut(); IntranetValidationException result = Assert.ThrowsAsync <IntranetValidationException>(async() => await sut.GenerateGenericKeyAsync(Array.Empty <string>())); // ReSharper disable PossibleNullReferenceException Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueShouldContainSomeItems)); // ReSharper restore PossibleNullReferenceException }
public void GenerateGenericKeyAsync_WhenKeyElementCollectionIsEmpty_ThrowsIntranetValidationExceptionWhereMessageContainsKeyElementCollection() { IKeyGenerator sut = CreateSut(); IntranetValidationException result = Assert.ThrowsAsync <IntranetValidationException>(async() => await sut.GenerateGenericKeyAsync(Array.Empty <string>())); // ReSharper disable PossibleNullReferenceException Assert.That(result.Message.Contains("keyElementCollection"), Is.True); // ReSharper restore PossibleNullReferenceException }
public void GenerateGenericKeyAsync_WhenKeyElementCollectionIsEmpty_ThrowsIntranetValidationException() { IKeyGenerator sut = CreateSut(); IntranetValidationException result = Assert.ThrowsAsync <IntranetValidationException>(async() => await sut.GenerateGenericKeyAsync(Array.Empty <string>())); Assert.That(result, Is.Not.Null); }
public void GenerateGenericKeyAsync_WhenKeyElementCollectionIsNull_ThrowsArgumentNullException() { IKeyGenerator sut = CreateSut(); ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.GenerateGenericKeyAsync(null)); // ReSharper disable PossibleNullReferenceException Assert.That(result.ParamName, Is.EqualTo("keyElementCollection")); // ReSharper restore PossibleNullReferenceException }