Initial commit
هذا الالتزام موجود في:
140
TestProject1/WondersControllerTests.cs
Normal file
140
TestProject1/WondersControllerTests.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
//using Ghaymah.WondersAPI.Controllers;
|
||||
//using Microsoft.AspNetCore.Mvc;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
//using Moq;
|
||||
//using WondersAPI.Data;
|
||||
//using WondersAPI.Models;
|
||||
|
||||
//namespace TestProject1
|
||||
//{
|
||||
// public class WondersControllerTests
|
||||
// {
|
||||
// private readonly Mock<AppDbContext> _mockContext;
|
||||
// private readonly Mock<ILogger<WondersController>> _mockLogger;
|
||||
// private readonly WondersController _controller;
|
||||
|
||||
// //public WondersControllerTests()
|
||||
// //{
|
||||
// // var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
// // .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // <--- fixed
|
||||
// // .Options;
|
||||
|
||||
// // var context = new AppDbContext(options);
|
||||
|
||||
// // // Add sample data
|
||||
// // context.Wonders.AddRange(new List<Wonder>
|
||||
// // {
|
||||
// // new Wonder { Id = 1, Name = "Pyramids of Giza", Country = "Egypt", Type = "Ancient", Era = "Old Kingdom", Description = "Ancient pyramids", DiscoveryYear = -2500 },
|
||||
// // new Wonder { Id = 2, Name = "Great Wall of China", Country = "China", Type = "Ancient", Era = "Ming Dynasty", Description = "Long defensive wall", DiscoveryYear = -700 }
|
||||
// // });
|
||||
// // context.SaveChanges();
|
||||
|
||||
// // _mockContext = new Mock<AppDbContext>(options);
|
||||
// // _mockLogger = new Mock<ILogger<WondersController>>();
|
||||
|
||||
// // _controller = new WondersController(context, _mockLogger.Object);
|
||||
// //}
|
||||
|
||||
// [Fact]
|
||||
// public async Task GetAllWonders_ReturnsOkResult_WithListOfWonders()
|
||||
// {
|
||||
// // Act
|
||||
// var result = await _controller.GetAllWonders();
|
||||
|
||||
// // Assert
|
||||
// var okResult = Assert.IsType<OkObjectResult>(result);
|
||||
// var wonders = Assert.IsType<List<Wonder>>(okResult.Value);
|
||||
// Assert.True(wonders.Count > 0);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task GetWonderById_ReturnsOkResult_WhenFound()
|
||||
// {
|
||||
// // Act
|
||||
// var result = await _controller.GetWonderById("1");
|
||||
|
||||
// // Assert
|
||||
// var okResult = Assert.IsType<OkObjectResult>(result);
|
||||
// var wonder = Assert.IsType<Wonder>(okResult.Value);
|
||||
// Assert.Equal("Pyramids of Giza", wonder.Name);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task GetWonderById_ReturnsNotFound_WhenNotExists()
|
||||
// {
|
||||
// // Act
|
||||
// var result = await _controller.GetWonderById("999");
|
||||
|
||||
// // Assert
|
||||
// Assert.IsType<NotFoundObjectResult>(result);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CreateWonder_ReturnsCreatedAtAction()
|
||||
// {
|
||||
// // Arrange
|
||||
// var newWonder = new Wonder
|
||||
// {
|
||||
// Name = "Machu Picchu",
|
||||
// Country = "Peru",
|
||||
// Type = "Ancient",
|
||||
// Era = "Inca Empire",
|
||||
// Description = "Historic sanctuary",
|
||||
// DiscoveryYear = 1450
|
||||
// };
|
||||
|
||||
// // Act
|
||||
// var result = await _controller.CreateWonder(newWonder);
|
||||
|
||||
// // Assert
|
||||
// var createdResult = Assert.IsType<CreatedAtActionResult>(result);
|
||||
// var createdWonder = Assert.IsType<Wonder>(createdResult.Value);
|
||||
// Assert.Equal("Machu Picchu", createdWonder.Name);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task UpdateWonder_ReturnsNoContent_WhenSuccess()
|
||||
// {
|
||||
// // Arrange
|
||||
// var updatedWonder = new Wonder
|
||||
// {
|
||||
// Id = 1,
|
||||
// Name = "Updated Pyramids",
|
||||
// Country = "Egypt",
|
||||
// Type = "Ancient",
|
||||
// Era = "Old Kingdom",
|
||||
// Description = "Updated Description",
|
||||
// DiscoveryYear = -2500
|
||||
// };
|
||||
|
||||
// // Act
|
||||
// var result = await _controller.UpdateWonder("1", updatedWonder);
|
||||
|
||||
// // Assert
|
||||
// Assert.IsType<NoContentResult>(result);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task DeleteWonder_ReturnsNoContent_WhenSuccess()
|
||||
// {
|
||||
// // Act
|
||||
// var result = await _controller.DeleteWonder("2");
|
||||
|
||||
// // Assert
|
||||
// Assert.IsType<NoContentResult>(result);
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task GetRandomWonder_ReturnsOkResult()
|
||||
// {
|
||||
// // Act
|
||||
// var result = await _controller.GetRandomWonder();
|
||||
|
||||
// // Assert
|
||||
// var okResult = Assert.IsType<OkObjectResult>(result);
|
||||
// var wonder = Assert.IsType<Wonder>(okResult.Value);
|
||||
// Assert.NotNull(wonder);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
المرجع في مشكلة جديدة
حظر مستخدم