public async Task PublishStagedReleaseContent() { var releaseId = Guid.NewGuid(); var publicBlobStorageService = new Mock <IBlobStorageService>(MockBehavior.Strict); var publicBlobCacheService = new Mock <IBlobCacheService>(MockBehavior.Strict); var releaseService = new Mock <IReleaseService>(MockBehavior.Strict); publicBlobStorageService.Setup(mock => mock.MoveDirectory(PublicContent, PublicContentStagingPath(), PublicContent, string.Empty, null)) .Returns(Task.CompletedTask); publicBlobCacheService.Setup(mock => mock.DeleteItem(It.IsAny <PublicationCacheKey>())) .Returns(Task.CompletedTask); releaseService.Setup(mock => mock.SetPublishedDates(releaseId, It.IsAny <DateTime>())) .Returns(Task.CompletedTask); var service = BuildPublishingService(publicBlobStorageService: publicBlobStorageService.Object, publicBlobCacheService: publicBlobCacheService.Object, releaseService: releaseService.Object); await service.PublishStagedReleaseContent(releaseId, "publication-slug"); MockUtils.VerifyAllMocks(publicBlobStorageService, publicBlobCacheService, releaseService); }
public async Task QueryForDataBlock_NotDataBlockType() { var contentPersistenceHelper = MockUtils.MockPersistenceHelper <ContentDbContext, ReleaseContentBlock>( new ReleaseContentBlock { ReleaseId = _releaseId, Release = new Release { Id = _releaseId, }, ContentBlockId = _dataBlockId, ContentBlock = new HtmlBlock { Id = _dataBlockId, } } ); var controller = BuildTableBuilderController( contentPersistenceHelper: contentPersistenceHelper.Object ); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; var result = await controller.QueryForDataBlock(_releaseId, _dataBlockId); Assert.IsType <NotFoundResult>(result.Result); }
public async Task QueryForDataBlock() { var tableBuilderService = new Mock <ITableBuilderService>(); tableBuilderService .Setup( s => s.Query( _releaseId, It.Is <ObservationQueryContext>( q => q.SubjectId == _query.SubjectId ) ) ) .ReturnsAsync( new TableBuilderResultViewModel { Results = new List <ObservationViewModel> { new ObservationViewModel() } } ); var contentPersistenceHelper = MockUtils.MockPersistenceHelper <ContentDbContext, ReleaseContentBlock>( new ReleaseContentBlock { ReleaseId = _releaseId, Release = new Release { Id = _releaseId, }, ContentBlockId = _dataBlockId, ContentBlock = new DataBlock { Id = _dataBlockId, Query = _query, Charts = new List <IChart>() } } ); var controller = BuildTableBuilderController( tableBuilderService: tableBuilderService.Object, contentPersistenceHelper: contentPersistenceHelper.Object ); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; var result = await controller.QueryForDataBlock(_releaseId, _dataBlockId); Assert.IsType <TableBuilderResultViewModel>(result.Value); Assert.Single(result.Value.Results); MockUtils.VerifyAllMocks(tableBuilderService, contentPersistenceHelper); }
public async Task CheckComplete_SingleDataFileCompleted_AlreadyFinished() { await FinishedStatuses.ForEachAsync(async finishedStatus => { var message = new ImportObservationsMessage { ReleaseId = Guid.NewGuid(), NumBatches = 1, DataFileName = "my_data_file.csv", TotalRows = 2, SubjectId = Guid.NewGuid() }; var importStatusService = new Mock <IImportStatusService>(Strict); var service = BuildFileImportService( importStatusService: importStatusService.Object); importStatusService .Setup(s => s.GetImportStatus(message.ReleaseId, message.DataFileName)) .ReturnsAsync(new ImportStatus { Status = finishedStatus }); var dbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(); await using (dbContext) { await service.CheckComplete(message.ReleaseId, message, dbContext); } MockUtils.VerifyAllMocks(importStatusService); }); }
public void CollectionController_Get_Basic() { //ARRANGE var collectionId = Guid.NewGuid(); var controller = MockUtils.MockProperties <CollectionsController>(); var collectionViewModel = new CollectionViewModel() { Id = collectionId, Name = "Collection 543" }; Mock.Get(controller.CollectionFacade).Setup(x => x.GetById(collectionId)).Returns( new CollectionDto() { Id = collectionId, Name = collectionViewModel.Name } ); Mock.Get(controller.Mapper).Setup(x => x.Map <CollectionViewModel>(It.Is <CollectionDto>(p => p is CollectionDto && p.Id == collectionId && p.Name == "Collection 543"))).Returns(collectionViewModel); //ACT var collection = controller.Get(collectionId).Value as CollectionViewModel; //ASSERT Assert.AreEqual(collectionId, collection.Id); Assert.AreEqual("Collection 543", collection.Name); }
public async Task Maintentance() { var container = ComponentTestFactory.BuildContainer(); var component = container.GetInstance <SecurityRiskComponent>(); var threat = await component.CreateThreat(new Models.SecurityThreatPostRp() { Name = MockUtils.GenerateRandomName() }); var threats = await component.GetThreats(); Assert.NotEmpty(threats); var threatGet = await component.GetThreat(threat.Id); Assert.NotNull(threatGet); await component.UpdateThreat(threat.Id, new Models.SecurityThreatPutRp() { Name = "change" }); threatGet = await component.GetThreat(threat.Id); Assert.Equal("change", threatGet.Name); await component.DeleteThreat(threat.Id); threatGet = await component.GetThreat(threat.Id); Assert.Null(threatGet); }
public static async Task <(int customer, int product)> BuildCustomerProduct(Container container, string customerName = "customer", string productName = null, bool defaultValues = false) { productName ??= MockUtils.GenerateRandomName(); var customerComponet = container.GetInstance <CustomerComponent>(); var customerQueryComponent = container.GetInstance <CustomerQueryComponent>(); await customerComponet.CreateCustomer(new Models.CustomerPostRp() { Name = customerName, Default = defaultValues }); var productComponent = container.GetInstance <ProductComponent>(); var customer = await customerQueryComponent.GetCustomerByName(customerName); var productQueryComponent = container.GetInstance <ProductQueryComponent>(); await productComponent.CreateProduct(new ProductPostRp() { CustomerId = customer.Id, Name = productName }); var product = await productQueryComponent.GetProductByName(customer.Id, productName); return(customer.Id, product.Id); }
public async Task ProductIdempotenceSuccess() { var container = ComponentTestFactory.BuildContainer(); var customerId = await ComponentTestFactory.BuildCustomer(container); var productComponet = container.GetInstance <ProductComponent>(); var productQueryComponent = container.GetInstance <ProductQueryComponent>(); var name = MockUtils.GenerateRandomName(); await productComponet.CreateProduct(new Models.ProductPostRp() { CustomerId = customerId, Name = name }); await productComponet.CreateProduct(new Models.ProductPostRp() { CustomerId = customerId, Name = name }); var products = await productQueryComponent.GetProducts(customerId); Assert.NotEmpty(products); Assert.Single(products); }
public async Task PublishMethodologyFilesIfApplicableForRelease_ReleaseHasNoRelatedMethodologies() { var releaseId = Guid.NewGuid(); var methodologyService = new Mock <IMethodologyService>(MockBehavior.Strict); var publicBlobStorageService = new Mock <IBlobStorageService>(MockBehavior.Strict); var privateBlobStorageService = new Mock <IBlobStorageService>(MockBehavior.Strict); var publicationService = new Mock <IPublicationService>(MockBehavior.Strict); var releaseService = new Mock <IReleaseService>(MockBehavior.Strict); methodologyService.Setup(mock => mock.GetLatestByRelease(releaseId)) .ReturnsAsync(new List <MethodologyVersion>()); // No other invocations on the services expected because the release has no related methodologies var service = BuildPublishingService(methodologyService: methodologyService.Object, publicBlobStorageService: publicBlobStorageService.Object, privateBlobStorageService: privateBlobStorageService.Object, publicationService: publicationService.Object, releaseService: releaseService.Object); await service.PublishMethodologyFilesIfApplicableForRelease(releaseId); MockUtils.VerifyAllMocks(methodologyService, publicBlobStorageService, privateBlobStorageService, publicationService, releaseService); }
private Mock <IPersistenceHelper <ContentDbContext> > DefaultPersistenceHelperMock() { var mock = MockUtils.MockPersistenceHelper <ContentDbContext, Release>(); MockUtils.SetupCall(mock, _release.Id, _release); return(mock); }
public async Task SourceItemBatchInteractionsCase() { var container = ComponentTestFactory.BuildContainer(); var customer = MockUtils.GenerateRandomName(); var product = MockUtils.GenerateRandomName(); var context = container.GetInstance <FalconDbContext>(); var(_, productId) = await ComponentTestFactory.BuildCustomerProduct(container, customerName : customer, productName : product); var itemComponent = container.GetInstance <SourceItemComponent>(); var sourceComponent = container.GetInstance <SourceComponent>(); var items = await itemComponent.CreateInteractionItems(new SourceItemBatchPostRp() { Customer = customer, Product = product, Kind = Core.Entities.SourceKindEnum.Interaction, Delimiter = ';', Items = new List <string>() { "OnboardingController::verifyOTPCode;2020-03-01 01:00:00;2020-03-01 01:59:59;75;0;59;1267.0053999999996", "OnboardingController::verifyOTPCode;2020-03-01 02:00:00;2020-03-01 02:59:59;38;0;36;576.58925", "OnboardingController::verifyOTPCode;2020-03-01 03:00:00;2020-03-01 03:59:59;22;0;21;571.0088000000001" } }); Assert.Equal(1, items.SourceCreated); Assert.Equal(9, items.ItemsCreated); }
public async Task Stream_MethodologyFileNotFound() { var methodologyVersion = new MethodologyVersion(); var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId)) { await contentDbContext.MethodologyVersions.AddAsync(methodologyVersion); await contentDbContext.SaveChangesAsync(); } var blobStorageService = new Mock <IBlobStorageService>(MockBehavior.Strict); await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId)) { var service = SetupMethodologyImageService(contentDbContext: contentDbContext, blobStorageService: blobStorageService.Object); var result = await service.Stream(methodologyVersion.Id, Guid.NewGuid()); result.AssertNotFound(); } MockUtils.VerifyAllMocks(blobStorageService); }
private TopicService SetupTopicService( ContentDbContext contentContext = null, StatisticsDbContext statisticsContext = null, PersistenceHelper <ContentDbContext> persistenceHelper = null, IMapper mapper = null, IUserService userService = null, IReleaseSubjectRepository releaseSubjectRepository = null, IReleaseDataFileService releaseDataFileService = null, IReleaseFileService releaseFileService = null, IPublishingService publishingService = null, IMethodologyService methodologyService = null) { return(new TopicService( Mock.Of <IConfiguration>(), contentContext ?? Mock.Of <ContentDbContext>(), statisticsContext ?? Mock.Of <StatisticsDbContext>(), persistenceHelper ?? MockUtils.MockPersistenceHelper <ContentDbContext, Topic>(_topic.Id, _topic).Object, mapper ?? AdminMapper(), userService ?? MockUtils.AlwaysTrueUserService().Object, releaseSubjectRepository ?? Mock.Of <IReleaseSubjectRepository>(), releaseDataFileService ?? Mock.Of <IReleaseDataFileService>(), releaseFileService ?? Mock.Of <IReleaseFileService>(), publishingService ?? Mock.Of <IPublishingService>(), methodologyService ?? Mock.Of <IMethodologyService>(), Mock.Of <IBlobCacheService>() )); }
public async Task Create_LatestPublishedReleaseForSubjectNotFound() { var request = new PermalinkCreateViewModel { Query = { SubjectId = Guid.NewGuid() } }; var releaseRepository = new Mock <IReleaseRepository>(MockBehavior.Strict); var subjectRepository = new Mock <ISubjectRepository>(MockBehavior.Strict); releaseRepository .Setup(s => s.GetLatestPublishedRelease(_publicationId)) .Returns((Release?)null); subjectRepository .Setup(s => s.GetPublicationIdForSubject(request.Query.SubjectId)) .ReturnsAsync(_publicationId); var service = BuildService(releaseRepository: releaseRepository.Object, subjectRepository: subjectRepository.Object); var result = await service.Create(request); MockUtils.VerifyAllMocks( releaseRepository, subjectRepository); result.AssertNotFound(); }
Mock <IUserService>) Mocks() { return( new Mock <ContentDbContext>(), MockUtils.MockPersistenceHelper <ContentDbContext, Release>(_release.Id, _release), new Mock <IUserService>()); }
public async Task Stream_ReleaseFileNotFound() { var release = new Release(); var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { await contentDbContext.Releases.AddAsync(release); await contentDbContext.SaveChangesAsync(); } var blobStorageService = new Mock <IBlobStorageService>(MockBehavior.Strict); await using (var contentDbContext = InMemoryApplicationDbContext()) { var service = SetupReleaseImageService(contentDbContext: contentDbContext, blobStorageService: blobStorageService.Object); var result = await service.Stream(release.Id, Guid.NewGuid()); result.AssertNotFound(); } MockUtils.VerifyAllMocks(blobStorageService); }
public void GetAnswers_WhenSendAnEvaluationId_ShouldReturnAsnwers() { var evaluationId = Guid.NewGuid(); var expected = new List <EvaluationScore>() { new EvaluationScore() { Id = Guid.NewGuid(), IdEvaluation = evaluationId }, new EvaluationScore() { Id = Guid.NewGuid(), IdEvaluation = evaluationId }, }; var mapperMock = new Mock <IMapper>(); mapperMock.Setup(m => m.Fetch <EvaluationScore>(It.IsAny <string>(), evaluationId)).Returns(expected); var answerDao = new AnswersDao(MockUtils.MockConnectionFactory(mapperMock)); var answer = answerDao.GetAnswers(evaluationId); Assert.Equal(2, answer.Count); }
public async Task SourceItemBatchInteractions() { var container = ComponentTestFactory.BuildContainer(); var customer = MockUtils.GenerateRandomName(); var product = MockUtils.GenerateRandomName(); var context = container.GetInstance <FalconDbContext>(); var(_, productId) = await ComponentTestFactory.BuildCustomerProduct(container, customerName : customer, productName : product); var itemComponent = container.GetInstance <SourceItemComponent>(); var sourceComponent = container.GetInstance <SourceComponent>(); var items = await itemComponent.CreateInteractionItems(new SourceItemBatchPostRp() { Customer = customer, Product = product, Kind = Core.Entities.SourceKindEnum.Interaction, Items = new List <string>() { "Controller::sendAdvisor,2020-03-03 01:00:00,2020-03-03 01:59:59,24,22,20,14164.86935", "Controller::sendAdvisor,2020-03-04 01:00:00,2020-03-04 01:59:59,24,23,21,14164.86935", "Controller::getAdvisorInfo,2020-03-03 00:00:00,2020-03-03 23:59:59,200,196,195,18474.299049999998" } }); Assert.Equal(2, items.SourceCreated); Assert.Equal(9, items.ItemsCreated); var sourceSendAdvisor = await sourceComponent.GetByName(productId, "Controller::sendAdvisor"); Assert.NotNull(sourceSendAdvisor); var period = new DatePeriodValue(DateTime.Parse("2020-03-03 00:00:00"), DateTime.Parse("2020-03-03 23:59:59")); var itemsSendAdvisor = await itemComponent.GetAvailabilityItems(sourceSendAdvisor.Id, period ); var all = context.SourcesItems.Where(c => c.SourceId == sourceSendAdvisor.Id && c.Group == Core.Entities.SourceGroupEnum.Availability && c.Target >= period.Start && c.Target <= period.End).ToList(); Assert.Equal(0.917m, itemsSendAdvisor.First().Measure); var itemsSendAdvisorExperience = await itemComponent.GetExperienceItems(sourceSendAdvisor.Id, new DatePeriodValue( DateTime.Parse("2020-03-03 00:00:00"), DateTime.Parse("2020-03-03 23:59:59") ) ); Assert.Equal(0.833m, itemsSendAdvisorExperience.First().Measure); var itemsSendAdvisorLatency = await itemComponent.GetLatencyItems(sourceSendAdvisor.Id, new DatePeriodValue(DateTime.Parse("2020-03-03 00:00:00"), DateTime.Parse("2020-03-03 23:59:59")) ); Assert.Equal(14164.86935m, itemsSendAdvisorLatency.First().Measure); }
public void TestWithEmptyString() { IValueExtractor ive = MockUtils.CreateExtractor(repository, ""); var rv = new RequiredValidator(ive, ""); Assert.IsFalse(rv.Validate(null), "Requried Validator does not recognize \"\" as null"); repository.VerifyAll(); }
public void TestNullWithEmptyString() { IValueExtractor ive = MockUtils.CreateExtractor(repository, null); var rv = new RequiredValidator(ive, ""); Assert.IsFalse(rv.Validate(null), "Requried Validator does not check for null when has a default value"); repository.VerifyAll(); }
public void TestNullValueInteger() { IValueExtractor ive = MockUtils.CreateExtractor(repository, 1); var rv = new RequiredValidator(ive, 1); Assert.IsFalse(rv.Validate(null), "Requried Validator does not recognize default value to be null"); repository.VerifyAll(); }
public void TestNullValue() { IValueExtractor ive = MockUtils.CreateExtractor(repository, null); var rv = new RequiredValidator(ive, null); Assert.IsFalse(rv.Validate(null), "Requried Validator does not check null"); repository.VerifyAll(); }
public void TestNotNullValue() { IValueExtractor ive = MockUtils.CreateExtractor(repository, new object()); var rv = new RequiredValidator(ive, null); Assert.IsTrue(rv.Validate(null), "Requried Validator does not check object difference from null"); repository.VerifyAll(); }
public async Task GetLatestByRelease() { var release = new Release { Publication = new Publication { Title = "Publication", Slug = "publication-slug" }, ReleaseName = "2018", TimePeriodCoverage = AcademicYearQ1 }; var methodologies = AsList( new MethodologyVersion { Id = Guid.NewGuid(), PreviousVersionId = null, PublishingStrategy = Immediately, Status = Approved, Version = 0 }, new MethodologyVersion { Id = Guid.NewGuid(), PreviousVersionId = null, PublishingStrategy = Immediately, Status = Approved, Version = 0 }); var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId)) { await contentDbContext.Releases.AddAsync(release); await contentDbContext.SaveChangesAsync(); } var methodologyVersionRepository = new Mock <IMethodologyVersionRepository>(MockBehavior.Strict); methodologyVersionRepository.Setup(mock => mock.GetLatestVersionByPublication(release.PublicationId)) .ReturnsAsync(methodologies); await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId)) { var service = SetupMethodologyService(contentDbContext, methodologyVersionRepository.Object); var result = await service.GetLatestByRelease(release.Id); Assert.Equal(methodologies, result); } MockUtils.VerifyAllMocks(methodologyVersionRepository); }
Mock <IUserService>) Mocks() { var persistenceHelper = MockUtils.MockPersistenceHelper <ContentDbContext>(); MockUtils.SetupCall(persistenceHelper, _release.Id, _release); return(persistenceHelper, MockUtils.AlwaysTrueUserService()); }
public void CreateAnswers_WhenSendAValidObject_ShouldCreateAndReturnObject() { var connectionMock = new CassandraConnection("answers", "localhost"); var mapperMock = new Mock <IMapper>(); var expected = new EvaluationScore() { Id = Guid.NewGuid(), IdEvaluation = Guid.NewGuid(), Qualification = Guid.NewGuid(), Date = DateTime.Now, Name = "TestName", Owner = "TestOwner", Score = 50, ScoreFormula = "Formula", Weight = 12, QuestionList = new List <QuestionScore>() { new QuestionScore() { IdQuestion = Guid.NewGuid(), Answers = new List <Guid>(), Score = 5, ScoreFormula = "QS1", OptionList = new List <OptionScore>() { new OptionScore() { IdOption = Guid.NewGuid(), IsAnswer = true, Sequence = 1, UserSelected = false, Weight = 3 } } }, new QuestionScore() { IdQuestion = Guid.NewGuid(), Answers = new List <Guid>(), Score = 5, ScoreFormula = "QS2", OptionList = new List <OptionScore>() }, }, QualificationRanges = new List <QualificationRange>() { new QualificationRange() { Id = Guid.NewGuid(), Start = 100, End = 0, Qualification = "GOOD" } }, }; mapperMock.Setup(m => m.Insert(expected, null)).Verifiable(); mapperMock.Setup(m => m.Single <EvaluationScore>(It.IsAny <string>(), It.IsAny <Guid>())).Returns(expected); var answerDao = new AnswersDao(MockUtils.MockConnectionFactory(mapperMock)); var response = answerDao.CreateAnswers(expected); Assert.Equal(expected.Id, response.Id); }
internal static ImportStatusBauService BuildImportStatusBauService( IUserService userService = null, ContentDbContext contentDbContext = null) { return(new ImportStatusBauService( userService ?? MockUtils.AlwaysTrueUserService().Object, contentDbContext ?? new Mock <ContentDbContext>().Object )); }
public async Task InitializeAsync() { _issuerAgent = await MockUtils.CreateAsync("issuer", config1, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage(cb.name, cb.data)), TestConstants.StewartDid); _router.RegisterAgent(_issuerAgent); _holderAgent = await MockUtils.CreateAsync("holder", config2, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage((cb).name, cb.data))); _router.RegisterAgent(_holderAgent); }
public void TestValueExtractorCorrectlyCalled() { var newObject = new object(); IValueExtractor ive = MockUtils.CreateExtractor(repository, null, newObject); var rv = new RequiredValidator(ive, null); Assert.IsFalse(rv.Validate(newObject), "Requried Validator does not check null"); repository.VerifyAll(); }
public async Task InitializeAsync() { _agent1 = await MockUtils.CreateAsync("agent1", config1, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage(cb.name, cb.data))); _router.RegisterAgent(_agent1); _agent2 = await MockUtils.CreateAsync("agent2", config2, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage(cb.name, cb.data))); _router.RegisterAgent(_agent2); }