Rhys
Rhys
CC#
Created by Rhys on 3/7/2024 in #help
Unit testing not working, doesn't hit multiple test classes
The first test class runs perfectly fine, but the second one doesnt even get hit. I cant debug or set any breakpoints as nothing is hit.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VehicleInspection_Domain.Interfaces;
using Moq;
using Microsoft.AspNetCore.Mvc;
using VehicleInspection_Domain.Models.AbstractModels;
using Newtonsoft.Json;

namespace VehicleInspection_Test
{
[TestClass]
public class VehicleInspectionTesting
{
private readonly IEmailRepository _emailRepository;

public VehicleInspectionTesting(IEmailRepository emailRepository)
{
_emailRepository = emailRepository;
}

[TestMethod]
public async Task Insepction_ReturnOkResult_AndSendsEmailOnMajorDefect()
{
string jsonData = @"
{
*** SOME DATA ***
}";

// Mock dependencies
var emailRepositoryMock = new Mock<IEmailRepository>();
var inspectionService = new VehicleInspectionTesting(emailRepositoryMock.Object);

// Act
var result = await inspectionService.ProcessInspection(jsonData);

// Assert
Assert.IsInstanceOfType(result, typeof(OkResult));

// Verify that SendCriticalDefectEmail was called when major defects exist
emailRepositoryMock.Verify(x => x.SendCriticalDefectEmail(It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
}
}
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VehicleInspection_Domain.Interfaces;
using Moq;
using Microsoft.AspNetCore.Mvc;
using VehicleInspection_Domain.Models.AbstractModels;
using Newtonsoft.Json;

namespace VehicleInspection_Test
{
[TestClass]
public class VehicleInspectionTesting
{
private readonly IEmailRepository _emailRepository;

public VehicleInspectionTesting(IEmailRepository emailRepository)
{
_emailRepository = emailRepository;
}

[TestMethod]
public async Task Insepction_ReturnOkResult_AndSendsEmailOnMajorDefect()
{
string jsonData = @"
{
*** SOME DATA ***
}";

// Mock dependencies
var emailRepositoryMock = new Mock<IEmailRepository>();
var inspectionService = new VehicleInspectionTesting(emailRepositoryMock.Object);

// Act
var result = await inspectionService.ProcessInspection(jsonData);

// Assert
Assert.IsInstanceOfType(result, typeof(OkResult));

// Verify that SendCriticalDefectEmail was called when major defects exist
emailRepositoryMock.Verify(x => x.SendCriticalDefectEmail(It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
}
}
https://gyazo.com/d591331eb72b053113bf56111c719a94
11 replies
CC#
Created by Rhys on 2/16/2024 in #help
✅ .NET8 Connection String Login Failure With Dapper
I have tested my username and password in SQL server management studio and the connection works fine. But when I try using my connection string through my API, my connection string fails.
"DBConnection": "Data Source=** ; Initial Catalog=** ; User Id=**; Password=**; Trusted_Connection=false; Integrated Security=false"
"DBConnection": "Data Source=** ; Initial Catalog=** ; User Id=**; Password=**; Trusted_Connection=false; Integrated Security=false"
Previously this did work with .NET 6 but now creating a new project in .NET 8 it breaks. Any advice or fixes are appreciated!
19 replies