Ejemplo n.º 1
0
        public async Task UpdateAuthorizedApiKeys()
        {
            var authorizedApiKeys = await _nyssContext.GatewaySettings
                                    .OrderBy(gs => gs.NationalSocietyId)
                                    .ThenBy(gs => gs.Id)
                                    .Select(gs => gs.ApiKey)
                                    .ToListAsync();

            var blobContentToUpload = string.Join(Environment.NewLine, authorizedApiKeys);
            await _smsGatewayBlobProvider.UpdateApiKeys(blobContentToUpload);
        }
Ejemplo n.º 2
0
        public async Task AddSmsGateway_WhenExceptionIsThrown_ShouldReturnError()
        {
            // 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
            };

            var content = Arg.Any <string>();

            _smsGatewayBlobProviderMock.UpdateApiKeys(content).ThrowsForAnyArgs(new ResultException(ResultKey.UnexpectedError));

            // 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 content1 = Arg.Any <string>();
            await _smsGatewayBlobProviderMock.Received(1).UpdateApiKeys(content1);

            result.IsSuccess.ShouldBeFalse();
            result.Message.Key.ShouldBe(ResultKey.UnexpectedError);
        }