Ejemplo n.º 1
0
        /// <summary>
        ///   Checks the state of an existing Feature.
        /// </summary>
        /// <param name = "request"><see cref = "CheckFeatureStateRequest" /> instance that defines the criteria by which the Feature will be queried.</param>
        /// <returns>
        ///   <see cref = "CheckFeatureStateResponse" /> containing the results of the request for the state of a Feature.
        /// </returns>
        public CheckFeatureStateResponse CheckFeatureState(CheckFeatureStateRequest request)
        {
            CheckFeatureStateResponse response;

            using (PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.CheckFeatureState))
            {
                Feature feature;

                try
                {
                    feature = m_StorageContainer.Retrieve(request.Key);
                }
                catch (Exception e)
                {
                    CheckFeatureStateException checkFeatureStateException =
                        new CheckFeatureStateException(
                            string.Format(
                                CultureInfo.CurrentUICulture,
                                ExceptionMessageResources.CHECK_FEATURE_STATE_EXCEPTION,
                                request.Key.Id,
                                request.Key.Space),
                            e);
                    m_Logger.Error(checkFeatureStateException);

                    throw checkFeatureStateException;
                }

                response = CheckFeatureStateResponse.Create(request.Header.MessageId, feature);
                LogInteraction(request, response);
            }

            return(response);
        }
Ejemplo n.º 2
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.º 3
0
        public void CreateFeatureThrowsFeatureStoreFaultExceptionOnException()
        {
            IStorageContainer storageContainer = m_MockRepository.StrictMock <IStorageContainer>();
            Feature           feature          = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(),
                                                                "CreateFeatureThrowsCreateFeatureFaultOnException");

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

                FeatureStoreService featureStoreService = new FeatureStoreService(storageContainer);

                try
                {
                    featureStoreService.CreateFeature(
                        CreateFeatureRequest.Create(
                            "CreateFeatureThrowsCreateFeatureFaultOnException",
                            feature));

                    Assert.Fail("Expecting FaultException<FeatureStoreFault>");
                }
                catch (FaultException <FeatureStoreFault> e)
                {
                    Console.WriteLine(e.Detail.Message);
                    Console.WriteLine(e.Message);
                    StringAssert.Contains(e.Detail.Message, "Bad Mojo Exception");
                }

                m_MockRepository.VerifyAll();
            }
        }
Ejemplo n.º 4
0
        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();
            }
        }
Ejemplo n.º 5
0
        public void CreateFeature()
        {
            Feature toCreate = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), FeatureName);

            IStorageContainer container = m_MockRepository.StrictMock <IStorageContainer>();
            string            messageId = Guid.NewGuid().ToString();

            using (m_MockRepository.Record())
            {
                Expect.Call(container.Retrieve(FeatureKey.Create(toCreate.Id, toCreate.OwnerId, toCreate.Space))).Return
                    (null);
                Expect.Call(container.Store(toCreate)).Return(toCreate);
                m_MockRepository.ReplayAll();

                StandardFeatureStore service = new StandardFeatureStore(container);

                CreateFeatureRequest request = CreateFeatureRequest.Create(messageId, toCreate);

                CreateFeatureResponse response = service.CreateFeature(request);

                Assert.AreEqual(messageId, response.Header.MessageId);
                Assert.AreEqual(toCreate.Id, response.Result.Id);
                Assert.AreEqual(toCreate.Name, response.Result.Name);
                Assert.AreEqual(toCreate.Space, response.Result.Space);
                Assert.AreEqual(toCreate.OwnerId, response.Result.OwnerId);

                m_MockRepository.VerifyAll();
            }
        }
Ejemplo n.º 6
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.º 7
0
        public void MultipleFeaturesCanBeAddedToStorageAndQueriedIndividually()
        {
            const string featureNameBase = "Feature Name ";
            const int    count           = 5;

            Guid[] spaces = new Guid[count];
            Guid[] owners = new Guid[count];

            for (int index = 0; index < count; index++)
            {
                spaces[index] = Guid.NewGuid();
                owners[index] = Guid.NewGuid();

                Feature feature = Feature.Create(index, owners[index], spaces[index], featureNameBase + index);
                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.IsFalse(stored.Enabled);
            }

            for (int index = 0; index < 5; index++)
            {
                Feature retrieved = m_StorageContainer.Retrieve(FeatureKey.Create(index, owners[index], spaces[index]));

                Assert.IsNotNull(retrieved);

                Assert.AreEqual(index, retrieved.Id);
                Assert.AreEqual(spaces[index], retrieved.Space);
                Assert.AreEqual(owners[index], retrieved.OwnerId);
                Assert.AreEqual(featureNameBase + index, retrieved.Name);
                Assert.IsFalse(retrieved.Enabled);
            }

            Assert.IsNull(m_StorageContainer.Retrieve(FeatureKey.Create(2112, Guid.Empty, Guid.Empty)));
        }