public void BuzHash_Implementation_HashSizeInBits_MatchesConfig() { var validHashSizes = new[] { 8, 16, 32, 64 }; foreach (var hashSize in validHashSizes) { var buzHashConfigMock = new Mock <IBuzHashConfig>(); { buzHashConfigMock.SetupGet(bhc => bhc.Rtab) .Returns(new UInt64[256]); buzHashConfigMock.SetupGet(bhc => bhc.HashSizeInBits) .Returns(hashSize); buzHashConfigMock.SetupGet(bhc => bhc.ShiftDirection) .Returns(CircularShiftDirection.Left); buzHashConfigMock.Setup(bhc => bhc.Clone()) .Returns(() => buzHashConfigMock.Object); } var buzHash = new BuzHash_Implementation(buzHashConfigMock.Object); Assert.Equal(hashSize, buzHash.HashSizeInBits); } }
public async Task BuzHash_Implementation_ComputeHashInternal_WhenInvalidHashSize_Throws() { var shouldReturnValidHashSize = true; var buzHashConfigMock = new Mock <IBuzHashConfig>(); { buzHashConfigMock.SetupGet(bhc => bhc.HashSizeInBits) .Returns(() => shouldReturnValidHashSize ? 32 : 1); buzHashConfigMock.SetupGet(bhc => bhc.Rtab) .Returns(new UInt64[256]); buzHashConfigMock.Setup(bhc => bhc.Clone()) .Returns(() => buzHashConfigMock.Object); } var buzHash = new BuzHash_Implementation(buzHashConfigMock.Object); shouldReturnValidHashSize = false; Assert.Throws <NotImplementedException>( () => buzHash.ComputeHash(new byte[0])); using (var memoryStream = new MemoryStream(new byte[0])) { Assert.Throws <NotImplementedException>( () => buzHash.ComputeHash(memoryStream)); await Assert.ThrowsAsync <NotImplementedException>( () => buzHash.ComputeHashAsync(memoryStream)); } }
public void BuzHash_Implementation_Config_IsCloneOfClone() { var buzHashConfig3 = Mock.Of <IBuzHashConfig>(); var buzHashConfig2 = Mock.Of <IBuzHashConfig>(bhc => bhc.Rtab == new UInt64[256] && bhc.HashSizeInBits == 32 && bhc.ShiftDirection == CircularShiftDirection.Left && bhc.Clone() == buzHashConfig3); var buzHashConfig = Mock.Of <IBuzHashConfig>(bhc => bhc.Clone() == buzHashConfig2); var buzHashHash = new BuzHash_Implementation(buzHashConfig); Assert.Equal(buzHashConfig3, buzHashHash.Config); }