public void RetrieveDefinedFeaturesThrowsFeatureStoreFaultExceptionOnException() { IStorageContainer storageContainer = m_MockRepository.StrictMock <IStorageContainer>(); FeatureScope scope = FeatureScope.Create(Guid.NewGuid(), Guid.NewGuid()); using (m_MockRepository.Record()) { Expect.Call(storageContainer.Retrieve(scope)).Throw(new CheckFeatureStateException("Bad Mojo Exception")); m_MockRepository.ReplayAll(); FeatureStoreService featureStoreService = new FeatureStoreService(storageContainer); try { featureStoreService.RetrieveDefinedFeatures( RetrieveDefinedFeaturesRequest.Create( "UpdateFeatureStateThrowsFeatureStoreFaultExceptionOnException", scope)); Assert.Fail("Expecting FaultException<FeatureStoreFault>"); } catch (FaultException <FeatureStoreFault> e) { Console.WriteLine(e.Detail.Message); Console.WriteLine(e.Message); StringAssert.Contains(e.Detail.Message, "An exception occurred retrieving defined Features."); } m_MockRepository.VerifyAll(); } }
public void RetrieveFeaturesForOwnerId() { string messageId = Guid.NewGuid().ToString(); Guid ownerId = Guid.NewGuid(); IList <Feature> features = new List <Feature> { Feature.Create(1, ownerId, Guid.Empty, "Feature One"), Feature.Create(1, ownerId, Guid.NewGuid(), "Feature Two"), Feature.Create(1, ownerId, Guid.NewGuid(), "Feature Three") }; IFeatureStore featureStore = new StandardFeatureStore(m_StorageContainer); FeatureScope featureScope = FeatureScope.Create(ownerId, Guid.Empty); RetrieveDefinedFeaturesRequest request = RetrieveDefinedFeaturesRequest.Create(messageId, featureScope); using (m_MockRepository.Record()) { Expect.Call(m_StorageContainer.Retrieve(featureScope)).Return(features); m_MockRepository.ReplayAll(); RetrieveDefinedFeaturesResponse response = featureStore.RetrieveDefinedFeatures(request); Assert.AreEqual(request.Header.MessageId, response.Header.MessageId); foreach (Feature feature in response.Result) { Assert.AreEqual(ownerId, feature.OwnerId); } m_MockRepository.VerifyAll(); } }
private static RetrieveDefinedFeaturesRequest BuildRetrieveDefinedFeaturesRequestWithSavedFeature( string messageId) { Guid ownerGuid = Guid.NewGuid(); Guid space = Guid.NewGuid(); Feature[] features = new[] { Feature.Create(3, ownerGuid, space, "RetrieveDefinedFeaturesFeature3"), Feature.Create(4, ownerGuid, space, "RetrieveDefinedFeaturesFeature4"), Feature.Create(5, ownerGuid, space, "RetrieveDefinedFeaturesFeature5") }; foreach (Feature feature in features) { AddFeatureToStorage(feature.Name, feature); } return(RetrieveDefinedFeaturesRequest.Create(messageId, FeatureScope.Create(ownerGuid, space))); }
/// <summary> /// Writes all the features that have been defined in the service to the Console. /// </summary> private static void DumpStoredFeatures() { IFeatureStoreServiceProxy proxy = new FeatureStoreServiceProxy(); RetrieveDefinedFeaturesResponse response = proxy.RetrieveDefinedFeatures( RetrieveDefinedFeaturesRequest.Create( "DumpStoredFeatures", FeatureScope.Create(Guid.Empty, Guid.Empty))); foreach (Feature feature in response.Result) { Console.WriteLine( string.Format( CultureInfo.CurrentUICulture, "Id [{0}], OwnerOd [{1}], Space [{2}], Name [{3}], Enabled [{4}]", feature.Id, feature.OwnerId, feature.Space, feature.Name, feature.Enabled)); } }
/// <summary> /// Thread routine that calls the various service methods thus generating the performance counter data. /// </summary> /// <param name="stopper"> /// The stopper. /// </param> private void Runner(object stopper) { ManualResetEvent stopEvent = (ManualResetEvent)stopper; IFeatureStoreServiceProxy proxy = new FeatureStoreServiceProxy(); Action <int>[] calls = new Action <int>[] { v => proxy.CreateFeature(CreateFeatureRequest.Create( "CreateFeature lambda", Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), Thread.CurrentThread.ManagedThreadId.ToString()))), v => proxy.UpdateFeatureState( UpdateFeatureStateRequest.Create( "UpdateFeatureState lambda", CreateFeatureKey(v), !m_StandardFeatures[v].Enabled)), v => proxy.CheckFeatureState( CheckFeatureStateRequest.Create( "CheckFeatureState lambda", CreateFeatureKey(v))), v => proxy.RetrieveDefinedFeatures( RetrieveDefinedFeaturesRequest.Create( "RetrieveDefinedFeatures lambda", FeatureScope.Create(m_StandardFeatures[v].OwnerId, m_StandardFeatures[v].Space))) }; while (true) { int index = m_Random.Next(0, calls.Length); Console.WriteLine(@"Invoking lambda {0}", index); calls[index].Invoke(index); if (stopEvent.WaitOne(20)) { break; } } }
/// <summary> /// Builds the feature scope. /// </summary> /// <param name = "serviceMethodUiBridge">The service method UI bridge.</param> /// <returns></returns> protected FeatureScope BuildFeatureScope(IServiceMethodUiBridge serviceMethodUiBridge) { return(FeatureScope.Create( serviceMethodUiBridge.FeatureStoreMethodArguments.OwnerId, serviceMethodUiBridge.FeatureStoreMethodArguments.Space)); }
public void StorageIsQueryableBySpaceAndOwnerId() { Guid ownerId1 = Guid.NewGuid(); Guid ownerId2 = Guid.NewGuid(); Guid ownerId3 = Guid.NewGuid(); Guid space1 = Guid.NewGuid(); Guid space2 = Guid.NewGuid(); Guid space3 = Guid.NewGuid(); List <Feature> defined = new List <Feature> { Feature.Create(1, ownerId1, space1, "space1 ownerId1"), Feature.Create(1, ownerId1, space2, "space2 ownerId1"), Feature.Create(1, ownerId1, space3, "space3 ownerId1"), Feature.Create(1, ownerId2, space1, "space1 ownerId2"), Feature.Create(2, ownerId2, space1, "space1 ownerId2"), Feature.Create(3, ownerId2, space1, "space1 ownerId2"), Feature.Create(1, ownerId2, space2, "space2 ownerId2"), Feature.Create(1, ownerId2, space3, "space3 ownerId2"), Feature.Create(1, ownerId3, space1, "space1 ownerId3"), Feature.Create(1, ownerId3, space2, "space2 ownerId3"), Feature.Create(1, ownerId3, space3, "space3 ownerId3") }; // CacheSwappingStorageContainer container = new CacheSwappingStorageContainer(@"MultipleQuery.dat"); foreach (Feature feature in defined) { Feature stored = m_StorageContainer.Store(feature); Assert.AreEqual(feature.Id, stored.Id); Assert.AreEqual(feature.Space, stored.Space); Assert.AreEqual(feature.OwnerId, stored.OwnerId); Assert.AreEqual(feature.Name, stored.Name); Assert.AreEqual(feature.Enabled, stored.Enabled); } /* -- Assert Owner1 All Features -- */ List <Feature> owner1Features = new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId1, Guid.Empty))); Assert.AreEqual(3, owner1Features.Count); CollectionAssert.Contains(owner1Features, defined[0]); CollectionAssert.Contains(owner1Features, defined[1]); CollectionAssert.Contains(owner1Features, defined[2]); /* -- Assert Owner2 All Features -- */ List <Feature> owner2Features = new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId2, Guid.Empty))); Assert.AreEqual(5, owner2Features.Count); CollectionAssert.Contains(owner2Features, defined[3]); CollectionAssert.Contains(owner2Features, defined[4]); CollectionAssert.Contains(owner2Features, defined[5]); CollectionAssert.Contains(owner2Features, defined[6]); CollectionAssert.Contains(owner2Features, defined[7]); /* -- Assert Owner2 Space1 Features -- */ List <Feature> owner2Space1Features = new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId2, space1))); Assert.AreEqual(3, owner2Space1Features.Count); CollectionAssert.Contains(owner2Space1Features, defined[3]); CollectionAssert.Contains(owner2Space1Features, defined[4]); CollectionAssert.Contains(owner2Space1Features, defined[5]); /* -- Assert Owner2 Space2 Features -- */ List <Feature> owner2Space2Features = new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId2, space2))); Assert.AreEqual(1, owner2Space2Features.Count); CollectionAssert.Contains(owner2Space2Features, defined[6]); /* -- Assert Owner2 Space3 Features -- */ List <Feature> owner2Space3Features = new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId2, space3))); Assert.AreEqual(1, owner2Space3Features.Count); CollectionAssert.Contains(owner2Space3Features, defined[7]); /* -- Assert Owner3 All Features -- */ List <Feature> owner3Features = new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId3, Guid.Empty))); Assert.AreEqual(3, owner3Features.Count); CollectionAssert.Contains(owner3Features, defined[8]); CollectionAssert.Contains(owner3Features, defined[9]); CollectionAssert.Contains(owner3Features, defined[10]); /* -- Assert Owner3 Space1 Features -- */ List <Feature> owner3Space1Features = new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId3, space1))); Assert.AreEqual(1, owner3Space1Features.Count); CollectionAssert.Contains(owner3Space1Features, defined[8]); /* -- Assert Owner2 Space2 Features -- */ List <Feature> owner3Space2Features = new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId3, space2))); Assert.AreEqual(1, owner3Space2Features.Count); CollectionAssert.Contains(owner3Space2Features, defined[9]); /* -- Assert Owner2 Space3 Features -- */ List <Feature> owner3Space3Features = new List <Feature>(m_StorageContainer.Retrieve(FeatureScope.Create(ownerId3, space3))); Assert.AreEqual(1, owner3Space3Features.Count); CollectionAssert.Contains(owner3Space3Features, defined[10]); }
public void ExerciseFullInterface() { Debug.WriteLine("BEGIN: ExerciseFullInterface"); CacheSwappingStorageContainer cacheSwappingStorageContainer = new CacheSwappingStorageContainer(@".\ExerciseFullInterface_Storage.dat"); StandardFeatureStore standardFeatureStore = new StandardFeatureStore(cacheSwappingStorageContainer); /* -- CreateFeature -- */ CreateFeatureRequest createFeatureRequest1 = CreateFeatureRequest.Create( Guid.NewGuid().ToString(), Feature.Create( 1, Guid.NewGuid(), Guid.NewGuid(), "Feature One")); CreateFeatureRequest createFeatureRequest2 = CreateFeatureRequest.Create( Guid.NewGuid().ToString(), Feature.Create( 2, Guid.NewGuid(), Guid.NewGuid(), "Feature Two")); CreateFeatureRequest createFeatureRequest3 = CreateFeatureRequest.Create( Guid.NewGuid().ToString(), Feature.Create( 3, Guid.NewGuid(), Guid.NewGuid(), "Feature Three")); CreateFeatureResponse createFeatureResponse = standardFeatureStore.CreateFeature(createFeatureRequest1); AssertCreateFeatureResponse(createFeatureRequest1, createFeatureResponse); createFeatureResponse = standardFeatureStore.CreateFeature(createFeatureRequest2); AssertCreateFeatureResponse(createFeatureRequest2, createFeatureResponse); createFeatureResponse = standardFeatureStore.CreateFeature(createFeatureRequest3); AssertCreateFeatureResponse(createFeatureRequest3, createFeatureResponse); AssertPerformanceCountersRecorded(PerformanceCounterReporterType.CreateFeature, false, 3); /* -- CheckFeatureState -- */ CheckFeatureStateRequest checkFeatureStateRequest1 = CheckFeatureStateRequest.Create( Guid.NewGuid().ToString(), FeatureKey.Create( createFeatureRequest1.Feature.Id, createFeatureRequest1.Feature.OwnerId, createFeatureRequest1.Feature.Space)); CheckFeatureStateResponse checkFeatureStateResponse = standardFeatureStore.CheckFeatureState(checkFeatureStateRequest1); AssertCheckFeatureStateResponse(checkFeatureStateRequest1, checkFeatureStateResponse); CheckFeatureStateRequest checkFeatureStateRequest2 = CheckFeatureStateRequest.Create( Guid.NewGuid().ToString(), FeatureKey.Create( createFeatureRequest2.Feature.Id, createFeatureRequest2.Feature.OwnerId, createFeatureRequest2.Feature.Space)); checkFeatureStateResponse = standardFeatureStore.CheckFeatureState(checkFeatureStateRequest2); AssertCheckFeatureStateResponse(checkFeatureStateRequest2, checkFeatureStateResponse); CheckFeatureStateRequest checkFeatureStateRequest3 = CheckFeatureStateRequest.Create( Guid.NewGuid().ToString(), FeatureKey.Create( createFeatureRequest3.Feature.Id, createFeatureRequest3.Feature.OwnerId, createFeatureRequest3.Feature.Space)); checkFeatureStateResponse = standardFeatureStore.CheckFeatureState(checkFeatureStateRequest3); AssertCheckFeatureStateResponse(checkFeatureStateRequest3, checkFeatureStateResponse); AssertPerformanceCountersRecorded(PerformanceCounterReporterType.CheckFeatureState, false, 3); /* -- UpdateFeatureState -- */ UpdateFeatureStateRequest updateFeatureStateRequest1 = UpdateFeatureStateRequest.Create( Guid.NewGuid().ToString(), FeatureKey.Create( createFeatureRequest1.Feature.Id, createFeatureRequest1.Feature.OwnerId, createFeatureRequest1.Feature.Space), true); UpdateFeatureStateResponse updateFeatureStateResponse = standardFeatureStore.UpdateFeatureState(updateFeatureStateRequest1); Assert.IsTrue(updateFeatureStateResponse.Result.Enabled); UpdateFeatureStateRequest updateFeatureStateRequest2 = UpdateFeatureStateRequest.Create( Guid.NewGuid().ToString(), FeatureKey.Create( createFeatureRequest2.Feature.Id, createFeatureRequest2.Feature.OwnerId, createFeatureRequest2.Feature.Space), true); updateFeatureStateResponse = standardFeatureStore.UpdateFeatureState(updateFeatureStateRequest2); Assert.IsTrue(updateFeatureStateResponse.Result.Enabled); UpdateFeatureStateRequest updateFeatureStateRequest3 = UpdateFeatureStateRequest.Create( Guid.NewGuid().ToString(), FeatureKey.Create( createFeatureRequest3.Feature.Id, createFeatureRequest3.Feature.OwnerId, createFeatureRequest3.Feature.Space), true); updateFeatureStateResponse = standardFeatureStore.UpdateFeatureState(updateFeatureStateRequest3); Assert.IsTrue(updateFeatureStateResponse.Result.Enabled); AssertPerformanceCountersRecorded(PerformanceCounterReporterType.UpdateFeatureState, false, 3); /* -- RetrieveDefinedFeatures -- */ RetrieveDefinedFeaturesRequest retrieveDefinedFeaturesRequest = RetrieveDefinedFeaturesRequest.Create( Guid.NewGuid().ToString(), FeatureScope.Create(createFeatureRequest1.Feature.OwnerId, createFeatureRequest1.Feature.Space)); RetrieveDefinedFeaturesResponse retrieveDefinedFeaturesResponse = standardFeatureStore.RetrieveDefinedFeatures(retrieveDefinedFeaturesRequest); Assert.IsNotNull(retrieveDefinedFeaturesResponse.Result); Assert.IsTrue(retrieveDefinedFeaturesResponse.Result.GetEnumerator().MoveNext()); AssertPerformanceCountersRecorded(PerformanceCounterReporterType.RetrieveDefinedFeatures, true, 1); Debug.WriteLine("END: ExerciseFullInterface"); }
public void RetrieveDefinedFeaturesExceptionThrown() { string messageId = Guid.NewGuid().ToString(); Exception exception = m_MockRepository.StrictMock <Exception>(); RetrieveDefinedFeaturesRequest request = RetrieveDefinedFeaturesRequest.Create(messageId, FeatureScope.Create( Guid.NewGuid(), Guid.NewGuid())); IFeatureStore featureStore = new StandardFeatureStore(m_StorageContainer); using (m_MockRepository.Record()) { Expect.Call(m_StorageContainer.Retrieve(request.FeatureScope)).Throw(exception); m_MockRepository.ReplayAll(); try { featureStore.RetrieveDefinedFeatures(request); Assert.Fail("Expected FeatureCreationException"); } catch (RetrieveDefinedFeaturesException) { } m_MockRepository.VerifyAll(); } }