/// <summary> /// Asserts the create feature response. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> /// <remarks></remarks> private static void AssertCreateFeatureResponse(CreateFeatureRequest request, CreateFeatureResponse response) { Assert.AreEqual(request.Header.MessageId, response.Header.MessageId); Assert.AreEqual(request.Feature.Id, response.Result.Id); Assert.AreEqual(request.Feature.Space, response.Result.Space); Assert.AreEqual(request.Feature.Name, response.Result.Name); }
/// <summary> /// Executes the specified service method completion sink. /// </summary> /// <param name = "serviceMethodUiBridge">The service method completion sink.</param> public void Execute(IServiceMethodUiBridge serviceMethodUiBridge) { m_ServiceMethodUiBridge = serviceMethodUiBridge; AsyncOperation asyncOperation = AsyncOperationManager.CreateOperation(m_AsyncKey); try { Feature feature = BuildFeature(serviceMethodUiBridge); CreateFeatureRequest request = CreateFeatureRequest.Create(MessageIdFactory.GenerateMessageId(), feature); IFeatureStoreServiceProxy featureStoreServiceProxy = new FeatureStoreServiceProxy(); featureStoreServiceProxy.BeginCreateFeature( request, ar => { string rtfResults; try { CreateFeatureResponse response = featureStoreServiceProxy.EndCreateFeature(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)); } }
/// <summary> /// Stores a feature that can be queried and updated. /// </summary> /// <param name = "request"><see cref = "CreateFeatureRequest" /> instance that defines the state required to create a new Feature.</param> /// <returns> /// <see cref = "CreateFeatureResponse" /> containing the results of the request to create a new Feature. /// </returns> public CreateFeatureResponse CreateFeature(CreateFeatureRequest request) { CreateFeatureResponse response; using (PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.CreateFeature)) { Feature feature; EnsureOwnerId(request.Feature); CheckDuplicateKey(request.Feature); try { feature = m_StorageContainer.Store(request.Feature); } catch (Exception e) { CreateFeatureException createFeatureException = new CreateFeatureException(ExceptionMessageResources.FEATURE_CREATION_EXCEPTION, e); m_Logger.Error(createFeatureException); throw createFeatureException; } response = CreateFeatureResponse.Create(request.Header.MessageId, feature); LogInteraction(request, response); } return(response); }
public void CreateFeatureExceptionThrownWhenCreationFails() { string messageId = Guid.NewGuid().ToString(); Exception exception = m_MockRepository.StrictMock <Exception>(); Feature toCreate = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), FeatureName); CreateFeatureRequest request = CreateFeatureRequest.Create(messageId, toCreate); IFeatureStore featureStore = new StandardFeatureStore(m_StorageContainer); using (m_MockRepository.Record()) { Expect.Call(exception.Message).Return("Bad Mojo"); Expect.Call(m_StorageContainer.Retrieve(FeatureKey.Create(toCreate.Id, toCreate.OwnerId, toCreate.Space))) .Return(null); Expect.Call(m_StorageContainer.Store(toCreate)).Throw(exception); m_MockRepository.ReplayAll(); try { featureStore.CreateFeature(request); Assert.Fail("Expected FeatureCreationException"); } catch (CreateFeatureException) { } m_MockRepository.VerifyAll(); } }
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(); } }
public void ProxyCanCallCreateFeatureAsynchronouslyWithCallback() { const string messageId = "ProxyCanCallCreateFeatureAsynchronouslyWithCallback"; ManualResetEvent resetEvent = new ManualResetEvent(false); CreateFeatureRequest request = BuildCreateFeatureRequest(messageId); CreateFeatureResponse response = null; m_FeatureStoreServiceProxy.BeginCreateFeature( request, r => { try { response = m_FeatureStoreServiceProxy.EndCreateFeature(r); resetEvent.Set(); } catch (Exception e) { Console.WriteLine(e); } }, null); resetEvent.WaitOne(); AssertCreateFeatureValues(request, response); }
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(); } }
public void CreateFeatureFailsWhenDuplicateKeyProvided() { string messageId = Guid.NewGuid().ToString(); Feature toCreate = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), FeatureName); IFeatureStore featureStore = new StandardFeatureStore(m_StorageContainer); using (m_MockRepository.Record()) { Expect.Call(m_StorageContainer.Retrieve(FeatureKey.Create(toCreate.Id, toCreate.OwnerId, toCreate.Space))) .Return(toCreate); m_MockRepository.ReplayAll(); try { featureStore.CreateFeature(CreateFeatureRequest.Create(messageId, toCreate)); Assert.Fail("Expected FeatureCreationException due to duplicate key violation."); } catch (CreateFeatureException e) { StringAssert.Contains(e.Message, "duplicate key violation"); StringAssert.Contains(e.Message, "Id"); StringAssert.Contains(e.Message, "OwnerId"); StringAssert.Contains(e.Message, "Space"); } } }
public void GivenARequestIsNUll_WhenValidating_ThenArgumentNullIsThrown() { CreateFeatureRequest request = null; request .WhenValidating() .ThenExceptionIsThrown <ArgumentValidationException>(); }
public IActionResult Post(CreateFeatureRequest request) { var command = new CreateFeatureCommand(request.Label, request.Description, request.Action, request.Controller, request.ControllerActionName, request.CreatedBy); Result result = _dispatcher.Dispatch(command); return(FromResult(result)); }
private static CreateFeatureRequest BuildCreateFeatureRequest(string messageId) { return(CreateFeatureRequest.Create( messageId, Feature.Create( 1, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid().ToString()))); }
/// <summary> /// Initializes the feature store service with the seed data features. /// </summary> private void SeedStore() { IFeatureStoreServiceProxy proxy = new FeatureStoreServiceProxy(); foreach (Feature standardFeature in m_StandardFeatures) { proxy.CreateFeature(CreateFeatureRequest.Create(standardFeature.Name, standardFeature)); } }
public void ProxyCanCallCreateFeatureAsynchronouslyWithBlocking() { const string messageId = "ProxyCanCallCreateFeatureAsynchronouslyWithBlocking"; CreateFeatureRequest request = BuildCreateFeatureRequest(messageId); IAsyncResult result = m_FeatureStoreServiceProxy.BeginCreateFeature(request, null, null); result.AsyncWaitHandle.WaitOne(); CreateFeatureResponse response = m_FeatureStoreServiceProxy.EndCreateFeature(result); AssertCreateFeatureValues(request, response); }
public void ProxyCanCallCreateFeatureAsynchronouslyWithPolling() { const string messageId = "ProxyCanCallCreateFeatureAsynchronouslyWithPolling"; CreateFeatureRequest request = BuildCreateFeatureRequest(messageId); IAsyncResult result = m_FeatureStoreServiceProxy.BeginCreateFeature(request, null, null); while (!result.IsCompleted) { } CreateFeatureResponse response = m_FeatureStoreServiceProxy.EndCreateFeature(result); AssertCreateFeatureValues(request, response); }
/// <summary> /// Builds the results rich text. /// </summary> /// <param name = "request">The request.</param> /// <param name = "response">The response.</param> /// <param name = "commandName">Name of the command.</param> /// <returns></returns> protected string BuildResultsRichText(CreateFeatureRequest request, CreateFeatureResponse response, string commandName) { StringBuilder builder = new StringBuilder(RtfResources.RTF_PREAMBLE); builder.AppendFormat(CultureInfo.CurrentUICulture, RtfResources.RTF_HEADER_FORMAT, commandName); builder.Append(RtfResources.REQUEST_SECTION); builder.Append(BuildMessageHeaderRichText(request.Header)); builder.Append(BuildFeatureRichText(request.Feature)); builder.Append(RtfResources.RESPONSE_SECTION); builder.Append(BuildMessageHeaderRichText(response.Header)); builder.Append(BuildFeatureRichText(response.Result)); builder.Append(RtfResources.RTF_CLOSE); return(builder.ToString()); }
public async Task <IActionResult> AddFeature([FromBody] CreateFeatureRequest request) { var feature = new Feature() { Name = request.Name, IsCalculated = request.IsCalculated, IsSearchFeature = request.IsSearchFeature, WeightRate = request.WeightRate, }; feature = await _featureApplication.AddFeature(feature); await SetUpdateScore(); return(Ok(feature)); }
public void AttemptingToAddFeatureWithEmptyOwnerIdThrowsCreateFeatureException() { string messageId = Guid.NewGuid().ToString(); Feature toCreate = Feature.Create(1, Guid.Empty, Guid.NewGuid(), FeatureName); IFeatureStore featureStore = new StandardFeatureStore(m_StorageContainer); try { featureStore.CreateFeature(CreateFeatureRequest.Create(messageId, toCreate)); Assert.Fail("Expected FeatureCreationException due to duplicate key violation."); } catch (CreateFeatureException e) { StringAssert.Contains(e.Message, "A non-empty OwnerId must be provided"); } }
public void Execute(IServiceMethodUiBridge serviceMethodUiBridge) { Feature feature = BuildFeature(serviceMethodUiBridge); try { CreateFeatureRequest request = CreateFeatureRequest.Create(MessageIdFactory.GenerateMessageId(), feature); IFeatureStoreServiceProxy featureStoreServiceProxy = new FeatureStoreServiceProxy(); CreateFeatureResponse response = featureStoreServiceProxy.CreateFeature(request); serviceMethodUiBridge.DisplayResults(BuildResultsRichText(request, response, GetType().Name)); } catch (Exception e) { serviceMethodUiBridge.DisplayResults(BuildExceptionRichText(e)); } }
public void ProxyCanCallCreateFeatureSynchronously() { const string messageId = "ProxyCanCallCreateFeatureSynchronously"; Feature feature = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), "Testing 1-2-3"); CreateFeatureResponse response = m_FeatureStoreServiceProxy.CreateFeature( CreateFeatureRequest.Create(messageId, feature)); Assert.IsNotNull(response.Result); Assert.AreEqual(messageId, response.Header.MessageId); Assert.AreEqual(feature.Enabled, response.Result.Enabled); Assert.AreEqual(feature.Id, response.Result.Id); Assert.AreEqual(feature.Name, response.Result.Name); Assert.AreEqual(feature.OwnerId, response.Result.OwnerId); Assert.AreEqual(feature.Space, response.Result.Space); }
/// <summary> /// Stores a feature that can be queried and updated. /// </summary> /// <param name = "request"><see cref = "CreateFeatureRequest" /> instance that defines the state required to create a new Feature.</param> /// <returns> /// <see cref = "CreateFeatureResponse" /> containing the results of the request to create a new Feature. /// </returns> public CreateFeatureResponse CreateFeature(CreateFeatureRequest request) { CreateFeatureResponse response; try { response = m_FeatureStoreImp.CreateFeature(request); } catch (CreateFeatureException e) { throw new FaultException <FeatureStoreFault>( FeatureStoreFault.Create(e.Message), new FaultReason( new FaultReasonText( e.Message, CultureInfo.CurrentCulture))); } return(response); }
/// <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; } } }
public static Action WhenValidating(this CreateFeatureRequest request) { return(() => request.Validate()); }
private static void AddFeatureToStorage(string messageId, Feature feature) { m_FeatureStoreServiceProxy.CreateFeature(CreateFeatureRequest.Create(messageId, feature)); }
public static Func <CreateFeatureCommand> WhenExtractingCommand(this CreateFeatureRequest request) { return(() => request.ToCreateFeatureCommand()); }
public static void ThenCommandIsFilled(this Func <CreateFeatureCommand> createFunc, CreateFeatureRequest request) { var command = createFunc(); command.Name.Should().Be(request.Name); command.Path.Should().BeEquivalentTo(request.Path); command.CreatedBy.Should().BeEquivalentTo(request.CreatedBy); }
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 static Func <Task <IActionResult> > WhenProcessingCommand( this CreateFeatureController controller, CreateFeatureRequest request) { return(() => controller.Put(request)); }
/// <summary> /// Stores a feature that can be queried and updated. /// </summary> /// <param name = "request"><see cref = "CreateFeatureRequest" /> instance that defines the state required to create a new Feature.</param> /// <returns> /// <see cref = "CreateFeatureResponse" /> containing the results of the request to create a new Feature. /// </returns> public CreateFeatureResponse CreateFeature(CreateFeatureRequest request) { return(Channel.CreateFeature(request)); }
/// <summary> /// Begins the create feature. /// </summary> /// <param name = "request">The request.</param> /// <param name = "callback">The callback.</param> /// <param name = "state">The state.</param> /// <returns><see cref = "IAsyncResult" /> instance used to query the state of the asynchronous operation.</returns> public IAsyncResult BeginCreateFeature(CreateFeatureRequest request, AsyncCallback callback, object state) { return(Channel.BeginCreateFeature(request, callback, state)); }