小编Moh*_*ish的帖子

索引处理程序未定义或未导出

我有一个运行良好的 lambda 函数,但我想导入一个包,所以我用 index.js 创建了一个目录并安装了我的 npm 包。

然后创建此文件夹的 zip 并使用上传

aws lambda 更新函数代码 --function-name smrtfac-test --zip-file fileb://lambda.zip

但现在我收到这个错误

index.handler is undefined or not exported
Run Code Online (Sandbox Code Playgroud)

原因可能是什么?myindex.jsnode_modules在同一个目录中。

aws-cli aws-lambda

27
推荐指数
2
解决办法
2万
查看次数

我们如何在 ASP.Net Core 中使用 HttpClient?

我正在编写 ASP.Net MVC Core 2.2 Web App。我需要使用 HTTP 或 HTTPS 从另一个 Web 服务器获取数据。我该怎么做?

我使用HttpClient.

我有一个接收消息的控制器,它工作正常,但是,我应该构建HttpClient吗?

[Route("api/[controller]")]
[ApiController]
public class MyController : ControllerBase
{
    private readonly IHostingEnvironment _env;
    private readonly ILogger _logger;
    private readonly IUpdateService _updateService;

    public MyController(
        IHostingEnvironment env,
        ILogger<MyController> logger,
        IUpdateService updateService)
    {
        _env = env;
        _logger = logger;
        _updateService = updateService;
    }

