public void Test_CanGetKeysByPattern_HasOnlyFallbackClientRule(string pattern) { List <string> expectedResult = new List <string> { "x", "y", "z" }; Mock <ICacheClientExtended> fallbackClientMocker = new Mock <ICacheClientExtended>(MockBehavior.Strict); fallbackClientMocker.Setup(c => c.GetKeysByPattern(pattern)) .Returns(expectedResult); IRoutedCacheClient routedCacheClient = CreateRoutedCacheClient(fallbackClientMocker.Object); IEnumerable <string> actualResult = routedCacheClient.GetKeysByPattern(pattern); Assert.NotNull(actualResult); CollectionAssert.AreEqual(expectedResult, actualResult); fallbackClientMocker.Verify(c => c.GetKeysByPattern(pattern), Times.Once); fallbackClientMocker.VerifyNoOtherCalls(); }
public void Test_CanGetKeysByPattern_HasManyClientRules_AllDifferent(string pattern) { List <string> expectedResult = new List <string> { "x", "y", "z", "a", "b", "c", "1", "2", "3" }; Mock <ICacheClientExtended> fallbackClientMocker = new Mock <ICacheClientExtended>(MockBehavior.Strict); Mock <ICacheClientExtended> client1Mocker = new Mock <ICacheClientExtended>(MockBehavior.Strict); Mock <ICacheClientExtended> client2Mocker = new Mock <ICacheClientExtended>(MockBehavior.Strict); fallbackClientMocker.Setup(c => c.GetKeysByPattern(pattern)) .Returns(new List <string>() { "x", "y", "z" }); client1Mocker.Setup(c => c.GetKeysByPattern(pattern)) .Returns(new List <string>() { "a", "b", "c" }); client2Mocker.Setup(c => c.GetKeysByPattern(pattern)) .Returns(new List <string>() { "1", "2", "3" }); IRoutedCacheClient routedCacheClient = CreateRoutedCacheClient(fallbackClientMocker.Object, new KeyStartsWithStringCacheClientRule(client1Mocker.Object, StringComparison.InvariantCultureIgnoreCase, Guid.NewGuid().ToString()), new KeyStartsWithStringCacheClientRule(client2Mocker.Object, StringComparison.InvariantCultureIgnoreCase, Guid.NewGuid().ToString())); IEnumerable <string> actualResult = routedCacheClient.GetKeysByPattern(pattern); Assert.NotNull(actualResult); CollectionAssert.AreEquivalent(expectedResult, actualResult); fallbackClientMocker.Verify(c => c.GetKeysByPattern(pattern), Times.Once); client1Mocker.Verify(c => c.GetKeysByPattern(pattern), Times.Once); client2Mocker.Verify(c => c.GetKeysByPattern(pattern), Times.Once); fallbackClientMocker.VerifyNoOtherCalls(); client1Mocker.VerifyNoOtherCalls(); client2Mocker.VerifyNoOtherCalls(); }
private void Assert_AllMethodsThrowObjectDisposedException(IRoutedCacheClient routedCacheClient) { Faker faker = new Faker(); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Add(RandomKey, faker.Random.Int())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Add(SessionKey, faker.Random.Int())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Add(RandomKey, faker.Random.Decimal(), faker.Date.Timespan())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Add(SessionKey, faker.Random.Decimal(), faker.Date.Timespan())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Add(RandomKey, faker.Random.String(), faker.Date.Future())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Add(SessionKey, faker.Random.String(), faker.Date.Future())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Decrement(RandomKey, faker.Random.UInt())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Decrement(SessionKey, faker.Random.UInt())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .FlushAll()); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .FlushAll()); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Get <string>(RandomKey)); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Get <string>(SessionKey)); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .GetAll <string>(faker.Make(faker.Random.Int(0, 100), () => RandomKey))); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .GetAll <string>(faker.Make(faker.Random.Int(0, 100), () => SessionKeyPrefix))); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .GetKeysByPattern(SessionKeyPrefix)); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .GetKeysByPattern(RandomKeyPrefix)); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .GetTimeToLive(SessionKey)); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .GetTimeToLive(RandomKey)); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Increment(RandomKey, faker.Random.UInt())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Increment(SessionKey, faker.Random.UInt())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Remove(SessionKey)); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Remove(RandomKey)); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .RemoveAll(faker.Make(faker.Random.Int(0, 100), () => RandomKey))); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .RemoveAll(faker.Make(faker.Random.Int(0, 100), () => SessionKeyPrefix))); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Replace(RandomKey, faker.Random.Int())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Replace(SessionKey, faker.Random.Int())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Replace(RandomKey, faker.Random.Decimal(), faker.Date.Timespan())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Replace(SessionKey, faker.Random.Decimal(), faker.Date.Timespan())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Replace(RandomKey, faker.Random.String(), faker.Date.Future())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Replace(SessionKey, faker.Random.String(), faker.Date.Future())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Set(RandomKey, faker.Random.Int())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Set(SessionKey, faker.Random.Int())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Set(RandomKey, faker.Random.Decimal(), faker.Date.Timespan())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Set(SessionKey, faker.Random.Decimal(), faker.Date.Timespan())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Set(RandomKey, faker.Random.String(), faker.Date.Future())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .Set(SessionKey, faker.Random.String(), faker.Date.Future())); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .SetAll(new Dictionary <string, string>(faker.Make( faker.Random.Int(0, 100), () => new KeyValuePair <string, string>(RandomKey, faker.Random.String()) )))); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .SetAll(new Dictionary <string, int>(faker.Make( faker.Random.Int(0, 100), () => new KeyValuePair <string, int>(SessionKey, faker.Random.Int()) )))); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .PushClientWithRule(new Mock <IRoutedCacheClientRule>(MockBehavior.Loose).Object)); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .ClearRules()); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .GetRegisteredClients()); Assert.Throws <ObjectDisposedException>(() => routedCacheClient .GetRegisteredClientRules()); }