public async Task UpdateTestResultsForSpecification_GivenNoChangesDetected_LogsAndReturns() { //Arrange const string specificationId = "spec-id"; Models.Specs.SpecificationVersionComparisonModel specificationVersionComparison = new Models.Specs.SpecificationVersionComparisonModel() { Id = specificationId, Current = new Models.Specs.SpecificationVersion { Name = "any name" }, Previous = new Models.Specs.SpecificationVersion { Name = "any name" } }; string json = JsonConvert.SerializeObject(specificationVersionComparison); Message message = new Message(Encoding.UTF8.GetBytes(json)); ILogger logger = CreateLogger(); TestResultsService service = CreateTestResultsService(logger: logger); //Act await service.UpdateTestResultsForSpecification(message); //Assert logger .Received(1) .Information(Arg.Is($"No changes detected")); }
public async Task UpdateTestResultsForSpecification_GivenNoResultsFoundInSearch_DoesNotUpdateSearch() { //Arrange const string specificationId = "spec-id"; Models.Specs.SpecificationVersionComparisonModel specificationVersionComparison = new Models.Specs.SpecificationVersionComparisonModel() { Id = specificationId, Current = new Models.Specs.SpecificationVersion { Name = "new name" }, Previous = new Models.Specs.SpecificationVersion { Name = "any name" } }; string json = JsonConvert.SerializeObject(specificationVersionComparison); Message message = new Message(Encoding.UTF8.GetBytes(json)); ILogger logger = CreateLogger(); SearchResults <TestScenarioResultIndex> searchResult = new SearchResults <TestScenarioResultIndex>(); ISearchRepository <TestScenarioResultIndex> searchRepository = CreateSearchRespository(); searchRepository .Search(Arg.Is(""), Arg.Any <SearchParameters>()) .Returns(searchResult); TestResultsService service = CreateTestResultsService(logger: logger, searchRepository: searchRepository); //Act await service.UpdateTestResultsForSpecification(message); //Assert await searchRepository .Received(1) .Search(Arg.Is(""), Arg.Is <SearchParameters>( m => m.Skip == 0 && m.Top == 1000 && m.SearchMode == SearchMode.Any && m.Filter == $"specificationId eq '{specificationVersionComparison.Id}' and specificationName ne '{specificationVersionComparison.Current.Name}'" )); await searchRepository .DidNotReceive() .Index(Arg.Any <IEnumerable <TestScenarioResultIndex> >()); }
public void UpdateTestResultsForSpecification_GivenInvalidModel_LogsDoesNotSave() { //Arrange dynamic anyObject = new { something = 1 }; string json = JsonConvert.SerializeObject(anyObject); Message message = new Message(Encoding.UTF8.GetBytes(json)); TestResultsService service = CreateTestResultsService(); //Act Func <Task> test = async() => await service.UpdateTestResultsForSpecification(message); //Assert test .Should() .ThrowExactly <InvalidModelException>(); }
public async Task UpdateTestResultsForSpecification_GivenResultsReturnedButIndexeingCausesErrors_LogsErrors() { //Arrange const string specificationId = "spec-id"; Models.Specs.SpecificationVersionComparisonModel specificationVersionComparison = new Models.Specs.SpecificationVersionComparisonModel() { Id = specificationId, Current = new Models.Specs.SpecificationVersion { Name = "new name" }, Previous = new Models.Specs.SpecificationVersion { Name = "any name" } }; string json = JsonConvert.SerializeObject(specificationVersionComparison); Message message = new Message(Encoding.UTF8.GetBytes(json)); ILogger logger = CreateLogger(); SearchResults <TestScenarioResultIndex> searchResult = new SearchResults <TestScenarioResultIndex> { Results = new List <CalculateFunding.Repositories.Common.Search.SearchResult <TestScenarioResultIndex> > { new CalculateFunding.Repositories.Common.Search.SearchResult <TestScenarioResultIndex> { Result = new TestScenarioResultIndex() }, new CalculateFunding.Repositories.Common.Search.SearchResult <TestScenarioResultIndex> { Result = new TestScenarioResultIndex() }, new CalculateFunding.Repositories.Common.Search.SearchResult <TestScenarioResultIndex> { Result = new TestScenarioResultIndex() } } }; IEnumerable <IndexError> indexErrors = new[] { new IndexError { ErrorMessage = "an error" } }; ISearchRepository <TestScenarioResultIndex> searchRepository = CreateSearchRespository(); searchRepository .Search(Arg.Is(""), Arg.Any <SearchParameters>()) .Returns(searchResult); searchRepository .Index(Arg.Any <IEnumerable <TestScenarioResultIndex> >()) .Returns(indexErrors); TestResultsService service = CreateTestResultsService(logger: logger, searchRepository: searchRepository); //Act await service.UpdateTestResultsForSpecification(message); //Assert await searchRepository .Received(1) .Search(Arg.Is(""), Arg.Is <SearchParameters>( m => m.Skip == 0 && m.Top == 1000 && m.SearchMode == SearchMode.Any && m.Filter == $"specificationId eq '{specificationVersionComparison.Id}' and specificationName ne '{specificationVersionComparison.Current.Name}'" )); await searchRepository .Received(1) .Index(Arg.Is <IEnumerable <TestScenarioResultIndex> >(m => m.Count() == 3)); logger .Received(1) .Error($"The following errors occcurred while updating test results for specification id: {specificationId}, an error"); }