Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MBDEVproAPI.API/Controllers/CustomerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ public async Task<IActionResult> EditCustomer([FromBody] CustomerModel model)
/// <param name="id"></param>
/// <returns>SaveViewModel</returns>
[HttpDelete("{CustomerID:int}")]
public async Task<SaveViewModel> DeleteCustomerVMAsync(int CustomerID)
public async Task<IActionResult> DeleteCustomerVMAsync(int CustomerID)// LOOK AT ALL THESE IN CONTROLLER COMPAARED TO LICENSE API, WE JUST USE ACTION RESULT HERE AND RETURN THE MODEL THAT IS IN THE SERVICE.
{
var result = await _customerService.DeleteCustomerVMAsync(CustomerID);
return result;
return Ok(result);
}
#endregion
}
Expand Down
16 changes: 8 additions & 8 deletions MBDEVproAPI.API/MBDEVproAPI.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.3" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="10.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.3">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.8" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="10.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.8" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Scalar.AspNetCore" Version="2.13.1" />
<PackageReference Include="Scalar.AspNetCore" Version="2.14.14" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Enrichers.Process" Version="3.0.0" />
Expand All @@ -25,8 +25,8 @@
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.4" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.19.1" />
</ItemGroup>

<ItemGroup>
Expand Down
62 changes: 26 additions & 36 deletions MBDEVproAPI.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,31 @@

app.UseSerilogRequestLogging();


// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
//app.MapOpenApi(); // Expose the OpenAPI JSON endpoint
//app.MapScalarApiReference(); // Map the Scalar UI endpoint

app.MapOpenApi();
app.MapScalarApiReference();
//app.MapScalarApiReference(options =>
//{
// options.Title = "MBDEVproAPI v1 .NET CORE 10";
// options.WithTheme(ScalarTheme.Moon); // Use a specific theme
// options.ForceDarkMode(); // Force dark mode
//});

// Automatically redirect to Scalar documentation
//app.MapGet("/", () => Results.Redirect("/scalar"));

Log.Information("MBDEVproAPI: (Development Environment)");
app.UseDeveloperExceptionPage();
}



if (app.Environment.EnvironmentName == "Test")
{
Log.Information("MBDEVproAPI: Test Environment)");
Expand All @@ -77,44 +92,19 @@
Log.Information("MBDEVproAPI: Production Environment)");
}

if (app.Environment.IsDevelopment() || app.Environment.EnvironmentName == "Test")
{
//app.UseSwagger();
//app.UseSwaggerUI(c =>
//{
// //c.SwaggerEndpoint("/MBDEVproAPI/swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// c.SwaggerEndpoint("../swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// // ENDPOINTS: https://localhost:7092/swagger/index.html
// // JSON: https://localhost:7092/swagger/v1/swagger.json
//});
}



//DEMO so can test with swagger and scalar UI, can remove later
app.MapOpenApi(); // Expose the OpenAPI JSON endpoint
app.MapScalarApiReference(); // Map the Scalar UI endpoint
//if (app.Environment.IsDevelopment() || app.Environment.EnvironmentName == "Test")
//{
// //app.UseSwagger();
// //app.UseSwaggerUI(c =>
// //{
// // //c.SwaggerEndpoint("/MBDEVproAPI/swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// // c.SwaggerEndpoint("../swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// // // ENDPOINTS: https://localhost:7092/swagger/index.html
// // // JSON: https://localhost:7092/swagger/v1/swagger.json
// //});
//}

Log.Information("MBDEVproAPI: (Development Environment)");
//app.UseDeveloperExceptionPage(); // For local only, can change later for testing and production environments, can also add custom error handling middleware for production environment.

app.MapScalarApiReference(options =>
{
options.Title = "MBDEVproAPI v1 .NET CORE 10";
options.WithTheme(ScalarTheme.Moon); // Use a specific theme
options.ForceDarkMode(); // Force dark mode
});


//DEMO so can test with swagger and scalar UI, can remove later
app.UseSwagger();
app.UseSwaggerUI(c =>
{
//c.SwaggerEndpoint("/MBDEVproAPI/swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
c.SwaggerEndpoint("../swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// ENDPOINTS: https://localhost:7092/swagger/index.html
// JSON: https://localhost:7092/swagger/v1/swagger.json
});

app.UseSerilogRequestLogging(); // Add Serilog request logging middleware

Expand Down
13 changes: 13 additions & 0 deletions MBDEVproAPI.API/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "10.0.5",
"commands": [
"dotnet-ef"
],
"rollForward": false
}
}
}
2 changes: 1 addition & 1 deletion MBDEVproAPI.BLL/MBDEVproAPI.BLL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="16.0.0" />
<PackageReference Include="AutoMapper" Version="16.1.1" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.2.8" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
Expand Down
7 changes: 0 additions & 7 deletions MBDEVproAPI.Repository/Class1.cs

This file was deleted.

