public async Task EditGlobalCoordinator_WhenEditingExistingGlobalCoordinator_SaveChangesAsyncIsCalled() { ArrangeUsersDbSetWithOneGlobalCoordinator(); await _globalCoordinatorService.Edit(new EditGlobalCoordinatorRequestDto { Id = 123 }); await _nyssContext.Received().SaveChangesAsync(); }
public async Task RegisterManager_WhenIdentityUserCreationSuccessful_NyssContextAddIsCalledOnce() { var userEmail = "*****@*****.**"; var registerManagerRequestDto = new CreateManagerRequestDto { Name = userEmail, Email = userEmail }; var result = await _managerService.Create(_nationalSocietyId, registerManagerRequestDto); await _nyssContext.Received().AddAsync(Arg.Any <UserNationalSociety>()); }
public async Task CreateHealthRisk_WhenSuccessful_ShouldReturnSuccess() { // Arrange var healthRiskRequestDto = new HealthRiskRequestDto { HealthRiskCode = 2, HealthRiskType = HealthRiskType, LanguageContent = new List <HealthRiskLanguageContentDto> { new HealthRiskLanguageContentDto { Name = HealthRiskName, FeedbackMessage = FeedbackMessage, CaseDefinition = CaseDefinition, LanguageId = LanguageId } } }; // Act await _healthRiskService.Create(healthRiskRequestDto); // Assert await _nyssContextMock.Received(1).AddAsync(Arg.Any <HealthRisk>()); }
public async Task DeleteNationalSocietyUser_WhenSuccessful_NyssContextSaveChangesShouldBeCalledOnce() { var manager = new ManagerUser { Id = 123, Role = Role.Manager }; ArrangeUsersFrom(new List <User> { manager }); var userNationalSociety = new UserNationalSociety { User = manager, UserId = manager.Id, NationalSocietyId = 1 }; ArrangeUserNationalSocietiesFrom(new List <UserNationalSociety> { userNationalSociety }); await _nationalSocietyUserService.DeleteUser <ManagerUser>(123, new List <string> { Role.Administrator.ToString() }); await _nyssContext.Received().SaveChangesAsync(); }
public async Task CreateNationalSociety_WhenSuccessful_ShouldReturnSuccess() { // Arrange _testData.BasicData.Data.GenerateData().AddToDbContext(); var nationalSocietyReq = new CreateNationalSocietyRequestDto { Name = BasicNationalSocietyServiceTestData.NationalSocietyName, ContentLanguageId = BasicNationalSocietyServiceTestData.ContentLanguageId, CountryId = BasicNationalSocietyServiceTestData.CountryId }; // Actual await _nationalSocietyService.Create(nationalSocietyReq); // Assert await _nyssContextMock.Received(1).AddAsync(Arg.Any <NationalSociety>()); }
public async Task AddExisting_WhenEmailExistsAndIsAssignable_SaveChangesShouldBeCalledOnce() { //act var result = await _userService.AddExisting(2, "*****@*****.**"); //assert await _nyssContext.Received(1).SaveChangesAsync(); }
public async Task ResolveLabelsOnReportAdded_WhenMoreReportGroupsInRange_ShouldMergeReportGroups() { //arrange _testData.WhenMoreReportGroupsInRange.GenerateData().AddToDbContext(); var report = _testData.WhenMoreReportGroupsInRange.AdditionalData.ReportBeingAdded; var group1Label = _testData.WhenMoreReportGroupsInRange.AdditionalData.Group1Label; var group2Label = _testData.WhenMoreReportGroupsInRange.AdditionalData.Group2Label; var group3Label = _testData.WhenMoreReportGroupsInRange.AdditionalData.Group3Label; //act await _reportLabelingService.ResolveLabelsOnReportAdded(report, report.ProjectHealthRisk); //assert var newReportGroup = report.ReportGroupLabel; var expectedUpdateCommandWithParametersFilled = $"UPDATE nyss.Reports SET ReportGroupLabel={newReportGroup} WHERE ReportGroupLabel IN ({group1Label}, {group2Label}, {group3Label})"; await _nyssContextMock.Received(1).ExecuteSqlInterpolatedAsync(Arg.Is <FormattableString>(x => x.ToString() == expectedUpdateCommandWithParametersFilled)); }
public async Task ReportAdded_WhenCountThresholdIsOne_ShouldSaveChanges2Times() { //arrange _testData.WhenCountThresholdIsOne.GenerateData().AddToDbContext(); var report = _testData.WhenCountThresholdIsOne.EntityData.Reports.Single(); //act var result = await _alertService.ReportAdded(report); // Assert await _nyssContextMock.Received(2).SaveChangesAsync(); }
public async Task CreateDataCollector_WhenSuccess_ShouldReturnSuccess(DataCollectorType type, string displayName) { // Arrange var dataCollector = new CreateDataCollectorRequestDto { DataCollectorType = type, PhoneNumber = "+4712344567", DisplayName = displayName, SupervisorId = SupervisorId, VillageId = _nyssContextMock.Villages.ToList()[0].Id, Latitude = 15, Longitude = 45 }; // Act await _dataCollectorService.Create(ProjectId, dataCollector); // Assert await _nyssContextMock.Received(1).AddAsync(Arg.Any <DataCollector>()); }
public async Task AddSmsGateway_WhenApiKeyDoesNotExistYet_ShouldReturnSuccess() { // Arrange const int nationalSocietyId = 1; var nationalSocieties = new[] { new NationalSociety { Id = nationalSocietyId, Name = "National Society" } }; var nationalSocietiesMockDbSet = nationalSocieties.AsQueryable().BuildMockDbSet(); _nyssContextMock.NationalSocieties.Returns(nationalSocietiesMockDbSet); var gatewaySettings = new[] { new GatewaySetting { Id = 1, Name = "Name", ApiKey = "api-key", NationalSocietyId = nationalSocietyId, GatewayType = GatewayType.SmsEagle } }; var gatewaySettingsMockDbSet = gatewaySettings.AsQueryable().BuildMockDbSet(); _nyssContextMock.GatewaySettings.Returns(gatewaySettingsMockDbSet); var gatewaySettingRequestDto = new GatewaySettingRequestDto { Name = "New SMS Gateway", ApiKey = "new-api-key", GatewayType = GatewayType.SmsEagle }; // Act var result = await _smsGatewayService.Create(nationalSocietyId, gatewaySettingRequestDto); // Assert await _nyssContextMock.GatewaySettings.Received(1).AddAsync( Arg.Is <GatewaySetting>(gs => gs.Name == "New SMS Gateway" && gs.ApiKey == "new-api-key" && gs.GatewayType == GatewayType.SmsEagle)); await _nyssContextMock.Received(1).SaveChangesAsync(); var content = Arg.Any <string>(); await _smsGatewayBlobProviderMock.Received(1).UpdateApiKeys(content); result.IsSuccess.ShouldBeTrue(); result.Message.Key.ShouldBe(ResultKey.NationalSociety.SmsGateway.SuccessfullyAdded); }