    // POST api/values
    [HttpPost]
    public async Task<IAsyncResult> Post([FromBody]Update update)
    {
        using (HttpClient Client = new HttpClient())
        {
            HttpResponseMessage result = Client.GetAsync(uri).Result;
            switch …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-2.0

11
推荐指数
1
解决办法
2万
查看次数

单元测试验证伴生对象方法被调用(模拟伴生对象)

当切换到 Kotlin 时,静态方法被移动到一个伴随对象中。但是,没有明显的方法可以对调用这些“静态方法”的其他方法进行单元测试。

在 Java 中,我们可以使用 PowerMockito 的 MockStatic(SomeClass.class) 来验证在被测方法中调用了静态方法。PowerMock 在 Kotlin 中失去了它的魔力。

为了测试,我创建了以下类。

public class DummyJava {
    static public Void staticMechod(){
          System.out.print("Dummy method is called");
          return null;
     }
}

class DummyCompanion {
    companion object {
        fun someCompanionMethod(){
            System.out.printf("companion method is called\n")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在有另一个类调用 DummyCompanion.someCompanion

public class DummyWrapper {
    public void callAStaticMethod(){
        DummyJava.staticMechod();
    }

    public void callCompanionMethod(){
        DummyCompanion.Companion.someCompanionMethod();
    }
}
Run Code Online (Sandbox Code Playgroud)

单元测试callAStaticMethod()我们使用了以下内容

@RunWith(PowerMockRunner.class)
@PrepareForTest({DummyJava.class, DummyCompanion.Companion.class})
public class staticClassTest {
    //This case works
    @Test 
    public void testForStaticMethod() { …
Run Code Online (Sandbox Code Playgroud)

java unit-testing kotlin

10
推荐指数
2
解决办法
9865
查看次数

身份服务器 4 登录后重定向仅在 Chrome 中不起作用

我使用身份服务器 4,称之为“身份验证服务器”,在 .net core 3.1 上运行。重定向到 auth-server 并提供提交登录的凭据后,有角度应用程序请求身份验证,它不会重定向回客户端应用程序。问题仅在 chrome 浏览器中(firefox 和 edge 工作正常)我可以看到重定向请求 - Request-Url 但它只是返回登录页面客户端配置:

public static IEnumerable<Client> GetClients()
{
    return new List<Client>(){
            new Client() {
                             RequireConsent =false,
                             RequireClientSecret = false,
                             ClientId = "takbull-clientapp-dev",
                             ClientName = "Takbull Client",
                             AllowedGrantTypes = GrantTypes.ImplicitAndClientCredentials,
                             AllowedScopes = new List<string> 
                             {
                              IdentityServerConstants.StandardScopes.OpenId,
                              IdentityServerConstants.StandardScopes.Email,
                              IdentityServerConstants.StandardScopes.Profile,
                              "takbull",
                              "takbull.api" 
                             },
                             // where to redirect to after login
                             RedirectUris = new List<string>()
                             {
                                 "http://localhost:4200/auth-callback/",
                                 "http://localhost:4200/silent-refresh.html",
                             },
                             //TODO: Add Production URL
                             // where to redirect to after logout
                             PostLogoutRedirectUris …
Run Code Online (Sandbox Code Playgroud)

.net-core identityserver4

10
推荐指数
3
解决办法
9402
查看次数

Android中获取蓝牙适配器的MAC地址

我正在尝试获取 Android 设备中蓝牙的 MAC 地址。所以我使用以下方法:

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String macAddress = mBluetoothAdapter.getAddress();
Run Code Online (Sandbox Code Playgroud)

返回的地址是02:00:00:00:00:00. 我见过一些问题和帖子说,除非您的应用程序是System Application ,否则不可能再在 android 中获取您的 MAC 地址。

那么如果我真的需要获取手机的MAC地址怎么办?是不可能做到还是怎么办?

注意:我知道这个问题在 SO 上被问了很多次,但大多数答案都已经过时了。

java android bluetooth-lowenergy

7
推荐指数
2
解决办法
1万
查看次数

ViewData 始终为空

我知道很多人问过这个问题,但没有人解决我的问题,请查看简单的两个代码片段,我使用的是 dotnet core 2.2。

我在ViewData.

控制器.cs:

public async Task<IActionResult> GetWebTripMetaData(Guid tripId)
{
    try
    {
        ViewData["Greeting"] = "Hello World!";
        return View();
    }
    catch (Exception)
    {
        return BadRequest("Internal Server Error");
    }
}
Run Code Online (Sandbox Code Playgroud)

看法:

@page
@model TripTale.Backend.Pages.tripModel
<html>
  <head>
      <link href="@Url.Content("~/Styles/trip.css")" rel="stylesheet" type="text/css" />
   </head>
    <body>
        @ViewData["Greeting"]
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

请注意,ViewData["Greeting"]从视图页面中删除时它工作正常。添加时,抛出未设置为实例的对象引用。

asp.net-mvc razor .net-core asp.net-core razor-pages

6
推荐指数
1
解决办法
4349
查看次数

在嵌套反应形式组中使用 mat-error

我有一个嵌套 FormGroup

this.outerForm= this.formBuilder.group({
  firstFormGroup: this.formBuilder.group({
    nserNumber: ['', Validators.required]
  }),
  ...
});
Run Code Online (Sandbox Code Playgroud)

我正在尝试以下操作:

<fieldset formGroupName="firstFormGroup">
        <ng-template matStepLabel>Enter NSER</ng-template>
        <div class="formRow">
          <div class="col-custom-col-50">
            <mat-form-field>
              <input matInput placeholder="NSER number" id='nserNumber' formControlName="nserNumber">
              <mat-error *ngIf="outerForm.controls.firstFormGroup.controls.nserNumber.required">Required</mat-error>
            </mat-form-field>
            <pre>{{outerForm.controls.firstFormGroup.controls.nserNumber | json}}</pre> 
          </div>
        </div>
Run Code Online (Sandbox Code Playgroud)

但是这个垫子错误不起作用。请帮忙

angular

2
推荐指数
1
解决办法
5467
查看次数

访问 .NET 5 Azure Function 中的 FunctionAppDirectory

我需要访问FunctionAppDirectoryAzure Functions

这是该函数的简化版本

[Function("Test")]
public static HttpResponseData Test([HttpTrigger(AuthorizationLevel.Function, "post", Route = "Test")] HttpRequestData req, 
ExecutionContext context, FunctionContext fContext)
{
    var log = fContext.GetLogger(nameof(TestOperations));
    log.LogInformation(context?.FunctionAppDirectory?.ToString());
    return req.CreateResponse(HttpStatusCode.OK);
}
Run Code Online (Sandbox Code Playgroud)

ExecutionContext这里是空的。

我的Program.cs文件

class Program
{
    static Task Main(string[] args)
    {
        var host = new HostBuilder()
            .ConfigureAppConfiguration(configurationBuilder =>
            {
                configurationBuilder.AddCommandLine(args);
            })
            .ConfigureFunctionsWorkerDefaults()
            .ConfigureServices(services =>
            {
                // Add Logging
                services.AddLogging();
            })
            .Build();

        return host.RunAsync();
    }
}
Run Code Online (Sandbox Code Playgroud)

在 .NET 5 中运行的 Azure 函数

如何配置 ExecutionContext 的绑定或以其他方式获取 FunctionAppDirectory?

azure azure-functions .net-5

2
推荐指数
1
解决办法
2859
查看次数

在 Angular 7 中验证图像尺寸

这个问题在JQuery和上有很多答案JavaScript。还有一些版本的Angular.

我尝试了很多解决方案,但没有一个奏效。

我正在使用Angular 7并尝试验证用户上传的图像的WidthHeight

这是我的.html代码片段:

<input type="file" name="upload" id="androidPhoneFile" class="upload-box" placeholder="Upload File" multiple="multiple" (change)="onAndroidPhoneChange($event)" formControlName="androidPhone" #androidPhonePhoto>
Run Code Online (Sandbox Code Playgroud)

这是我的.ts组件文件:

AddFilesToFormData(event: any, fileName: string) {
const reader = new FileReader();
const img = new Image();
img.onload = function() {
  const height = img.height;
  const width = img.width;
  console.log('Width and Height', width, height);
};

img.src = event.target.files[0];
if (event.target.files && event.target.files.length) {
  const [file] = event.target.files;
  reader.readAsDataURL(file);
  reader.onload …
Run Code Online (Sandbox Code Playgroud)

typescript angular

1
推荐指数
1
解决办法
4255
查看次数

如何模拟httpclient

我是 TDD 新手,能否请您使用 moq 编写测试用例以获取以下代码 -

public async Task<Model> GetAssetDeliveryRecordForId(string id)
{
    var response = await client.GetAsync($"api/getdata?id={id}");
    response.EnsureSuccessStatusCode();
    var result = await response.Content.ReadAsAsync<Model>();
    return result;
}
Run Code Online (Sandbox Code Playgroud)

提前致谢。

c# nunit moq .net-core

-2
推荐指数
1
解决办法
3321
查看次数