147 changes: 147 additions & 0 deletions MBDEVproAPI.Tests/CustomerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace MBDEVproAPI.Tests
{
public class CustomerTests
{

#region Variables and Constructors

private ICustomerService _customerService;

#endregion

public CustomerTests(ICustomerService customerService) {

_customerService = customerService;

}


//using MBDEVproAPI.DataModel.Entities;
private static readonly List<Customer> _customerListEntity = new()
{ new Customer { CustomerID = 1, BusinessID = 52466, Company = "cheeseburger", FirstName = "Jeff", LastName = "Smith", Email = "Jeff@Smith.com", Address = "123 Test St" }
};


//using MBDEVproAPI.Common.Models;
private static readonly List<CustomerModel> _customerListModel = new()
{ new CustomerModel { CustomerID = 1, BusinessID = 52466, Company = "cheeseburger", FirstName = "Jeff", LastName = "Smith", Email = "Jeff@Smith.com", Address = "123 Test St" }
};


#region commented out code
//public int CustomerID { get; set; }
//public int BusinessID { get; set; }

//public string? Company { get; set; }
//public string FirstName { get; set; } = String.Empty;
//public string LastName { get; set; } = String.Empty;

//public string Email { get; set; } = String.Empty;

//public string? Title { get; set; }
//public string? BPhone { get; set; }
//public string? HPhone { get; set; }
//public string? MPhone { get; set; }
//public string? Fax { get; set; }

//public string Address { get; set; } = String.Empty;
//public string City { get; set; } = String.Empty;
//public string State { get; set; } = String.Empty;
//public string ZIPCode { get; set; } = String.Empty;
//public string Country { get; set; } = String.Empty;

//public string? WebPage { get; set; }
//public string? Notes { get; set; }
//public string? Photo { get; set; }
//public string? Map { get; set; }

//public CustomerTests()
//{
// var mock = new Mock<ICustomerService>();
// mock.Setup(s => s.GetCustomerAsync(It.IsAny<int>()))
// .ReturnsAsync((int id) => _customerListEntity.FirstOrDefault(c => c.CustomerID == id) ?? new Customer());
// mock.Setup(s => s.GetAllCustomersVMAsync(It.IsAny<int>()))
// .ReturnsAsync((int businessId) => new CustomerViewModel { CustomerList = _customerListEntity.Select(x => Mapper.MapObject(x, new CustomerModel())).ToList() });
// _customerService = mock.Object;
//}


//public class CustomerTests
//{
// private ICustomerService _customerService;

// public CustomerTests()
// {
// _customerService = new TestCustomerService();
// }

// private static readonly List<Customer> _customerListEntity = new()
// {
// new Customer { CustomerID = 1, BusinessID = 52466, Company = "cheeseburger", FirstName = "Jeff", LastName = "Smith", Email = "Jeff@Smith.com", Address = "123 Test St" }
// };

// // Simple test-only implementation
// private class TestCustomerService : ICustomerService
// {
// public Task<Customer> GetCustomerAsync(int CustomerID)
// {
// var c = _customerListEntity.FirstOrDefault(x => x.CustomerID == CustomerID);
// return Task.FromResult(c ?? new Customer());
// }

// public Task<CustomerViewModel> GetAllCustomersVMAsync(int BusinessID)
// {
// var vm = new CustomerViewModel { CustomerList = _customerListEntity.Select(x => Mapper.MapObject(x, new CustomerModel())).ToList() };
// return Task.FromResult(vm);
// }

// // Implement other members of ICustomerService as no-op or throw NotImplementedException
// // ...
// }

// // tests follow...
//}
#endregion



#region Tests

[Fact]
public async Task GetCustomerAsync()
{
var customer = await _customerService.GetCustomerAsync(3);
Assert.NotNull(customer);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
[InlineData(5)]
public async Task GetCustomerAsyncID(int id)
{
var customer = await _customerService.GetCustomerAsync(id);
Assert.NotNull(customer);
}


[Theory]
[InlineData(52466)]
public async Task GetAllCustomersVMAsyncTest(int id)
{
var customers = await _customerService.GetAllCustomersVMAsync(id);
Assert.NotNull(customers);
}

#endregion


}
}
27 changes: 27 additions & 0 deletions MBDEVproAPI.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
global using System;
global using System.Collections.Generic;
//global using MBDEVproAPI.BLL.Interfaces;
//global using MBDEVproAPI.BLL.Services;
global using MBDEVproAPI.Common.Models;
global using MBDEVproAPI.Common.ViewModels;
global using MBDEVproAPI.BLL.Interfaces;
global using MBDEVproAPI.BLL.Services;
global using MBDEVproAPI.DataModel;
global using MBDEVproAPI.DataModel.Entities;
global using MBDEVproAPI.Repository.Interfaces;
global using MBDEVproAPI.Repository.Repositories;
global using Microsoft.AspNetCore.Authorization;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Hosting;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.AspNetCore.Mvc.Filters;
global using Microsoft.EntityFrameworkCore;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;
//global using Microsoft.OpenApi.Models;
global using Serilog;
global using Serilog.Formatting.Json;
global using Microsoft.OpenApi;
global using Scalar.AspNetCore;
16 changes: 12 additions & 4 deletions MBDEVproAPI.Tests/MBDEVproAPI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
<PackageReference Include="AutoMapper" Version="16.1.1" />
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="Moq.EntityFrameworkCore" Version="10.0.0.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="3.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 0 additions & 11 deletions MBDEVproAPI.Tests/UnitTest1.cs

This file was deleted.