Ejemplo n.º 1
0
        public void CheckFeatureStateThrowsFeatureStoreFaultExceptionOnException()
        {
            IStorageContainer storageContainer = m_MockRepository.StrictMock <IStorageContainer>();
            FeatureKey        key = FeatureKey.Create(1, Guid.NewGuid(), Guid.NewGuid());

            using (m_MockRepository.Record())
            {
                Expect.Call(storageContainer.Retrieve(FeatureKey.Create(key.Id, key.OwnerId, key.Space))).Throw(
                    new CheckFeatureStateException("Bad Mojo Exception"));
                m_MockRepository.ReplayAll();

                FeatureStoreService featureStoreService = new FeatureStoreService(storageContainer);

                try
                {
                    featureStoreService.CheckFeatureState(
                        CheckFeatureStateRequest.Create(
                            "CheckFeatureStateThrowsFeatureStoreFaultExceptionOnException",
                            key));

                    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 querying the data store for the Feature.");
                }

                m_MockRepository.VerifyAll();
            }
        }
Ejemplo n.º 2
0
        public void ExceptionIsRaisedAsCheckFeatureStateException()
        {
            string     messageId             = Guid.NewGuid().ToString();
            Exception  exception             = m_MockRepository.StrictMock <Exception>();
            FeatureKey query                 = FeatureKey.Create(-1, Guid.Empty, Guid.Empty);
            CheckFeatureStateRequest request = CheckFeatureStateRequest.Create(messageId, query);
            StandardFeatureStore     standardFeatureStore = new StandardFeatureStore(m_StorageContainer);

            using (m_MockRepository.Record())
            {
                Expect.Call(exception.Message).Return("Bad Mojo");
                Expect.Call(m_StorageContainer.Retrieve(query)).Throw(exception);
                m_MockRepository.ReplayAll();

                try
                {
                    standardFeatureStore.CheckFeatureState(request);
                    Assert.Fail("Expected CheckFeatureStateException");
                }
                catch (CheckFeatureStateException e)
                {
                    StringAssert.Contains(e.Message, "Id " + query.Id);
                    StringAssert.Contains(e.Message, "Space " + query.Space);
                }

                m_MockRepository.VerifyAll();
            }
        }
Ejemplo n.º 3
0
        private static CheckFeatureStateRequest BuildCheckFeatureStateRequestWithSavedFeature(string messageId)
        {
            Feature feature = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), "CheckFeatureStateFeature");

            AddFeatureToStorage(messageId, feature);
            return(CheckFeatureStateRequest.Create(messageId,
                                                   FeatureKey.Create(feature.Id, feature.OwnerId, feature.Space)));
        }
Ejemplo n.º 4
0
        public void Execute(IServiceMethodUiBridge serviceMethodUiBridge)
        {
            FeatureKey featureKey = BuildFeatureKey(serviceMethodUiBridge);

            try
            {
                CheckFeatureStateRequest request = CheckFeatureStateRequest.Create(
                    MessageIdFactory.GenerateMessageId(), featureKey);
                IFeatureStoreServiceProxy featureStoreServiceProxy = new FeatureStoreServiceProxy();
                CheckFeatureStateResponse response = featureStoreServiceProxy.CheckFeatureState(request);

                serviceMethodUiBridge.DisplayResults(BuildResultsRichText(request, response, GetType().Name));
            }
            catch (Exception e)
            {
                serviceMethodUiBridge.DisplayResults(BuildExceptionRichText(e));
            }
        }
Ejemplo n.º 5
0
        public void NonExistentFeatureResultsInNullResult()
        {
            string     messageId             = Guid.NewGuid().ToString();
            FeatureKey query                 = FeatureKey.Create(-1, Guid.Empty, Guid.Empty);
            CheckFeatureStateRequest request = CheckFeatureStateRequest.Create(messageId, query);
            StandardFeatureStore     standardFeatureStore = new StandardFeatureStore(m_StorageContainer);

            using (m_MockRepository.Record())
            {
                Expect.Call(m_StorageContainer.Retrieve(query)).Return(null);

                m_MockRepository.ReplayAll();

                CheckFeatureStateResponse response = standardFeatureStore.CheckFeatureState(request);

                Assert.AreEqual(messageId, response.Header.MessageId);
                Assert.IsNull(response.Result);
                m_MockRepository.VerifyAll();
            }
        }
Ejemplo n.º 6
0
        /// <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;
                }
            }
        }
Ejemplo n.º 7
0
        public void Execute(IServiceMethodUiBridge serviceMethodUiBridge)
        {
            m_ServiceMethodUiBridge = serviceMethodUiBridge;
            AsyncOperation asyncOperation = AsyncOperationManager.CreateOperation(m_AsyncKey);

            FeatureKey featureKey = BuildFeatureKey(serviceMethodUiBridge);

            try
            {
                CheckFeatureStateRequest request = CheckFeatureStateRequest.Create(
                    MessageIdFactory.GenerateMessageId(), featureKey);
                IFeatureStoreServiceProxy featureStoreServiceProxy = new FeatureStoreServiceProxy();

                featureStoreServiceProxy.BeginCheckFeatureState(
                    request,
                    ar =>
                {
                    string rtfResults;
                    try
                    {
                        CheckFeatureStateResponse response = featureStoreServiceProxy.EndCheckFeatureState(ar);
                        rtfResults = BuildResultsRichText(request, response, GetType().Name);
                    }
                    catch (Exception e)
                    {
                        rtfResults = BuildExceptionRichText(e);
                    }
                    asyncOperation.PostOperationCompleted(HandleEndAsync, rtfResults);
                },
                    null);
            }
            catch (Exception e)
            {
                serviceMethodUiBridge.DisplayResults(BuildExceptionRichText(e));
            }
        }
Ejemplo n.º 8
0
        public void QueryExistingFeature()
        {
            string     messageId                      = Guid.NewGuid().ToString();
            Guid       space                          = Guid.NewGuid();
            Guid       owner                          = Guid.NewGuid();
            FeatureKey query                          = FeatureKey.Create(1, owner, space);
            CheckFeatureStateRequest request          = CheckFeatureStateRequest.Create(messageId, query);
            Feature foundFeature                      = Feature.Create(1, owner, space, FeatureName);
            StandardFeatureStore standardFeatureStore = new StandardFeatureStore(m_StorageContainer);

            using (m_MockRepository.Record())
            {
                Expect.Call(m_StorageContainer.Retrieve(query)).Return(foundFeature);

                m_MockRepository.ReplayAll();

                CheckFeatureStateResponse response = standardFeatureStore.CheckFeatureState(request);

                Assert.AreEqual(messageId, response.Header.MessageId);
                Assert.IsNotNull(response);
                Assert.IsFalse(response.Result.Enabled);
                m_MockRepository.VerifyAll();
            }
        }
Ejemplo n.º 9
0
        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");
        }