protected virtual IObjectSecurityStrategy CreateSecurityStrategy() { return(new DomainObjectSecurityStrategyDecorator( ObjectSecurityStrategy.Create(this, InvalidationToken.Create()), this, RequiredSecurityForStates.None)); }
private IBusinessObject CreateDerivedBindableSecurableObject(ISecurityContextFactory securityContextFactoryStub) { return((IBusinessObject) DerivedBindableSecurableObject.NewObject( _clientTransaction, ObjectSecurityStrategy.Create(securityContextFactoryStub, InvalidationToken.Create()))); }
IObjectSecurityStrategy ISecurableObject.GetSecurityStrategy() { return(new DomainObjectSecurityStrategyDecorator( ObjectSecurityStrategy.Create(this, InvalidationToken.Create()), this, RequiredSecurityForStates.NewAndDeleted)); }
private SecurableObject CreateSecurableObject(ISecurityContextFactory securityContextFactory, ClientTransaction clientTransaction = null, Action <SecurableObject> action = null) { return(SecurableObject.NewObject( clientTransaction ?? _clientTransaction, ObjectSecurityStrategy.Create(securityContextFactory, InvalidationToken.Create()), action)); }
public void SetUp() { _context = SecurityContext.Create(typeof(SecurableObject), "owner", "group", "tenant", new Dictionary <string, Enum>(), new Enum[0]); _invalidationToken = InvalidationToken.Create(); _strategy = ObjectSecurityStrategy.Create(new SerializableSecurityContextFactory(_context), _invalidationToken); }
public void IsCurrent_WithCurrentRevision_ReturnsTrue() { var token = InvalidationToken.Create(); var revision = token.GetCurrent(); Assert.That(token.IsCurrent(revision), Is.True); }
public IObjectSecurityStrategy GetSecurityStrategy() { if (_objectSecurityStrategy == null) { _objectSecurityStrategy = ObjectSecurityStrategy.Create(this, InvalidationToken.Create()); } return(_objectSecurityStrategy); }
public void IsCurrent_WithInvalidatedRevision_ReturnsFalse() { var token = InvalidationToken.Create(); var revision = token.GetCurrent(); token.Invalidate(); Assert.That(token.IsCurrent(revision), Is.False); }
public void IsCurrent_WithRevisionFromDifferentToken_ThrowsArgumentException() { var token1 = InvalidationToken.Create(); var token2 = InvalidationToken.Create(); Assert.That( () => token2.IsCurrent(token1.GetCurrent()), Throws.ArgumentException.With.Message.EqualTo( "The Revision used for the comparision was not created by the current CacheInvalidationToken.\r\nParameter name: revision")); }
public void IsCurrent_WithRevisionFromDefaultConstructor_ThrowsArgumentException() { var token = InvalidationToken.Create(); Assert.That( () => token.IsCurrent(new InvalidationToken.Revision()), Throws.ArgumentException.With.Message.EqualTo( "The Revision used for the comparision was either created via the default constructor or the associated CacheInvalidationToken has already been garbage collected.\r\n" + "Parameter name: revision")); }
public void Create_CacheInvalidationTokenOverload() { var cacheInvalidationToken = InvalidationToken.Create(); var result = CacheFactory.Create <string, int> (cacheInvalidationToken); Assert.That(result, Is.TypeOf(typeof(InvalidationTokenBasedCacheDecorator <string, int>))); Assert.That(((InvalidationTokenBasedCacheDecorator <string, int>)result).InvalidationToken, Is.SameAs(cacheInvalidationToken)); var innerCache = PrivateInvoke.GetNonPublicField(result, "_innerCache"); Assert.That(innerCache, Is.TypeOf(typeof(Cache <string, int>))); }
IObjectSecurityStrategy ISecurableObject.GetSecurityStrategy() { if (_domainObjectSecurityStrategy == null) { _domainObjectSecurityStrategy = new InstanceBasedReEntrancyGuardedObjectSecurityStrategyDecorator( new DomainObjectSecurityStrategyDecorator( ObjectSecurityStrategy.Create(this, InvalidationToken.Create()), this, RequiredSecurityForStates.NewAndDeleted)); } return(_domainObjectSecurityStrategy); }
public void SetUp() { _securityProviderMock = MockRepository.GenerateStrictMock <ISecurityProvider>(); _securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory>(); _principalStub = MockRepository.GenerateStub <ISecurityPrincipal>(); _principalStub.Stub(_ => _.User).Return("user"); _context = SecurityContext.Create(typeof(SecurableObject), "owner", "group", "tenant", new Dictionary <string, Enum>(), new Enum[0]); _securityContextFactoryStub.Stub(_ => _.CreateSecurityContext()).Return(_context); _invalidationToken = InvalidationToken.Create(); _strategy = ObjectSecurityStrategy.Create(_securityContextFactoryStub, _invalidationToken); }
public void GetCurrent_FromDifferentCacheInvalidationTokens_ReturnsDifferentRevisions() { var token1 = InvalidationToken.Create(); var token2 = InvalidationToken.Create(); if (token1.GetHashCode() == token2.GetHashCode()) { Assert.Ignore( "GetHashCode() happened to have returned the same value for different CacheInvalidationToken instances. " + "This means the same seed value has been used and the tokens should not be used for comparission."); } Assert.That(token1.GetCurrent(), Is.Not.EqualTo(token2.GetCurrent())); }
public void Create_CacheInvalidationTokenOverload_IEqualityComparerOverload() { var cacheInvalidationToken = InvalidationToken.Create(); var result = CacheFactory.Create <string, int> (cacheInvalidationToken, _comparer); Assert.That(result, Is.TypeOf(typeof(InvalidationTokenBasedCacheDecorator <string, int>))); Assert.That(((InvalidationTokenBasedCacheDecorator <string, int>)result).InvalidationToken, Is.SameAs(cacheInvalidationToken)); var innerCache = PrivateInvoke.GetNonPublicField(result, "_innerCache"); Assert.That(innerCache, Is.TypeOf(typeof(Cache <string, int>))); var innerDataStore = PrivateInvoke.GetNonPublicField(innerCache, "_dataStore"); Assert.That(((SimpleDataStore <string, int>)innerDataStore).Comparer, Is.SameAs(_comparer)); }
public void Serialization() { var token = InvalidationToken.Create(); var revision = token.GetCurrent(); var deserializedObjects = Serializer.SerializeAndDeserialize(new object[] { token, revision }); var deserializedToken = (InvalidationToken)deserializedObjects[0]; var deserializedRevision = (InvalidationToken.Revision)deserializedObjects[1]; Assert.That(deserializedToken.IsCurrent(deserializedRevision), Is.True); #if DEBUG Assert.That( () => token.IsCurrent(deserializedRevision), Throws.ArgumentException.With.Message.EqualTo( "The Revision used for the comparision was not created by the current CacheInvalidationToken.\r\nParameter name: revision")); #endif }
public void HasAccess_Property() { var securityContextStub = MockRepository.GenerateStub <ISecurityContext>(); var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory>(); securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(securityContextStub); _securityProviderStub .Stub(mock => mock.GetAccess(securityContextStub, _securityPrincipalStub)) .Return(new[] { AccessType.Get(GeneralAccessTypes.Read) }); ISecurableObject securableObject = new SecurableObject( ObjectSecurityStrategy.Create(securityContextFactoryStub, InvalidationToken.Create())); var hasMethodAccess = _securityClient.HasPropertyReadAccess(securableObject, "IsVisible"); Assert.That(hasMethodAccess, Is.True); }
public void GetEnumerator_NonGeneric_AfterTokenWasInvalidated_ReturnsEmptySequence() { var cache = new Cache <string, object>(); object exptected1 = new object(); object exptected2 = new object(); cache.Add("key1", exptected1); cache.Add("key2", exptected2); var decorated = new InvalidationTokenBasedCacheDecorator <string, object> (cache, InvalidationToken.Create()); decorated.InvalidationToken.Invalidate(); Assert.That(decorated.ToNonGenericEnumerable().Cast <KeyValuePair <string, object> >(), Is.Empty); }
public void Clear_ClearsInnerCache() { var cache = new Cache <object, string>(); var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create()); var key = new object(); cache.Add(key, "Value"); ((ICache <object, string>)decorator).Clear(); string cachedValue; bool cachedResult = cache.TryGetValue(key, out cachedValue); Assert.That(cachedResult, Is.False); }
public void GetCurrent_FromSameCacheInvalidationToken_ReturnsSameRevisionTwice() { var token = InvalidationToken.Create(); Assert.That(token.GetCurrent(), Is.EqualTo(token.GetCurrent())); }
public void Clear_DoesNotInvalidateToken() { var cache = new Cache <object, string>(); var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create()); var revision = decorator.InvalidationToken.GetCurrent(); ((ICache <object, string>)decorator).Clear(); Assert.That(decorator.InvalidationToken.IsCurrent(revision), Is.True); }
public void GetOrCreateValue_AfterTokenWasInvalidated_RefreshesRevision_ReturnsValue() { var cache = new Cache <object, string>(); var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create()); var key = new object(); cache.Add(key, "Value1"); decorator.InvalidationToken.Invalidate(); var valueOnFirstCall = decorator.GetOrCreateValue(key, o => "Value2"); Assert.That(valueOnFirstCall, Is.EqualTo("Value2")); var valueOnSecondCall = decorator.GetOrCreateValue(key, o => { throw new InvalidOperationException(); }); Assert.That(valueOnSecondCall, Is.EqualTo("Value2")); }
public void GetOrCreateValue_WithValueInCache_ReturnsValue() { var cache = new Cache <object, string>(); var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create()); var key = new object(); cache.Add(key, "Value"); var value = decorator.GetOrCreateValue(key, o => { throw new InvalidOperationException(); }); Assert.That(value, Is.EqualTo("Value")); }
private IBusinessObject CreateDerivedSecurableClassWithProperties(ISecurityContextFactory securityContextFactoryStub) { return((IBusinessObject)ObjectFactory.Create( false, typeof(DerivedSecurableClassWithProperties), ParamList.Create(ObjectSecurityStrategy.Create(securityContextFactoryStub, InvalidationToken.Create())))); }
public void IsNull_WithNullCache_ReturnsTrue() { var cache = new NullCache <object, string>(); var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create()); Assert.That(((ICache <object, string>)decorator).IsNull, Is.True); }
public void Serializable() { var cache = new Cache <object, string>(); var invalidationTokenBasedCacheDecorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create()); var deserializedInstance = Serializer.SerializeAndDeserialize(invalidationTokenBasedCacheDecorator); Assert.That(deserializedInstance, Is.Not.SameAs(invalidationTokenBasedCacheDecorator)); Assert.That(deserializedInstance.InvalidationToken, Is.Not.SameAs(invalidationTokenBasedCacheDecorator.InvalidationToken)); }
public void GetOrCreateValue_WithValueNotInCache_CreatedValue_ReturnsValue() { var cache = new Cache <object, string>(); var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create()); var key = new object(); var value = decorator.GetOrCreateValue(key, o => "Value"); Assert.That(value, Is.EqualTo("Value")); string cachedValue; cache.TryGetValue(key, out cachedValue); Assert.That(cachedValue, Is.EqualTo("Value")); }
public void GetEnumerator_NonGeneric_ReturnsItemsFromCache() { var cache = new Cache <string, object>(); var decorator = new InvalidationTokenBasedCacheDecorator <string, object> (cache, InvalidationToken.Create()); object exptected1 = new object(); object exptected2 = new object(); cache.Add("key1", exptected1); cache.Add("key2", exptected2); Assert.That( decorator.ToNonGenericEnumerable(), Is.EquivalentTo( new[] { new KeyValuePair <string, object> ("key1", exptected1), new KeyValuePair <string, object> ("key2", exptected2) } )); }
public void Clear_RefreshesRevision() { var cache = new Cache <object, string>(); var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create()); decorator.InvalidationToken.Invalidate(); ((ICache <object, string>)decorator).Clear(); var key = new object(); cache.Add(key, "Value"); string value; var result = decorator.TryGetValue(key, out value); Assert.That(result, Is.True); Assert.That(value, Is.EqualTo("Value")); }
public void GetOrCreateValue_AfterTokenWasInvalidated_CreatesNewValue_ReturnsValue() { var cache = new Cache <object, string>(); var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create()); var key = new object(); cache.Add(key, "Value1"); decorator.InvalidationToken.Invalidate(); var value = decorator.GetOrCreateValue(key, o => "Value2"); Assert.That(value, Is.EqualTo("Value2")); string cachedValue; cache.TryGetValue(key, out cachedValue); Assert.That(cachedValue, Is.EqualTo("Value2")); }