public async void UpdateMarkSessionType_ValidMarkSessionId_ReturnsUpdatedMarkSessionModel() { // Arrange var markSessionId = "5ae86f68b90b230007d7ea34"; var markSessionType = MarkSessionTypeEnum.ToBeArchived; var markSessionModel = MarkSessionModelDataMocks.MockMarkSessionModel(); var markSessionRepository = new Mock <IMarkSessionRepository>(); markSessionRepository .Setup(m => m.GetForFilter(It.IsAny <FilterDefinition <MarkSessionModel> >())) .ReturnsAsync(markSessionModel); markSessionRepository .Setup(m => m.Update(It.IsAny <MarkSessionModel>())) .Returns(Task.CompletedTask); var dependantResourceHandler = new Mock <IDependantResourceHandler>(); var backgroundJobsHandler = new Mock <IBackgroundJobsHandler>(); var loggerService = new Mock <ILoggerService>(); var markSessionHandler = new MarkSessionHandler( markSessionRepository.Object, dependantResourceHandler.Object, backgroundJobsHandler.Object, loggerService.Object ); // Act await markSessionHandler.UpdateMarkSessionType(markSessionId, markSessionType); // Assert Assert.Equal(markSessionType, markSessionModel.MarkSessionType); }
UnmarkResourcesForMarkSession_ProjectMarkSessionModel_ReturnsMarkSessionWithoutDependantResources() { // Arrange var markSessionModel = MarkSessionModelDataMocks.MockMarkSessionModel(); var markSessionRepository = new Mock <IMarkSessionRepository>(); var projectClient = new Mock <IProjectClient>(); var metadataClient = new Mock <IMetadataClient>(); var scenarioClient = new Mock <IScenarioClient>(); var resultConfigClient = new Mock <IResultConfigClient>(); var simPlanClient = new Mock <ISimPlanClient>(); var simRunClient = new Mock <ISimRunClient>(); var resultDataClient = new Mock <IResultDataClient>(); var dependantResourceHandler = new DependantResourceHandler( projectClient.Object, markSessionRepository.Object, metadataClient.Object, scenarioClient.Object, resultConfigClient.Object, simPlanClient.Object, simRunClient.Object, resultDataClient.Object ); // Act await dependantResourceHandler.UnmarkResourcesForMarkSession(markSessionModel); // Assert Assert.Empty(markSessionModel.DependantResources); }
public async void GetMarkSessionsByMarkSessionType_ValidMarkSessionType_ReturnsMarkSessionModelList() { // Arrange var markSessionType = MarkSessionTypeEnum.ToBeDeleted; var markSessionRepository = new Mock <IMarkSessionRepository>(); markSessionRepository .Setup(m => m.GetAllForFilter(It.IsAny <FilterDefinition <MarkSessionModel> >())) .ReturnsAsync(MarkSessionModelDataMocks.MockMarkSessionModelList()); var dependantResourceHandler = new Mock <IDependantResourceHandler>(); var backgroundJobsHandler = new Mock <IBackgroundJobsHandler>(); var loggerService = new Mock <ILoggerService>(); var markSessionHandler = new MarkSessionHandler( markSessionRepository.Object, dependantResourceHandler.Object, backgroundJobsHandler.Object, loggerService.Object ); // Act var result = await markSessionHandler.GetMarkSessionsByMarkSessionType(markSessionType); // Assert Assert.NotEmpty(result); }
public async void Update_ValidMarkSessionModel_NoExceptionThrown() { // Arrange var markSessionModel = MarkSessionModelDataMocks.MockMarkSessionModel(); var markSessionCollection = new Mock <IMongoCollection <MarkSessionModel> >(); markSessionCollection .Setup(m => m.ReplaceOneAsync( It.IsAny <FilterDefinition <MarkSessionModel> >(), It.IsAny <MarkSessionModel>(), It.IsAny <UpdateOptions>(), It.IsAny <CancellationToken>() )).ReturnsAsync(It.IsAny <ReplaceOneResult>()); var dbMongoService = new Mock <IDbMongoService>(); dbMongoService .Setup(m => m.GetMarkSessionCollection()) .Returns(markSessionCollection.Object); var markSessionRepository = new MarkSessionRepository(dbMongoService.Object); Exception exception = null; try { // Act await markSessionRepository.Update(markSessionModel); } catch (Exception e) { exception = e; } // Assert Assert.Null(exception); }
public async void Delete_MarkSessionModelWithoutDependantResources_NoExceptionThrown() { // Arrange var markSessionModel = MarkSessionModelDataMocks.MockMarkSessionModel(); markSessionModel.SourceDependency = null; markSessionModel.DependantResources = new List <DependantResourceModel>(); var markSessionCollection = new Mock <IMongoCollection <MarkSessionModel> >(); markSessionCollection .Setup(m => m.DeleteOneAsync( It.IsAny <FilterDefinition <MarkSessionModel> >(), It.IsAny <CancellationToken>() )).ReturnsAsync(It.IsAny <DeleteResult>()); var dbMongoService = new Mock <IDbMongoService>(); dbMongoService .Setup(m => m.GetMarkSessionCollection()) .Returns(markSessionCollection.Object); var markSessionRepository = new MarkSessionRepository(dbMongoService.Object); Exception exception = null; try { // Act await markSessionRepository.Delete(markSessionModel); } catch (CannotDeleteMarkSessionException e) { exception = e; } // Assert Assert.Null(exception); }
public async void DeleteDependantResourcesForMarkSession_MarkSessionModel_NoExceptionThrown() { // Arrange var fileClient = new Mock <IFileClient>(); fileClient .Setup(m => m.DeleteResource(It.IsAny <DependantResourceModel>())) .Returns(Task.CompletedTask); var scenarioClient = new Mock <IScenarioClient>(); scenarioClient .Setup(m => m.DeleteResource(It.IsAny <DependantResourceModel>())) .Returns(Task.CompletedTask); var resultConfigClient = new Mock <IResultConfigClient>(); resultConfigClient .Setup(m => m.DeleteResource(It.IsAny <DependantResourceModel>())) .Returns(Task.CompletedTask); var simPlanClient = new Mock <ISimPlanClient>(); simPlanClient .Setup(m => m.DeleteResource(It.IsAny <DependantResourceModel>(), It.IsAny <string>())) .Returns(Task.CompletedTask); var simRunClient = new Mock <ISimRunClient>(); simRunClient .Setup(m => m.DeleteResource(It.IsAny <DependantResourceModel>(), It.IsAny <string>())) .Returns(Task.CompletedTask); var resultDataClient = new Mock <IResultDataClient>(); resultDataClient .Setup(m => m.DeleteResource(It.IsAny <DependantResourceModel>())) .Returns(Task.CompletedTask); var dependantResourceHandler = new DependantResourceHandler( fileClient.Object, scenarioClient.Object, resultConfigClient.Object, simPlanClient.Object, simRunClient.Object, resultDataClient.Object ); Exception exception = null; try { // Act await dependantResourceHandler.DeleteDependantResourcesForMarkSession( MarkSessionModelDataMocks.MockMarkSessionModel() ); } catch (Exception e) { exception = e; } // Assert Assert.Null(exception); }
public void IsMarkSessionRecentlyUpdated_RecentlyUpdatedMarkSession_ReturnsTrue() { // Arrange var markSessionModel = MarkSessionModelDataMocks.MockMarkSessionModel(); // Act var result = markSessionModel.IsMarkSessionRecentlyUpdated(); // Assert Assert.True(result); }
public void IsMarkSessionRecentlyUpdated_NotRecentlyUpdatedMarkSession_ReturnsFalse() { // Arrange var markSessionModel = MarkSessionModelDataMocks.MockMarkSessionModel(); markSessionModel.LatestUpdateTimestampInTicks = DateTime.Now.Ticks - 2 * Constants.MarkSessionUpdateReferenceTimeInTicks; // Act var result = markSessionModel.IsMarkSessionRecentlyUpdated(); // Assert Assert.False(result); }
public async void Create_ExistingMarkSessionModel_ThrowsException() { // Arrange var markSessionModel = MarkSessionModelDataMocks.MockMarkSessionModel(); var markSessionModelIndexManager = new Mock <IMongoIndexManager <MarkSessionModel> >(); markSessionModelIndexManager .Setup(m => m.CreateOneAsync( It.IsAny <IndexKeysDefinition <MarkSessionModel> >(), It.IsAny <CreateIndexOptions>(), It.IsAny <CancellationToken>() )).ReturnsAsync(""); var markSessionCollection = new Mock <IMongoCollection <MarkSessionModel> >(); markSessionCollection .Setup(m => m.Indexes) .Returns(markSessionModelIndexManager.Object); markSessionCollection .Setup(m => m.InsertOneAsync( It.IsAny <MarkSessionModel>(), It.IsAny <InsertOneOptions>(), It.IsAny <CancellationToken>() )).Returns(Task.FromException(new Exception())); var dbMongoService = new Mock <IDbMongoService>(); dbMongoService .Setup(m => m.GetMarkSessionCollection()) .Returns(markSessionCollection.Object); var markSessionRepository = new MarkSessionRepository(dbMongoService.Object); Exception exception = null; try { // Act await markSessionRepository.Create(markSessionModel); } catch (FailedToCreateMarkSessionException e) { exception = e; } // Assert Assert.NotNull(exception); }
public async void StartAsync_TrueCancellationToken_NoExceptionThrown() { // Arrange var markingServiceClient = new Mock <IMarkingServiceClient>(); markingServiceClient .Setup(m => m.GetMarkSessionsByMarkSessionType(It.IsAny <string>())) .ReturnsAsync( new List <MarkSessionModel> { MarkSessionModelDataMocks.MockMarkSessionModel(), MarkSessionModelDataMocks.MockMarkSessionModel(), MarkSessionModelDataMocks.MockMarkSessionModel(), MarkSessionModelDataMocks.MockMarkSessionModel(), MarkSessionModelDataMocks.MockMarkSessionModel() } ); var markSessionHandler = new Mock <IMarkSessionHandler>(); markSessionHandler .Setup(m => m.DeleteMarkSessionAndDependantResources(It.IsAny <MarkSessionModel>())) .ReturnsAsync("12345"); var loggerService = new Mock <ILoggerService>(); var hostedStartupService = new HostedStartupService( markingServiceClient.Object, markSessionHandler.Object, loggerService.Object ); var cancellationToken = new CancellationToken(true); Exception exception = null; try { // Act await hostedStartupService.StartAsync(cancellationToken); } catch (Exception e) { exception = e; } // Assert Assert.Null(exception); }
public async void StartAsync_TrueCancellationToken_NoExceptionThrown() { // Arrange var markSessionRepository = new Mock <IMarkSessionRepository>(); markSessionRepository .Setup(m => m.GetAll()) .ReturnsAsync( new List <MarkSessionModel> { MarkSessionModelDataMocks.MockMarkSessionModel(), MarkSessionModelDataMocks.MockMarkSessionModel(), MarkSessionModelDataMocks.MockMarkSessionModel(), MarkSessionModelDataMocks.MockMarkSessionModel(), MarkSessionModelDataMocks.MockMarkSessionModel() } ); var markSessionHandler = new Mock <IMarkSessionHandler>(); markSessionHandler .Setup(m => m.DeleteMarkSession(It.IsAny <string>())) .ReturnsAsync(It.IsAny <string>()); var loggerService = new Mock <ILoggerService>(); var hostedStartupService = new HostedStartupService( markSessionRepository.Object, markSessionHandler.Object, loggerService.Object ); var cancellationToken = new CancellationToken(true); Exception exception = null; try { // Act await hostedStartupService.StartAsync(cancellationToken); } catch (Exception e) { exception = e; } // Assert Assert.Null(exception); }
public async void MarkResourcesForMarkSession_ProjectMarkSessionModel_ReturnsMarkSessionWithDependantResources() { // Arrange var emptyMarkSessionModel = MarkSessionModelDataMocks.MockMarkSessionModel(); emptyMarkSessionModel.DependantResources = new List <DependantResourceModel>(); var markSessionRepository = new Mock <IMarkSessionRepository>(); var projectClient = new Mock <IProjectClient>(); var metadataClient = new Mock <IMetadataClient>(); metadataClient .Setup(m => m.GetMetadataForProject(It.IsAny <string>())) .ReturnsAsync(MetadataModelDataMocks.MockFinishedMetadataModelList); metadataClient .Setup(m => m.MarkMetadata(It.IsAny <MetadataModel>())) .ReturnsAsync(DependantResourceDataMocks.MockDependantResourceModel); var scenarioClient = new Mock <IScenarioClient>(); var resultConfigClient = new Mock <IResultConfigClient>(); resultConfigClient .Setup(m => m.GetResultConfigsForMetadata(It.IsAny <string>())) .ReturnsAsync(new List <ResultConfigModel>()); var simPlanClient = new Mock <ISimPlanClient>(); var simRunClient = new Mock <ISimRunClient>(); var resultDataClient = new Mock <IResultDataClient>(); var dependantResourceHandler = new DependantResourceHandler( projectClient.Object, markSessionRepository.Object, metadataClient.Object, scenarioClient.Object, resultConfigClient.Object, simPlanClient.Object, simRunClient.Object, resultDataClient.Object ); // Act await dependantResourceHandler.MarkResourcesForMarkSession(emptyMarkSessionModel); // Assert Assert.NotEmpty(emptyMarkSessionModel.DependantResources); }
public async void Delete_MarkSessionModelWithDependantResources_ThrowsException() { // Arrange var markSessionModel = MarkSessionModelDataMocks.MockMarkSessionModel(); var dbMongoService = new Mock <IDbMongoService>(); var markSessionRepository = new MarkSessionRepository(dbMongoService.Object); Exception exception = null; try { // Act await markSessionRepository.Delete(markSessionModel); } catch (CannotDeleteMarkSessionException e) { exception = e; } // Assert Assert.NotNull(exception); }