public void UpdateHandlerReturnsMockDefinitionTest() { #region Test Setup var metadataFake = new Faker <MetadataInfo>() .RuleFor(m => m.Title, f => f.Lorem.Sentence()) .RuleFor(m => m.Description, f => f.Lorem.Paragraph()); var mockDefinitionFake = new Faker <MockDefinition>() .RuleFor(m => m.Host, f => f.Internet.DomainName()) .RuleFor(m => m.Metadata, f => metadataFake.Generate()); var options = new MemoryCacheOptions(); var cache = new MemoryCache(options); var Expected = mockDefinitionFake.Generate(); var mockDefinitionUpdate = new MockDefinition { Host = Expected.Host + "diff", Metadata = Expected.Metadata }; cache.Set(Expected.Metadata.Title, Expected); var updateMockDefinitionCommand = new UpdateMockDefinitionByTitleCommand(mockDefinitionUpdate, ref TestUtils.databaseLock); #endregion var Target = new UpdateMockDefinitionHandler(cache, data); var Actual = Target.Handle(updateMockDefinitionCommand, CancellationToken.None).Result; Assert.Equal(Expected, Actual); }
public IActionResult Post([FromBody] MockDefinition mockDefinition) { var command = new SaveMockDefinitionCommand(mockDefinition, ref databaseLock); this.mediator.Send(command).Wait(); Log.Information("OrbitalAdminController: Sent HTTPPost Command to save Mockdefinition, {MockDefinition}", mockDefinition.Metadata.Title); return(Created(new Uri($"{Request.Path}/{mockDefinition.Metadata.Title}", UriKind.Relative), mockDefinition)); }
public IActionResult Put([FromBody] MockDefinition mockDefinition) { var command = new UpdateMockDefinitionByTitleCommand(mockDefinition, ref databaseLock); var result = mediator.Send(command).Result; if (result == null) { return(Created(new Uri($"{Request.Path}/{mockDefinition.Metadata.Title}", UriKind.Relative), mockDefinition)); } Log.Information("OrbitalAdminController: Sent HTTPut Command to update Mockdefinition, {MockDefinition}", mockDefinition.Metadata.Title); return(Ok()); }
public static string GetMockDefinitionText(MockDefinition mockDefinition) { var fullPathMockDefinition = File.ReadAllText(GetFullPathToMockDefinition(mockDefinition)); try { JObject.Parse(fullPathMockDefinition); } catch (JsonReaderException e) { throw e; } return(fullPathMockDefinition); }
public static string GetFullPathToMockDefinition(MockDefinition mockDefinition) { switch (mockDefinition) { case MockDefinition.DefaultMock: return(@"./MockDefinitions/PetStoreMockDefinition.json"); case MockDefinition.BodyMock: return(@"./MockDefinitions/PetStoreMockDefinitionBody.json"); case MockDefinition.HeaderMock: return(@"./MockDefinitions/PetStoreMockDefinitionHeaders.json"); case MockDefinition.EndpointMock: return(@"./MockDefinitions/PetStoreMockDefinitionEndpoint.json"); case MockDefinition.BodyJsonContains: return(@"./MockDefinitions/PetStoreMockDefinitionBodyJsonContains.json"); case MockDefinition.QueryMock: return(@"./MockDefinitions/PetStoreMockDefinitionQuery.json"); case MockDefinition.UrlMock: return(@"./MockDefinitions/PetStoreMockDefinitionUrl.json"); case MockDefinition.PolicyMock: return(@"./MockDefinitions/PetStoreMockDefinitionPolicy.json"); case MockDefinition.BodyJsonPathMock: return(@"./MockDefinitions/PetStoreBaseMockDefinitionBodyJsonPath.json"); case MockDefinition.DefaultScenarioMock: return(@"./MockDefinitions/PetStoreMockDefinitionDefaultScenario.json"); case MockDefinition.TemplatedResponseMock: return(@"./MockDefinitions/PetStoreMockDefinitionTemplatedResponse.json"); case MockDefinition.DefaultScenarioWithTieBreakerMock: return(@"./MockDefinitions/PetStoreMockDefinitionDefaultResponseTieBreaker.json"); default: return(@"./MockDefinitions/PetStoreMockDefinitionHeaders.json"); } }
public void GetAllEntriesSuccessTest() { #region Test Setup var metadataFake = new Faker <MetadataInfo>() .RuleFor(m => m.Title, f => f.Lorem.Sentence()) .RuleFor(m => m.Description, f => f.Lorem.Paragraph()); var mockDefinitionFake = new Faker <MockDefinition>() .RuleFor(m => m.Host, f => f.Internet.DomainName()) .RuleFor(m => m.Metadata, f => metadataFake.Generate()); var options = new MemoryCacheOptions(); var cache = new MemoryCache(options); var mockdeffake1 = mockDefinitionFake.Generate(); var mockdeffake2 = new MockDefinition { Host = mockdeffake1.Host + "diff", Metadata = mockdeffake1.Metadata }; cache.Set(data.mockIds, new List <string> { mockdeffake1.Metadata.Title, mockdeffake2.Metadata.Title }); cache.Set(mockdeffake1.Metadata.Title, mockdeffake1); cache.Set(mockdeffake2.Metadata.Title, mockdeffake2); var getAllMockDefinitionsCommand = new GetAllMockDefinitionsCommand(ref TestUtils.databaseLock); var Target = new GetAllMockDefinitionsHandler(cache, data); var Actual = Target.Handle(getAllMockDefinitionsCommand, CancellationToken.None).Result.ToList(); Assert.Equal(2, Actual.Count); Assert.Equal(mockdeffake1.Metadata.Title, Actual[0].Metadata.Title); Assert.Equal(mockdeffake2.Metadata.Title, Actual[1].Metadata.Title); #endregion }
/// <summary> /// Constructor /// </summary> /// <param name="mockDefinition">Mock definition to store in cache</param> /// <param name="databaseLock">The database lock</param> public SaveMockDefinitionCommand(MockDefinition mockDefinition, ref object databaseLock) { this.MockDefinition = mockDefinition; this.databaseLock = databaseLock; }