Skip to content

Commit

Permalink
Updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
praves77 committed Dec 7, 2024
1 parent 5682ea0 commit dd5386b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 17 deletions.
20 changes: 10 additions & 10 deletions MoesifMiddlewareExample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoesifNet8Example", "Moesif
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoesifNet6Example", "MoesifNet6Example\MoesifNet6Example.csproj", "{F248B0AC-68C5-46F8-BA5D-9E275ADC4F08}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moesif.Middleware", "..\moesif-dotnet\Moesif.Middleware\Moesif.Middleware.csproj", "{2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moesif.Api", "..\moesifapi-csharp\Moesif.Api\Moesif.Api.csproj", "{B4A40605-57BA-4C5D-B68F-348717EF61B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moesif.Api", "..\moesifapi-csharp\Moesif.Api\Moesif.Api.csproj", "{1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moesif.Middleware", "..\moesif-dotnet\Moesif.Middleware\Moesif.Middleware.csproj", "{E49606CF-77F8-48BA-B265-AA85BC980193}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -42,14 +42,14 @@ Global
{F248B0AC-68C5-46F8-BA5D-9E275ADC4F08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F248B0AC-68C5-46F8-BA5D-9E275ADC4F08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F248B0AC-68C5-46F8-BA5D-9E275ADC4F08}.Release|Any CPU.Build.0 = Release|Any CPU
{2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}.Release|Any CPU.Build.0 = Release|Any CPU
{1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}.Release|Any CPU.Build.0 = Release|Any CPU
{B4A40605-57BA-4C5D-B68F-348717EF61B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4A40605-57BA-4C5D-B68F-348717EF61B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4A40605-57BA-4C5D-B68F-348717EF61B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4A40605-57BA-4C5D-B68F-348717EF61B1}.Release|Any CPU.Build.0 = Release|Any CPU
{E49606CF-77F8-48BA-B265-AA85BC980193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E49606CF-77F8-48BA-B265-AA85BC980193}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E49606CF-77F8-48BA-B265-AA85BC980193}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E49606CF-77F8-48BA-B265-AA85BC980193}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 10 additions & 2 deletions MoesifNet6Example/MoesifNet6Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0'">
<DefineConstants>NET6_0_OR_GREATER</DefineConstants>
<DefineConstants>NETCORE</DefineConstants>
<!-- IMPORTANT please comment following lines before release build/publish -->
<!-- <DefineConstants>MOESIF_INSTRUMENT</DefineConstants>-->
</PropertyGroup>

<ItemGroup>
<Folder Include="publish\" />
<Folder Include="Settings\" />
Expand All @@ -15,8 +23,8 @@
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="9.0.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0" />
<!-- <PackageReference Include="Moesif.Api" Version="3.1.0" />-->
<!-- <PackageReference Include="Moesif.Middleware" Version="3.1.1"/>-->
<!-- <PackageReference Include="Moesif.Api" Version="3.1.1" />-->
<!-- <PackageReference Include="Moesif.Middleware" Version="3.1.2"/>-->
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

Expand Down
12 changes: 12 additions & 0 deletions MoesifNet6Example/Settings/MoesifOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ public bool isConfiguredMoesifApplicationId()
}
return !string.IsNullOrWhiteSpace(appId) && !appId.StartsWith("<");
}

public bool IsLambda()
{
var isLambda = false;
try {
isLambda = (bool) getMoesifOptions().GetValueOrDefault(MoesifOptionsParamNames.IsLambda);
}
catch (Exception ex){
Console.WriteLine("Error Reading Moesif Application Id in appsettings(.env).json: " + ex.Message );
}
return isLambda;
}
}

public class MoesifOptionsParamNames
Expand Down
36 changes: 34 additions & 2 deletions MoesifNet6Example/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

using System;
using System.Collections.Generic;
using System.Net;
using System.Text.Json.Nodes;
using Amazon.Lambda.APIGatewayEvents;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -34,9 +37,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
#if MOESIF_INSTRUMENT
Console.WriteLine($"Begin: Configure");
#endif
var isLambda = false;
MoesifOptions mo = new MoesifOptions(Configuration);
ensureValidConfig(mo);
app.UseMiddleware<MoesifMiddleware>(mo.getMoesifOptions());
isLambda = mo.IsLambda();

if (env.IsDevelopment())
{
Expand All @@ -51,9 +56,36 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
endpoints.MapGet("/", async context =>
{
var msg = "Hello World!";
var msg = $"Hello World! isLambd = {isLambda}";
Console.WriteLine($"Hit the home page: {msg}");
await context.Response.WriteAsync(msg);
// if (isLambda)
// {
// var response = new APIGatewayProxyResponse
// {
// StatusCode = (int)HttpStatusCode.OK,
// Body = $"Welcome to Home! Request path: /",
// Headers = new Dictionary<string, string> { { "Content-Type", "text/json" } }
// };
// }
// else
// {
await context.Response.WriteAsync(new JsonObject
{
["msg"] = msg,
["zipcode"] = 94709
}.ToString());
// }
});

endpoints.MapGet("/foo", async context =>
{
// var hdrs = new Dictionary<string, string> { { "Content-Type", "text/json" } };
var response = new JsonObject
{
["StatusCode"] = (int)HttpStatusCode.OK,
["Body"] = $"Hello from Lambda! Request path: /foo"
};
await context.Response.WriteAsJsonAsync(response);
});

endpoints.MapControllerRoute(
Expand Down
7 changes: 4 additions & 3 deletions MoesifNet6Example/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"MoesifOptions": {
"MyTag": "ILT_Org_PK_App",
"ApplicationId": "<Your-Moesif-Application-Id>",
"LocalDebug": false,
"LogBody": true,
"RequestMaxBodySize": 100,
"ResponseMaxBodySize": 100,
"RequestMaxBodySize": 100000,
"ResponseMaxBodySize": 100000,
"LogBodyOutgoing": true,
"ApiVersion": "3.1.0",
"ApiVersion": "3.1.2",
"EnableBatching": true,
"BatchSize": 1,
"IsLambda": true
Expand Down

0 comments on commit dd5386b

Please sign in to comment.